]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/ipa-fnsummary.h
Allow automatics in equivalences
[thirdparty/gcc.git] / gcc / ipa-fnsummary.h
1 /* IPA function body analysis.
2 Copyright (C) 2003-2019 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 /* Hints are reasons why IPA heuristics should preffer specializing given
29 function. They are represtented as bitmap of the following values. */
30 enum ipa_hints_vals {
31 /* When specialization 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. Set by simple_edge_hints in ipa-inline-analysis.c. */
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 Set by simple_edge_hints in ipa-inline-analysis.c. */
50 INLINE_HINT_cross_module = 64,
51 /* We know that the callee is hot by profile. */
52 INLINE_HINT_known_hot = 128
53 };
54
55 typedef int ipa_hints;
56
57 /* Simple description of whether a memory load or a condition refers to a load
58 from an aggregate and if so, how and where from in the aggregate.
59 Individual fields have the same meaning like fields with the same name in
60 struct condition. */
61
62 struct agg_position_info
63 {
64 HOST_WIDE_INT offset;
65 bool agg_contents;
66 bool by_ref;
67 };
68
69 /* Representation of function body size and time depending on the call
70 context. We keep simple array of record, every containing of predicate
71 and time/size to account. */
72 class GTY(()) size_time_entry
73 {
74 public:
75 /* Predicate for code to be executed. */
76 predicate exec_predicate;
77 /* Predicate for value to be constant and optimized out in a specialized copy.
78 When deciding on specialization this makes it possible to see how much
79 the executed code paths will simplify. */
80 predicate nonconst_predicate;
81 int size;
82 sreal GTY((skip)) time;
83 };
84
85 /* Function inlining information. */
86 class GTY(()) ipa_fn_summary
87 {
88 public:
89 /* Keep all field empty so summary dumping works during its computation.
90 This is useful for debugging. */
91 ipa_fn_summary ()
92 : estimated_self_stack_size (0), self_size (0), min_size (0),
93 inlinable (false), single_caller (false),
94 fp_expressions (false), estimated_stack_size (false),
95 stack_frame_offset (false), time (0), size (0), conds (NULL),
96 size_time_table (NULL), loop_iterations (NULL), loop_stride (NULL),
97 growth (0), scc_no (0)
98 {
99 }
100
101 /* Copy constructor. */
102 ipa_fn_summary (const ipa_fn_summary &s)
103 : estimated_self_stack_size (s.estimated_self_stack_size),
104 self_size (s.self_size), min_size (s.min_size),
105 inlinable (s.inlinable), single_caller (s.single_caller),
106 fp_expressions (s.fp_expressions),
107 estimated_stack_size (s.estimated_stack_size),
108 stack_frame_offset (s.stack_frame_offset), time (s.time), size (s.size),
109 conds (s.conds), size_time_table (s.size_time_table),
110 loop_iterations (s.loop_iterations), loop_stride (s.loop_stride),
111 growth (s.growth), scc_no (s.scc_no)
112 {}
113
114 /* Default constructor. */
115 ~ipa_fn_summary ();
116
117 /* Information about the function body itself. */
118
119 /* Estimated stack frame consumption by the function. */
120 HOST_WIDE_INT estimated_self_stack_size;
121 /* Size of the function body. */
122 int self_size;
123 /* Minimal size increase after inlining. */
124 int min_size;
125
126 /* False when there something makes inlining impossible (such as va_arg). */
127 unsigned inlinable : 1;
128 /* True wen there is only one caller of the function before small function
129 inlining. */
130 unsigned int single_caller : 1;
131 /* True if function contains any floating point expressions. */
132 unsigned int fp_expressions : 1;
133
134 /* Information about function that will result after applying all the
135 inline decisions present in the callgraph. Generally kept up to
136 date only for functions that are not inline clones. */
137
138 /* Estimated stack frame consumption by the function. */
139 HOST_WIDE_INT estimated_stack_size;
140 /* Expected offset of the stack frame of function. */
141 HOST_WIDE_INT stack_frame_offset;
142 /* Estimated size of the function after inlining. */
143 sreal GTY((skip)) time;
144 int size;
145
146 /* Conditional size/time information. The summaries are being
147 merged during inlining. */
148 conditions conds;
149 vec<size_time_entry, va_gc> *size_time_table;
150
151 /* Predicate on when some loop in the function becomes to have known
152 bounds. */
153 predicate * GTY((skip)) loop_iterations;
154 /* Predicate on when some loop in the function becomes to have known
155 stride. */
156 predicate * GTY((skip)) loop_stride;
157 /* Estimated growth for inlining all copies of the function before start
158 of small functions inlining.
159 This value will get out of date as the callers are duplicated, but
160 using up-to-date value in the badness metric mean a lot of extra
161 expenses. */
162 int growth;
163 /* Number of SCC on the beginning of inlining process. */
164 int scc_no;
165
166 /* Record time and size under given predicates. */
167 void account_size_time (int, sreal, const predicate &, const predicate &);
168
169 /* We keep values scaled up, so fractional sizes can be accounted. */
170 static const int size_scale = 2;
171 };
172
173 class GTY((user)) ipa_fn_summary_t:
174 public fast_function_summary <ipa_fn_summary *, va_gc>
175 {
176 public:
177 ipa_fn_summary_t (symbol_table *symtab):
178 fast_function_summary <ipa_fn_summary *, va_gc> (symtab) {}
179
180 static ipa_fn_summary_t *create_ggc (symbol_table *symtab)
181 {
182 class ipa_fn_summary_t *summary = new (ggc_alloc <ipa_fn_summary_t> ())
183 ipa_fn_summary_t (symtab);
184 summary->disable_insertion_hook ();
185 return summary;
186 }
187
188 /* Remove ipa_fn_summary for all callees of NODE. */
189 void remove_callees (cgraph_node *node);
190
191 virtual void insert (cgraph_node *, ipa_fn_summary *);
192 virtual void remove (cgraph_node *node, ipa_fn_summary *)
193 {
194 remove_callees (node);
195 }
196
197 virtual void duplicate (cgraph_node *src, cgraph_node *dst,
198 ipa_fn_summary *src_data, ipa_fn_summary *dst_data);
199 };
200
201 extern GTY(()) fast_function_summary <ipa_fn_summary *, va_gc>
202 *ipa_fn_summaries;
203
204 /* Information kept about callgraph edges. */
205 class ipa_call_summary
206 {
207 public:
208 /* Keep all field empty so summary dumping works during its computation.
209 This is useful for debugging. */
210 ipa_call_summary ()
211 : predicate (NULL), param (vNULL), call_stmt_size (0), call_stmt_time (0),
212 loop_depth (0), is_return_callee_uncaptured (false)
213 {
214 }
215
216 /* Copy constructor. */
217 ipa_call_summary (const ipa_call_summary &s):
218 predicate (s.predicate), param (s.param), call_stmt_size (s.call_stmt_size),
219 call_stmt_time (s.call_stmt_time), loop_depth (s.loop_depth),
220 is_return_callee_uncaptured (s.is_return_callee_uncaptured)
221 {
222 }
223
224 /* Default destructor. */
225 ~ipa_call_summary ();
226
227 class predicate *predicate;
228 /* Vector indexed by parameters. */
229 vec<inline_param_summary> param;
230 /* Estimated size and time of the call statement. */
231 int call_stmt_size;
232 int call_stmt_time;
233 /* Depth of loop nest, 0 means no nesting. */
234 unsigned int loop_depth;
235 /* Indicates whether the caller returns the value of it's callee. */
236 bool is_return_callee_uncaptured;
237 };
238
239 class ipa_call_summary_t: public fast_call_summary <ipa_call_summary *, va_heap>
240 {
241 public:
242 ipa_call_summary_t (symbol_table *symtab):
243 fast_call_summary <ipa_call_summary *, va_heap> (symtab) {}
244
245 /* Hook that is called by summary when an edge is duplicated. */
246 virtual void duplicate (cgraph_edge *src, cgraph_edge *dst,
247 ipa_call_summary *src_data,
248 ipa_call_summary *dst_data);
249 };
250
251 extern fast_call_summary <ipa_call_summary *, va_heap> *ipa_call_summaries;
252
253 /* In ipa-fnsummary.c */
254 void ipa_debug_fn_summary (struct cgraph_node *);
255 void ipa_dump_fn_summaries (FILE *f);
256 void ipa_dump_fn_summary (FILE *f, struct cgraph_node *node);
257 void ipa_dump_hints (FILE *f, ipa_hints);
258 void ipa_free_fn_summary (void);
259 void inline_analyze_function (struct cgraph_node *node);
260 void estimate_ipcp_clone_size_and_time (struct cgraph_node *,
261 vec<tree>,
262 vec<ipa_polymorphic_call_context>,
263 vec<ipa_agg_jump_function_p>,
264 int *, sreal *, sreal *,
265 ipa_hints *);
266 void ipa_merge_fn_summary_after_inlining (struct cgraph_edge *edge);
267 void ipa_update_overall_fn_summary (struct cgraph_node *node);
268 void compute_fn_summary (struct cgraph_node *, bool);
269
270
271 void evaluate_properties_for_edge (struct cgraph_edge *e, bool inline_p,
272 clause_t *clause_ptr,
273 clause_t *nonspec_clause_ptr,
274 vec<tree> *known_vals_ptr,
275 vec<ipa_polymorphic_call_context>
276 *known_contexts_ptr,
277 vec<ipa_agg_jump_function_p> *);
278 void estimate_node_size_and_time (struct cgraph_node *node,
279 clause_t possible_truths,
280 clause_t nonspec_possible_truths,
281 vec<tree> known_vals,
282 vec<ipa_polymorphic_call_context>,
283 vec<ipa_agg_jump_function_p> known_aggs,
284 int *ret_size, int *ret_min_size,
285 sreal *ret_time,
286 sreal *ret_nonspecialized_time,
287 ipa_hints *ret_hints,
288 vec<inline_param_summary>
289 inline_param_summary);
290
291 void ipa_fnsummary_c_finalize (void);
292
293 #endif /* GCC_IPA_FNSUMMARY_H */