[AArch64] Fix predicate and constraint mismatch in logical atomic operations
[official-gcc.git] / gcc / ipa-inline.h
blob2ac6e4e93cb2acee18e0c9732223d59c36597760
1 /* Inlining decision heuristics.
2 Copyright (C) 2003-2014 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 3, or (at your option) any later
10 version.
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.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #ifndef GCC_IPA_INLINE_H
22 #define GCC_IPA_INLINE_H
25 /* Representation of inline parameters that do depend on context function is
26 inlined into (i.e. known constant values of function parameters.
28 Conditions that are interesting for function body are collected into CONDS
29 vector. They are of simple for function_param OP VAL, where VAL is
30 IPA invariant. The conditions are then referred by predicates. */
32 struct GTY(()) condition
34 /* If agg_contents is set, this is the offset from which the used data was
35 loaded. */
36 HOST_WIDE_INT offset;
37 tree val;
38 int operand_num;
39 ENUM_BITFIELD(tree_code) code : 16;
40 /* Set if the used data were loaded from an aggregate parameter or from
41 data received by reference. */
42 unsigned agg_contents : 1;
43 /* If agg_contents is set, this differentiates between loads from data
44 passed by reference and by value. */
45 unsigned by_ref : 1;
48 /* Inline hints are reasons why inline heuristics should preffer inlining given
49 function. They are represtented as bitmap of the following values. */
50 enum inline_hints_vals {
51 /* When inlining turns indirect call into a direct call,
52 it is good idea to do so. */
53 INLINE_HINT_indirect_call = 1,
54 /* Inlining may make loop iterations or loop stride known. It is good idea
55 to do so because it enables loop optimizatoins. */
56 INLINE_HINT_loop_iterations = 2,
57 INLINE_HINT_loop_stride = 4,
58 /* Inlining within same strongly connected component of callgraph is often
59 a loss due to increased stack frame usage and prologue setup costs. */
60 INLINE_HINT_same_scc = 8,
61 /* Inlining functions in strongly connected component is not such a great
62 win. */
63 INLINE_HINT_in_scc = 16,
64 /* If function is declared inline by user, it may be good idea to inline
65 it. */
66 INLINE_HINT_declared_inline = 32,
67 /* Programs are usually still organized for non-LTO compilation and thus
68 if functions are in different modules, inlining may not be so important.
70 INLINE_HINT_cross_module = 64,
71 /* If array indexes of loads/stores become known there may be room for
72 further optimization. */
73 INLINE_HINT_array_index = 128,
74 /* We know that the callee is hot by profile. */
75 INLINE_HINT_known_hot = 256
77 typedef int inline_hints;
80 typedef vec<condition, va_gc> *conditions;
82 /* Representation of predicates i.e. formulas using conditions defined
83 above. Predicates are simple logical formulas in conjunctive-disjunctive
84 form.
86 Predicate is array of clauses terminated by 0. Every clause must be true
87 in order to make predicate true.
88 Clauses are represented as bitmaps of conditions. One of conditions
89 must be true in order for clause to be true. */
91 #define MAX_CLAUSES 8
92 typedef unsigned int clause_t;
93 struct GTY(()) predicate
95 clause_t clause[MAX_CLAUSES + 1];
98 /* Represnetation of function body size and time depending on the inline
99 context. We keep simple array of record, every containing of predicate
100 and time/size to account.
102 We keep values scaled up, so fractional sizes and times can be
103 accounted. */
104 #define INLINE_SIZE_SCALE 2
105 #define INLINE_TIME_SCALE (CGRAPH_FREQ_BASE * 2)
106 struct GTY(()) size_time_entry
108 struct predicate predicate;
109 int size;
110 int time;
113 /* Function inlining information. */
114 struct GTY(()) inline_summary
116 /* Information about the function body itself. */
118 /* Estimated stack frame consumption by the function. */
119 HOST_WIDE_INT estimated_self_stack_size;
120 /* Size of the function body. */
121 int self_size;
122 /* Time of the function body. */
123 int self_time;
124 /* Minimal size increase after inlining. */
125 int min_size;
127 /* False when there something makes inlining impossible (such as va_arg). */
128 unsigned inlinable : 1;
130 /* Information about function that will result after applying all the
131 inline decisions present in the callgraph. Generally kept up to
132 date only for functions that are not inline clones. */
134 /* Estimated stack frame consumption by the function. */
135 HOST_WIDE_INT estimated_stack_size;
136 /* Expected offset of the stack frame of inlined function. */
137 HOST_WIDE_INT stack_frame_offset;
138 /* Estimated size of the function after inlining. */
139 int time;
140 int size;
142 /* Conditional size/time information. The summaries are being
143 merged during inlining. */
144 conditions conds;
145 vec<size_time_entry, va_gc> *entry;
147 /* Predicate on when some loop in the function becomes to have known
148 bounds. */
149 struct predicate * GTY((skip)) loop_iterations;
150 /* Predicate on when some loop in the function becomes to have known
151 stride. */
152 struct predicate * GTY((skip)) loop_stride;
153 /* Predicate on when some array indexes become constants. */
154 struct predicate * GTY((skip)) array_index;
155 /* Estimated growth for inlining all copies of the function before start
156 of small functions inlining.
157 This value will get out of date as the callers are duplicated, but
158 using up-to-date value in the badness metric mean a lot of extra
159 expenses. */
160 int growth;
161 /* Number of SCC on the beginning of inlining process. */
162 int scc_no;
165 /* Need a typedef for inline_summary because of inline function
166 'inline_summary' below. */
167 typedef struct inline_summary inline_summary_t;
168 extern GTY(()) vec<inline_summary_t, va_gc> *inline_summary_vec;
170 /* Information kept about parameter of call site. */
171 struct inline_param_summary
173 /* REG_BR_PROB_BASE based probability that parameter will change in between
174 two invocation of the calls.
175 I.e. loop invariant parameters
176 REG_BR_PROB_BASE/estimated_iterations and regular
177 parameters REG_BR_PROB_BASE.
179 Value 0 is reserved for compile time invariants. */
180 int change_prob;
183 /* Information kept about callgraph edges. */
184 struct inline_edge_summary
186 /* Estimated size and time of the call statement. */
187 int call_stmt_size;
188 int call_stmt_time;
189 /* Depth of loop nest, 0 means no nesting. */
190 unsigned short int loop_depth;
191 struct predicate *predicate;
192 /* Array indexed by parameters.
193 0 means that parameter change all the time, REG_BR_PROB_BASE means
194 that parameter is constant. */
195 vec<inline_param_summary> param;
198 /* Need a typedef for inline_edge_summary because of inline function
199 'inline_edge_summary' below. */
200 typedef struct inline_edge_summary inline_edge_summary_t;
201 extern vec<inline_edge_summary_t> inline_edge_summary_vec;
203 struct edge_growth_cache_entry
205 int time, size;
206 inline_hints hints;
209 extern vec<int> node_growth_cache;
210 extern vec<edge_growth_cache_entry> edge_growth_cache;
212 /* In ipa-inline-analysis.c */
213 void debug_inline_summary (struct cgraph_node *);
214 void dump_inline_summaries (FILE *f);
215 void dump_inline_summary (FILE *f, struct cgraph_node *node);
216 void dump_inline_hints (FILE *f, inline_hints);
217 void inline_generate_summary (void);
218 void inline_read_summary (void);
219 void inline_write_summary (void);
220 void inline_free_summary (void);
221 void inline_analyze_function (struct cgraph_node *node);
222 void initialize_inline_failed (struct cgraph_edge *);
223 int estimate_time_after_inlining (struct cgraph_node *, struct cgraph_edge *);
224 int estimate_size_after_inlining (struct cgraph_node *, struct cgraph_edge *);
225 void estimate_ipcp_clone_size_and_time (struct cgraph_node *,
226 vec<tree>, vec<tree>,
227 vec<ipa_agg_jump_function_p>,
228 int *, int *, inline_hints *);
229 int do_estimate_growth (struct cgraph_node *);
230 bool growth_likely_positive (struct cgraph_node *, int);
231 void inline_merge_summary (struct cgraph_edge *edge);
232 void inline_update_overall_summary (struct cgraph_node *node);
233 int do_estimate_edge_size (struct cgraph_edge *edge);
234 int do_estimate_edge_time (struct cgraph_edge *edge);
235 inline_hints do_estimate_edge_hints (struct cgraph_edge *edge);
236 void initialize_growth_caches (void);
237 void free_growth_caches (void);
238 void compute_inline_parameters (struct cgraph_node *, bool);
239 bool speculation_useful_p (struct cgraph_edge *e, bool anticipate_inlining);
240 unsigned int early_inliner (function *fun);
242 /* In ipa-inline-transform.c */
243 bool inline_call (struct cgraph_edge *, bool, vec<cgraph_edge *> *, int *, bool,
244 bool *callee_removed = NULL);
245 unsigned int inline_transform (struct cgraph_node *);
246 void clone_inlined_nodes (struct cgraph_edge *e, bool, bool, int *,
247 int freq_scale);
249 extern int ncalls_inlined;
250 extern int nfunctions_inlined;
252 static inline struct inline_summary *
253 inline_summary (struct cgraph_node *node)
255 return &(*inline_summary_vec)[node->uid];
258 static inline struct inline_edge_summary *
259 inline_edge_summary (struct cgraph_edge *edge)
261 return &inline_edge_summary_vec[edge->uid];
264 /* Return estimated unit growth after inlning all calls to NODE.
265 Quick accesors to the inline growth caches.
266 For convenience we keep zero 0 as unknown. Because growth
267 can be both positive and negative, we simply increase positive
268 growths by 1. */
269 static inline int
270 estimate_growth (struct cgraph_node *node)
272 int ret;
273 if ((int)node_growth_cache.length () <= node->uid
274 || !(ret = node_growth_cache[node->uid]))
275 return do_estimate_growth (node);
276 return ret - (ret > 0);
280 /* Return estimated size of the inline sequence of EDGE. */
282 static inline int
283 estimate_edge_size (struct cgraph_edge *edge)
285 int ret;
286 if ((int)edge_growth_cache.length () <= edge->uid
287 || !(ret = edge_growth_cache[edge->uid].size))
288 return do_estimate_edge_size (edge);
289 return ret - (ret > 0);
292 /* Return estimated callee growth after inlining EDGE. */
294 static inline int
295 estimate_edge_growth (struct cgraph_edge *edge)
297 #ifdef ENABLE_CHECKING
298 gcc_checking_assert (inline_edge_summary (edge)->call_stmt_size
299 || !edge->callee->analyzed);
300 #endif
301 return (estimate_edge_size (edge)
302 - inline_edge_summary (edge)->call_stmt_size);
305 /* Return estimated callee runtime increase after inlning
306 EDGE. */
308 static inline int
309 estimate_edge_time (struct cgraph_edge *edge)
311 int ret;
312 if ((int)edge_growth_cache.length () <= edge->uid
313 || !(ret = edge_growth_cache[edge->uid].time))
314 return do_estimate_edge_time (edge);
315 return ret - (ret > 0);
319 /* Return estimated callee runtime increase after inlning
320 EDGE. */
322 static inline inline_hints
323 estimate_edge_hints (struct cgraph_edge *edge)
325 inline_hints ret;
326 if ((int)edge_growth_cache.length () <= edge->uid
327 || !(ret = edge_growth_cache[edge->uid].hints))
328 return do_estimate_edge_hints (edge);
329 return ret - 1;
333 /* Reset cached value for NODE. */
335 static inline void
336 reset_node_growth_cache (struct cgraph_node *node)
338 if ((int)node_growth_cache.length () > node->uid)
339 node_growth_cache[node->uid] = 0;
342 /* Reset cached value for EDGE. */
344 static inline void
345 reset_edge_growth_cache (struct cgraph_edge *edge)
347 if ((int)edge_growth_cache.length () > edge->uid)
349 struct edge_growth_cache_entry zero = {0, 0, 0};
350 edge_growth_cache[edge->uid] = zero;
354 #endif /* GCC_IPA_INLINE_H */