]> gcc.gnu.org Git - gcc.git/blob - gcc/ipa-fnsummary.h
Makefile.in: Add ipa-fnsummary.o and ipa-fnsummary.h
[gcc.git] / gcc / ipa-fnsummary.h
1 /* IPA function body analysis.
2 Copyright (C) 2003-2017 Free Software Foundation, Inc.
3 Contributed by Jan Hubicka
4
5 This file is part of GCC.
6
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.
11
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.
16
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/>. */
20
21 #ifndef GCC_IPA_SUMMARY_H
22 #define GCC_IPA_SUMMARY_H
23
24 #include "sreal.h"
25 #include "ipa-predicate.h"
26
27
28 /* Inline hints are reasons why inline heuristics should preffer inlining given
29 function. They are represtented as bitmap of the following values. */
30 enum inline_hints_vals {
31 /* When inlining turns indirect call into a direct call,
32 it is good idea to do so. */
33 INLINE_HINT_indirect_call = 1,
34 /* Inlining may make loop iterations or loop stride known. It is good idea
35 to do so because it enables loop optimizatoins. */
36 INLINE_HINT_loop_iterations = 2,
37 INLINE_HINT_loop_stride = 4,
38 /* Inlining within same strongly connected component of callgraph is often
39 a loss due to increased stack frame usage and prologue setup costs. */
40 INLINE_HINT_same_scc = 8,
41 /* Inlining functions in strongly connected component is not such a great
42 win. */
43 INLINE_HINT_in_scc = 16,
44 /* If function is declared inline by user, it may be good idea to inline
45 it. */
46 INLINE_HINT_declared_inline = 32,
47 /* Programs are usually still organized for non-LTO compilation and thus
48 if functions are in different modules, inlining may not be so important.
49 */
50 INLINE_HINT_cross_module = 64,
51 /* If array indexes of loads/stores become known there may be room for
52 further optimization. */
53 INLINE_HINT_array_index = 128,
54 /* We know that the callee is hot by profile. */
55 INLINE_HINT_known_hot = 256
56 };
57
58 typedef int inline_hints;
59
60 /* Simple description of whether a memory load or a condition refers to a load
61 from an aggregate and if so, how and where from in the aggregate.
62 Individual fields have the same meaning like fields with the same name in
63 struct condition. */
64
65 struct agg_position_info
66 {
67 HOST_WIDE_INT offset;
68 bool agg_contents;
69 bool by_ref;
70 };
71
72 /* Represnetation of function body size and time depending on the inline
73 context. We keep simple array of record, every containing of predicate
74 and time/size to account.
75
76 We keep values scaled up, so fractional sizes can be accounted. */
77 #define INLINE_SIZE_SCALE 2
78 struct GTY(()) size_time_entry
79 {
80 /* Predicate for code to be executed. */
81 predicate exec_predicate;
82 /* Predicate for value to be constant and optimized out in a specialized copy.
83 When deciding on specialization this makes it possible to see how much
84 the executed code paths will simplify. */
85 predicate nonconst_predicate;
86 int size;
87 sreal GTY((skip)) time;
88 };
89
90 /* Function inlining information. */
91 struct GTY(()) inline_summary
92 {
93 /* Information about the function body itself. */
94
95 /* Estimated stack frame consumption by the function. */
96 HOST_WIDE_INT estimated_self_stack_size;
97 /* Size of the function body. */
98 int self_size;
99 /* Minimal size increase after inlining. */
100 int min_size;
101
102 /* False when there something makes inlining impossible (such as va_arg). */
103 unsigned inlinable : 1;
104 /* True when function contains cilk spawn (and thus we can not inline
105 into it). */
106 unsigned contains_cilk_spawn : 1;
107 /* True wen there is only one caller of the function before small function
108 inlining. */
109 unsigned int single_caller : 1;
110 /* True if function contains any floating point expressions. */
111 unsigned int fp_expressions : 1;
112
113 /* Information about function that will result after applying all the
114 inline decisions present in the callgraph. Generally kept up to
115 date only for functions that are not inline clones. */
116
117 /* Estimated stack frame consumption by the function. */
118 HOST_WIDE_INT estimated_stack_size;
119 /* Expected offset of the stack frame of inlined function. */
120 HOST_WIDE_INT stack_frame_offset;
121 /* Estimated size of the function after inlining. */
122 sreal GTY((skip)) time;
123 int size;
124
125 /* Conditional size/time information. The summaries are being
126 merged during inlining. */
127 conditions conds;
128 vec<size_time_entry, va_gc> *size_time_table;
129
130 /* Predicate on when some loop in the function becomes to have known
131 bounds. */
132 predicate * GTY((skip)) loop_iterations;
133 /* Predicate on when some loop in the function becomes to have known
134 stride. */
135 predicate * GTY((skip)) loop_stride;
136 /* Predicate on when some array indexes become constants. */
137 predicate * GTY((skip)) array_index;
138 /* Estimated growth for inlining all copies of the function before start
139 of small functions inlining.
140 This value will get out of date as the callers are duplicated, but
141 using up-to-date value in the badness metric mean a lot of extra
142 expenses. */
143 int growth;
144 /* Number of SCC on the beginning of inlining process. */
145 int scc_no;
146
147 /* Keep all field empty so summary dumping works during its computation.
148 This is useful for debugging. */
149 inline_summary ()
150 : estimated_self_stack_size (0), self_size (0), min_size (0),
151 inlinable (false), contains_cilk_spawn (false), single_caller (false),
152 fp_expressions (false), estimated_stack_size (false),
153 stack_frame_offset (false), time (0), size (0), conds (NULL),
154 size_time_table (NULL), loop_iterations (NULL), loop_stride (NULL),
155 array_index (NULL), growth (0), scc_no (0)
156 {
157 }
158
159 /* Record time and size under given predicates. */
160 void account_size_time (int, sreal, const predicate &, const predicate &);
161
162 /* Reset inline summary to empty state. */
163 void reset (struct cgraph_node *node);
164 };
165
166 class GTY((user)) inline_summary_t: public function_summary <inline_summary *>
167 {
168 public:
169 inline_summary_t (symbol_table *symtab, bool ggc):
170 function_summary <inline_summary *> (symtab, ggc) {}
171
172 static inline_summary_t *create_ggc (symbol_table *symtab)
173 {
174 struct inline_summary_t *summary = new (ggc_alloc <inline_summary_t> ())
175 inline_summary_t(symtab, true);
176 summary->disable_insertion_hook ();
177 return summary;
178 }
179
180
181 virtual void insert (cgraph_node *, inline_summary *);
182 virtual void remove (cgraph_node *node, inline_summary *);
183 virtual void duplicate (cgraph_node *src, cgraph_node *dst,
184 inline_summary *src_data, inline_summary *dst_data);
185 };
186
187 extern GTY(()) function_summary <inline_summary *> *inline_summaries;
188
189 /* Information kept about callgraph edges. */
190 struct ipa_call_summary
191 {
192 class predicate *predicate;
193 /* Vector indexed by parameters. */
194 vec<inline_param_summary> param;
195 /* Estimated size and time of the call statement. */
196 int call_stmt_size;
197 int call_stmt_time;
198 /* Depth of loop nest, 0 means no nesting. */
199 unsigned int loop_depth;
200
201 /* Keep all field empty so summary dumping works during its computation.
202 This is useful for debugging. */
203 ipa_call_summary ()
204 : predicate (NULL), param (vNULL), call_stmt_size (0), call_stmt_time (0),
205 loop_depth (0)
206 {
207 }
208
209 /* Reset inline summary to empty state. */
210 void reset ();
211 };
212
213 class ipa_call_summary_t: public call_summary <ipa_call_summary *>
214 {
215 public:
216 ipa_call_summary_t (symbol_table *symtab, bool ggc):
217 call_summary <ipa_call_summary *> (symtab, ggc) {}
218
219 /* Hook that is called by summary when an edge is duplicated. */
220 virtual void remove (cgraph_edge *cs, ipa_call_summary *);
221 /* Hook that is called by summary when an edge is duplicated. */
222 virtual void duplicate (cgraph_edge *src, cgraph_edge *dst,
223 ipa_call_summary *src_data,
224 ipa_call_summary *dst_data);
225 };
226
227 extern call_summary <ipa_call_summary *> *ipa_call_summaries;
228
229 /* In ipa-fnsummary.c */
230 void debug_inline_summary (struct cgraph_node *);
231 void dump_inline_summaries (FILE *f);
232 void dump_inline_summary (FILE *f, struct cgraph_node *node);
233 void dump_inline_hints (FILE *f, inline_hints);
234 void inline_generate_summary (void);
235 void inline_read_summary (void);
236 void inline_write_summary (void);
237 void inline_free_summary (void);
238 void inline_analyze_function (struct cgraph_node *node);
239 int estimate_size_after_inlining (struct cgraph_node *, struct cgraph_edge *);
240 void estimate_ipcp_clone_size_and_time (struct cgraph_node *,
241 vec<tree>,
242 vec<ipa_polymorphic_call_context>,
243 vec<ipa_agg_jump_function_p>,
244 int *, sreal *, sreal *,
245 inline_hints *);
246 void inline_merge_summary (struct cgraph_edge *edge);
247 void inline_update_overall_summary (struct cgraph_node *node);
248 void compute_inline_parameters (struct cgraph_node *, bool);
249 bool inline_account_function_p (struct cgraph_node *node);
250
251
252 void evaluate_properties_for_edge (struct cgraph_edge *e, bool inline_p,
253 clause_t *clause_ptr,
254 clause_t *nonspec_clause_ptr,
255 vec<tree> *known_vals_ptr,
256 vec<ipa_polymorphic_call_context>
257 *known_contexts_ptr,
258 vec<ipa_agg_jump_function_p> *);
259 void estimate_node_size_and_time (struct cgraph_node *node,
260 clause_t possible_truths,
261 clause_t nonspec_possible_truths,
262 vec<tree> known_vals,
263 vec<ipa_polymorphic_call_context>,
264 vec<ipa_agg_jump_function_p> known_aggs,
265 int *ret_size, int *ret_min_size,
266 sreal *ret_time,
267 sreal *ret_nonspecialized_time,
268 inline_hints *ret_hints,
269 vec<inline_param_summary>
270 inline_param_summary);
271
272 #endif /* GCC_IPA_FNSUMMARY_H */
This page took 0.053844 seconds and 6 git commands to generate.