comparison gcc/ipa-fnsummary.h @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children 84e7813d76e9
comparison
equal deleted inserted replaced
68:561a7518be6b 111:04ced10e8804
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 /* 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 /* 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 ipa_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 /* Representation of function body size and time depending on the call
73 context. We keep simple array of record, every containing of predicate
74 and time/size to account. */
75 struct GTY(()) size_time_entry
76 {
77 /* Predicate for code to be executed. */
78 predicate exec_predicate;
79 /* Predicate for value to be constant and optimized out in a specialized copy.
80 When deciding on specialization this makes it possible to see how much
81 the executed code paths will simplify. */
82 predicate nonconst_predicate;
83 int size;
84 sreal GTY((skip)) time;
85 };
86
87 /* Function inlining information. */
88 struct GTY(()) ipa_fn_summary
89 {
90 /* Information about the function body itself. */
91
92 /* Estimated stack frame consumption by the function. */
93 HOST_WIDE_INT estimated_self_stack_size;
94 /* Size of the function body. */
95 int self_size;
96 /* Minimal size increase after inlining. */
97 int min_size;
98
99 /* False when there something makes inlining impossible (such as va_arg). */
100 unsigned inlinable : 1;
101 /* True when function contains cilk spawn (and thus we can not inline
102 into it). */
103 unsigned contains_cilk_spawn : 1;
104 /* True wen there is only one caller of the function before small function
105 inlining. */
106 unsigned int single_caller : 1;
107 /* True if function contains any floating point expressions. */
108 unsigned int fp_expressions : 1;
109
110 /* Information about function that will result after applying all the
111 inline decisions present in the callgraph. Generally kept up to
112 date only for functions that are not inline clones. */
113
114 /* Estimated stack frame consumption by the function. */
115 HOST_WIDE_INT estimated_stack_size;
116 /* Expected offset of the stack frame of function. */
117 HOST_WIDE_INT stack_frame_offset;
118 /* Estimated size of the function after inlining. */
119 sreal GTY((skip)) time;
120 int size;
121
122 /* Conditional size/time information. The summaries are being
123 merged during inlining. */
124 conditions conds;
125 vec<size_time_entry, va_gc> *size_time_table;
126
127 /* Predicate on when some loop in the function becomes to have known
128 bounds. */
129 predicate * GTY((skip)) loop_iterations;
130 /* Predicate on when some loop in the function becomes to have known
131 stride. */
132 predicate * GTY((skip)) loop_stride;
133 /* Predicate on when some array indexes become constants. */
134 predicate * GTY((skip)) array_index;
135 /* Estimated growth for inlining all copies of the function before start
136 of small functions inlining.
137 This value will get out of date as the callers are duplicated, but
138 using up-to-date value in the badness metric mean a lot of extra
139 expenses. */
140 int growth;
141 /* Number of SCC on the beginning of inlining process. */
142 int scc_no;
143
144 /* Keep all field empty so summary dumping works during its computation.
145 This is useful for debugging. */
146 ipa_fn_summary ()
147 : estimated_self_stack_size (0), self_size (0), min_size (0),
148 inlinable (false), contains_cilk_spawn (false), single_caller (false),
149 fp_expressions (false), estimated_stack_size (false),
150 stack_frame_offset (false), time (0), size (0), conds (NULL),
151 size_time_table (NULL), loop_iterations (NULL), loop_stride (NULL),
152 array_index (NULL), growth (0), scc_no (0)
153 {
154 }
155
156 /* Record time and size under given predicates. */
157 void account_size_time (int, sreal, const predicate &, const predicate &);
158
159 /* Reset summary to empty state. */
160 void reset (struct cgraph_node *node);
161
162 /* We keep values scaled up, so fractional sizes can be accounted. */
163 static const int size_scale = 2;
164 };
165
166 class GTY((user)) ipa_fn_summary_t: public function_summary <ipa_fn_summary *>
167 {
168 public:
169 ipa_fn_summary_t (symbol_table *symtab, bool ggc):
170 function_summary <ipa_fn_summary *> (symtab, ggc) {}
171
172 static ipa_fn_summary_t *create_ggc (symbol_table *symtab)
173 {
174 struct ipa_fn_summary_t *summary = new (ggc_alloc <ipa_fn_summary_t> ())
175 ipa_fn_summary_t(symtab, true);
176 summary->disable_insertion_hook ();
177 return summary;
178 }
179
180
181 virtual void insert (cgraph_node *, ipa_fn_summary *);
182 virtual void remove (cgraph_node *node, ipa_fn_summary *);
183 virtual void duplicate (cgraph_node *src, cgraph_node *dst,
184 ipa_fn_summary *src_data, ipa_fn_summary *dst_data);
185 };
186
187 extern GTY(()) function_summary <ipa_fn_summary *> *ipa_fn_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 ipa_debug_fn_summary (struct cgraph_node *);
231 void ipa_dump_fn_summaries (FILE *f);
232 void ipa_dump_fn_summary (FILE *f, struct cgraph_node *node);
233 void ipa_dump_hints (FILE *f, ipa_hints);
234 void ipa_free_fn_summary (void);
235 void inline_analyze_function (struct cgraph_node *node);
236 void estimate_ipcp_clone_size_and_time (struct cgraph_node *,
237 vec<tree>,
238 vec<ipa_polymorphic_call_context>,
239 vec<ipa_agg_jump_function_p>,
240 int *, sreal *, sreal *,
241 ipa_hints *);
242 void ipa_merge_fn_summary_after_inlining (struct cgraph_edge *edge);
243 void ipa_update_overall_fn_summary (struct cgraph_node *node);
244 void compute_fn_summary (struct cgraph_node *, bool);
245
246
247 void evaluate_properties_for_edge (struct cgraph_edge *e, bool inline_p,
248 clause_t *clause_ptr,
249 clause_t *nonspec_clause_ptr,
250 vec<tree> *known_vals_ptr,
251 vec<ipa_polymorphic_call_context>
252 *known_contexts_ptr,
253 vec<ipa_agg_jump_function_p> *);
254 void estimate_node_size_and_time (struct cgraph_node *node,
255 clause_t possible_truths,
256 clause_t nonspec_possible_truths,
257 vec<tree> known_vals,
258 vec<ipa_polymorphic_call_context>,
259 vec<ipa_agg_jump_function_p> known_aggs,
260 int *ret_size, int *ret_min_size,
261 sreal *ret_time,
262 sreal *ret_nonspecialized_time,
263 ipa_hints *ret_hints,
264 vec<inline_param_summary>
265 inline_param_summary);
266
267 #endif /* GCC_IPA_FNSUMMARY_H */