annotate gcc/ipa-fnsummary.h @ 138:fc828634a951

merge
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 08 Nov 2018 14:17:14 +0900
parents 84e7813d76e9
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* IPA function body analysis.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2 Copyright (C) 2003-2018 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3 Contributed by Jan Hubicka
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 This file is part of GCC.
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 GCC is free software; you can redistribute it and/or modify it under
kono
parents:
diff changeset
8 the terms of the GNU General Public License as published by the Free
kono
parents:
diff changeset
9 Software Foundation; either version 3, or (at your option) any later
kono
parents:
diff changeset
10 version.
kono
parents:
diff changeset
11
kono
parents:
diff changeset
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
kono
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kono
parents:
diff changeset
15 for more details.
kono
parents:
diff changeset
16
kono
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
18 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
19 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
20
kono
parents:
diff changeset
21 #ifndef GCC_IPA_SUMMARY_H
kono
parents:
diff changeset
22 #define GCC_IPA_SUMMARY_H
kono
parents:
diff changeset
23
kono
parents:
diff changeset
24 #include "sreal.h"
kono
parents:
diff changeset
25 #include "ipa-predicate.h"
kono
parents:
diff changeset
26
kono
parents:
diff changeset
27
kono
parents:
diff changeset
28 /* Hints are reasons why IPA heuristics should preffer specializing given
kono
parents:
diff changeset
29 function. They are represtented as bitmap of the following values. */
kono
parents:
diff changeset
30 enum ipa_hints_vals {
kono
parents:
diff changeset
31 /* When specialization turns indirect call into a direct call,
kono
parents:
diff changeset
32 it is good idea to do so. */
kono
parents:
diff changeset
33 INLINE_HINT_indirect_call = 1,
kono
parents:
diff changeset
34 /* Inlining may make loop iterations or loop stride known. It is good idea
kono
parents:
diff changeset
35 to do so because it enables loop optimizatoins. */
kono
parents:
diff changeset
36 INLINE_HINT_loop_iterations = 2,
kono
parents:
diff changeset
37 INLINE_HINT_loop_stride = 4,
kono
parents:
diff changeset
38 /* Inlining within same strongly connected component of callgraph is often
kono
parents:
diff changeset
39 a loss due to increased stack frame usage and prologue setup costs. */
kono
parents:
diff changeset
40 INLINE_HINT_same_scc = 8,
kono
parents:
diff changeset
41 /* Inlining functions in strongly connected component is not such a great
kono
parents:
diff changeset
42 win. */
kono
parents:
diff changeset
43 INLINE_HINT_in_scc = 16,
kono
parents:
diff changeset
44 /* If function is declared inline by user, it may be good idea to inline
kono
parents:
diff changeset
45 it. Set by simple_edge_hints in ipa-inline-analysis.c. */
kono
parents:
diff changeset
46 INLINE_HINT_declared_inline = 32,
kono
parents:
diff changeset
47 /* Programs are usually still organized for non-LTO compilation and thus
kono
parents:
diff changeset
48 if functions are in different modules, inlining may not be so important.
kono
parents:
diff changeset
49 Set by simple_edge_hints in ipa-inline-analysis.c. */
kono
parents:
diff changeset
50 INLINE_HINT_cross_module = 64,
kono
parents:
diff changeset
51 /* If array indexes of loads/stores become known there may be room for
kono
parents:
diff changeset
52 further optimization. */
kono
parents:
diff changeset
53 INLINE_HINT_array_index = 128,
kono
parents:
diff changeset
54 /* We know that the callee is hot by profile. */
kono
parents:
diff changeset
55 INLINE_HINT_known_hot = 256
kono
parents:
diff changeset
56 };
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 typedef int ipa_hints;
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 /* Simple description of whether a memory load or a condition refers to a load
kono
parents:
diff changeset
61 from an aggregate and if so, how and where from in the aggregate.
kono
parents:
diff changeset
62 Individual fields have the same meaning like fields with the same name in
kono
parents:
diff changeset
63 struct condition. */
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 struct agg_position_info
kono
parents:
diff changeset
66 {
kono
parents:
diff changeset
67 HOST_WIDE_INT offset;
kono
parents:
diff changeset
68 bool agg_contents;
kono
parents:
diff changeset
69 bool by_ref;
kono
parents:
diff changeset
70 };
kono
parents:
diff changeset
71
kono
parents:
diff changeset
72 /* Representation of function body size and time depending on the call
kono
parents:
diff changeset
73 context. We keep simple array of record, every containing of predicate
kono
parents:
diff changeset
74 and time/size to account. */
kono
parents:
diff changeset
75 struct GTY(()) size_time_entry
kono
parents:
diff changeset
76 {
kono
parents:
diff changeset
77 /* Predicate for code to be executed. */
kono
parents:
diff changeset
78 predicate exec_predicate;
kono
parents:
diff changeset
79 /* Predicate for value to be constant and optimized out in a specialized copy.
kono
parents:
diff changeset
80 When deciding on specialization this makes it possible to see how much
kono
parents:
diff changeset
81 the executed code paths will simplify. */
kono
parents:
diff changeset
82 predicate nonconst_predicate;
kono
parents:
diff changeset
83 int size;
kono
parents:
diff changeset
84 sreal GTY((skip)) time;
kono
parents:
diff changeset
85 };
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 /* Function inlining information. */
kono
parents:
diff changeset
88 struct GTY(()) ipa_fn_summary
kono
parents:
diff changeset
89 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
90 /* Keep all field empty so summary dumping works during its computation.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
91 This is useful for debugging. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
92 ipa_fn_summary ()
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
93 : estimated_self_stack_size (0), self_size (0), min_size (0),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
94 inlinable (false), single_caller (false),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
95 fp_expressions (false), estimated_stack_size (false),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
96 stack_frame_offset (false), time (0), size (0), conds (NULL),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
97 size_time_table (NULL), loop_iterations (NULL), loop_stride (NULL),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
98 array_index (NULL), growth (0), scc_no (0)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
99 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
100 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
101
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
102 /* Copy constructor. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
103 ipa_fn_summary (const ipa_fn_summary &s)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
104 : estimated_self_stack_size (s.estimated_self_stack_size),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
105 self_size (s.self_size), min_size (s.min_size),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
106 inlinable (s.inlinable), single_caller (s.single_caller),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
107 fp_expressions (s.fp_expressions),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
108 estimated_stack_size (s.estimated_stack_size),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
109 stack_frame_offset (s.stack_frame_offset), time (s.time), size (s.size),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
110 conds (s.conds), size_time_table (s.size_time_table),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
111 loop_iterations (s.loop_iterations), loop_stride (s.loop_stride),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
112 array_index (s.array_index), growth (s.growth), scc_no (s.scc_no)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
113 {}
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
114
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
115 /* Default constructor. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
116 ~ipa_fn_summary ();
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
117
111
kono
parents:
diff changeset
118 /* Information about the function body itself. */
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 /* Estimated stack frame consumption by the function. */
kono
parents:
diff changeset
121 HOST_WIDE_INT estimated_self_stack_size;
kono
parents:
diff changeset
122 /* Size of the function body. */
kono
parents:
diff changeset
123 int self_size;
kono
parents:
diff changeset
124 /* Minimal size increase after inlining. */
kono
parents:
diff changeset
125 int min_size;
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 /* False when there something makes inlining impossible (such as va_arg). */
kono
parents:
diff changeset
128 unsigned inlinable : 1;
kono
parents:
diff changeset
129 /* True wen there is only one caller of the function before small function
kono
parents:
diff changeset
130 inlining. */
kono
parents:
diff changeset
131 unsigned int single_caller : 1;
kono
parents:
diff changeset
132 /* True if function contains any floating point expressions. */
kono
parents:
diff changeset
133 unsigned int fp_expressions : 1;
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 /* Information about function that will result after applying all the
kono
parents:
diff changeset
136 inline decisions present in the callgraph. Generally kept up to
kono
parents:
diff changeset
137 date only for functions that are not inline clones. */
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 /* Estimated stack frame consumption by the function. */
kono
parents:
diff changeset
140 HOST_WIDE_INT estimated_stack_size;
kono
parents:
diff changeset
141 /* Expected offset of the stack frame of function. */
kono
parents:
diff changeset
142 HOST_WIDE_INT stack_frame_offset;
kono
parents:
diff changeset
143 /* Estimated size of the function after inlining. */
kono
parents:
diff changeset
144 sreal GTY((skip)) time;
kono
parents:
diff changeset
145 int size;
kono
parents:
diff changeset
146
kono
parents:
diff changeset
147 /* Conditional size/time information. The summaries are being
kono
parents:
diff changeset
148 merged during inlining. */
kono
parents:
diff changeset
149 conditions conds;
kono
parents:
diff changeset
150 vec<size_time_entry, va_gc> *size_time_table;
kono
parents:
diff changeset
151
kono
parents:
diff changeset
152 /* Predicate on when some loop in the function becomes to have known
kono
parents:
diff changeset
153 bounds. */
kono
parents:
diff changeset
154 predicate * GTY((skip)) loop_iterations;
kono
parents:
diff changeset
155 /* Predicate on when some loop in the function becomes to have known
kono
parents:
diff changeset
156 stride. */
kono
parents:
diff changeset
157 predicate * GTY((skip)) loop_stride;
kono
parents:
diff changeset
158 /* Predicate on when some array indexes become constants. */
kono
parents:
diff changeset
159 predicate * GTY((skip)) array_index;
kono
parents:
diff changeset
160 /* Estimated growth for inlining all copies of the function before start
kono
parents:
diff changeset
161 of small functions inlining.
kono
parents:
diff changeset
162 This value will get out of date as the callers are duplicated, but
kono
parents:
diff changeset
163 using up-to-date value in the badness metric mean a lot of extra
kono
parents:
diff changeset
164 expenses. */
kono
parents:
diff changeset
165 int growth;
kono
parents:
diff changeset
166 /* Number of SCC on the beginning of inlining process. */
kono
parents:
diff changeset
167 int scc_no;
kono
parents:
diff changeset
168
kono
parents:
diff changeset
169 /* Record time and size under given predicates. */
kono
parents:
diff changeset
170 void account_size_time (int, sreal, const predicate &, const predicate &);
kono
parents:
diff changeset
171
kono
parents:
diff changeset
172 /* We keep values scaled up, so fractional sizes can be accounted. */
kono
parents:
diff changeset
173 static const int size_scale = 2;
kono
parents:
diff changeset
174 };
kono
parents:
diff changeset
175
kono
parents:
diff changeset
176 class GTY((user)) ipa_fn_summary_t: public function_summary <ipa_fn_summary *>
kono
parents:
diff changeset
177 {
kono
parents:
diff changeset
178 public:
kono
parents:
diff changeset
179 ipa_fn_summary_t (symbol_table *symtab, bool ggc):
kono
parents:
diff changeset
180 function_summary <ipa_fn_summary *> (symtab, ggc) {}
kono
parents:
diff changeset
181
kono
parents:
diff changeset
182 static ipa_fn_summary_t *create_ggc (symbol_table *symtab)
kono
parents:
diff changeset
183 {
kono
parents:
diff changeset
184 struct ipa_fn_summary_t *summary = new (ggc_alloc <ipa_fn_summary_t> ())
kono
parents:
diff changeset
185 ipa_fn_summary_t(symtab, true);
kono
parents:
diff changeset
186 summary->disable_insertion_hook ();
kono
parents:
diff changeset
187 return summary;
kono
parents:
diff changeset
188 }
kono
parents:
diff changeset
189
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
190 /* Remove ipa_fn_summary for all callees of NODE. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
191 void remove_callees (cgraph_node *node);
111
kono
parents:
diff changeset
192
kono
parents:
diff changeset
193 virtual void insert (cgraph_node *, ipa_fn_summary *);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
194 virtual void remove (cgraph_node *node, ipa_fn_summary *)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
195 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
196 remove_callees (node);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
197 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
198
111
kono
parents:
diff changeset
199 virtual void duplicate (cgraph_node *src, cgraph_node *dst,
kono
parents:
diff changeset
200 ipa_fn_summary *src_data, ipa_fn_summary *dst_data);
kono
parents:
diff changeset
201 };
kono
parents:
diff changeset
202
kono
parents:
diff changeset
203 extern GTY(()) function_summary <ipa_fn_summary *> *ipa_fn_summaries;
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205 /* Information kept about callgraph edges. */
kono
parents:
diff changeset
206 struct ipa_call_summary
kono
parents:
diff changeset
207 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
208 /* Keep all field empty so summary dumping works during its computation.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
209 This is useful for debugging. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
210 ipa_call_summary ()
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
211 : predicate (NULL), param (vNULL), call_stmt_size (0), call_stmt_time (0),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
212 loop_depth (0), is_return_callee_uncaptured (false)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
213 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
214 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
215
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
216 /* Copy constructor. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
217 ipa_call_summary (const ipa_call_summary &s):
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
218 predicate (s.predicate), param (s.param), call_stmt_size (s.call_stmt_size),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
219 call_stmt_time (s.call_stmt_time), loop_depth (s.loop_depth),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
220 is_return_callee_uncaptured (s.is_return_callee_uncaptured)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
221 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
222 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
223
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
224 /* Default destructor. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
225 ~ipa_call_summary ();
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
226
111
kono
parents:
diff changeset
227 class predicate *predicate;
kono
parents:
diff changeset
228 /* Vector indexed by parameters. */
kono
parents:
diff changeset
229 vec<inline_param_summary> param;
kono
parents:
diff changeset
230 /* Estimated size and time of the call statement. */
kono
parents:
diff changeset
231 int call_stmt_size;
kono
parents:
diff changeset
232 int call_stmt_time;
kono
parents:
diff changeset
233 /* Depth of loop nest, 0 means no nesting. */
kono
parents:
diff changeset
234 unsigned int loop_depth;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
235 /* Indicates whether the caller returns the value of it's callee. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
236 bool is_return_callee_uncaptured;
111
kono
parents:
diff changeset
237 };
kono
parents:
diff changeset
238
kono
parents:
diff changeset
239 class ipa_call_summary_t: public call_summary <ipa_call_summary *>
kono
parents:
diff changeset
240 {
kono
parents:
diff changeset
241 public:
kono
parents:
diff changeset
242 ipa_call_summary_t (symbol_table *symtab, bool ggc):
kono
parents:
diff changeset
243 call_summary <ipa_call_summary *> (symtab, ggc) {}
kono
parents:
diff changeset
244
kono
parents:
diff changeset
245 /* Hook that is called by summary when an edge is duplicated. */
kono
parents:
diff changeset
246 virtual void duplicate (cgraph_edge *src, cgraph_edge *dst,
kono
parents:
diff changeset
247 ipa_call_summary *src_data,
kono
parents:
diff changeset
248 ipa_call_summary *dst_data);
kono
parents:
diff changeset
249 };
kono
parents:
diff changeset
250
kono
parents:
diff changeset
251 extern call_summary <ipa_call_summary *> *ipa_call_summaries;
kono
parents:
diff changeset
252
kono
parents:
diff changeset
253 /* In ipa-fnsummary.c */
kono
parents:
diff changeset
254 void ipa_debug_fn_summary (struct cgraph_node *);
kono
parents:
diff changeset
255 void ipa_dump_fn_summaries (FILE *f);
kono
parents:
diff changeset
256 void ipa_dump_fn_summary (FILE *f, struct cgraph_node *node);
kono
parents:
diff changeset
257 void ipa_dump_hints (FILE *f, ipa_hints);
kono
parents:
diff changeset
258 void ipa_free_fn_summary (void);
kono
parents:
diff changeset
259 void inline_analyze_function (struct cgraph_node *node);
kono
parents:
diff changeset
260 void estimate_ipcp_clone_size_and_time (struct cgraph_node *,
kono
parents:
diff changeset
261 vec<tree>,
kono
parents:
diff changeset
262 vec<ipa_polymorphic_call_context>,
kono
parents:
diff changeset
263 vec<ipa_agg_jump_function_p>,
kono
parents:
diff changeset
264 int *, sreal *, sreal *,
kono
parents:
diff changeset
265 ipa_hints *);
kono
parents:
diff changeset
266 void ipa_merge_fn_summary_after_inlining (struct cgraph_edge *edge);
kono
parents:
diff changeset
267 void ipa_update_overall_fn_summary (struct cgraph_node *node);
kono
parents:
diff changeset
268 void compute_fn_summary (struct cgraph_node *, bool);
kono
parents:
diff changeset
269
kono
parents:
diff changeset
270
kono
parents:
diff changeset
271 void evaluate_properties_for_edge (struct cgraph_edge *e, bool inline_p,
kono
parents:
diff changeset
272 clause_t *clause_ptr,
kono
parents:
diff changeset
273 clause_t *nonspec_clause_ptr,
kono
parents:
diff changeset
274 vec<tree> *known_vals_ptr,
kono
parents:
diff changeset
275 vec<ipa_polymorphic_call_context>
kono
parents:
diff changeset
276 *known_contexts_ptr,
kono
parents:
diff changeset
277 vec<ipa_agg_jump_function_p> *);
kono
parents:
diff changeset
278 void estimate_node_size_and_time (struct cgraph_node *node,
kono
parents:
diff changeset
279 clause_t possible_truths,
kono
parents:
diff changeset
280 clause_t nonspec_possible_truths,
kono
parents:
diff changeset
281 vec<tree> known_vals,
kono
parents:
diff changeset
282 vec<ipa_polymorphic_call_context>,
kono
parents:
diff changeset
283 vec<ipa_agg_jump_function_p> known_aggs,
kono
parents:
diff changeset
284 int *ret_size, int *ret_min_size,
kono
parents:
diff changeset
285 sreal *ret_time,
kono
parents:
diff changeset
286 sreal *ret_nonspecialized_time,
kono
parents:
diff changeset
287 ipa_hints *ret_hints,
kono
parents:
diff changeset
288 vec<inline_param_summary>
kono
parents:
diff changeset
289 inline_param_summary);
kono
parents:
diff changeset
290
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
291 void ipa_fnsummary_c_finalize (void);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
292
111
kono
parents:
diff changeset
293 #endif /* GCC_IPA_FNSUMMARY_H */