]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/ipa-fnsummary.h
PR target/84369
[thirdparty/gcc.git] / gcc / ipa-fnsummary.h
CommitLineData
b9a58fc5 1/* IPA function body analysis.
fbd26352 2 Copyright (C) 2003-2019 Free Software Foundation, Inc.
b9a58fc5 3 Contributed by Jan Hubicka
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9Software Foundation; either version 3, or (at your option) any later
10version.
11
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
16
17You should have received a copy of the GNU General Public License
18along 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
1297cbcd 28/* Hints are reasons why IPA heuristics should preffer specializing given
b9a58fc5 29 function. They are represtented as bitmap of the following values. */
1297cbcd 30enum ipa_hints_vals {
31 /* When specialization turns indirect call into a direct call,
b9a58fc5 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
1297cbcd 45 it. Set by simple_edge_hints in ipa-inline-analysis.c. */
b9a58fc5 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.
1297cbcd 49 Set by simple_edge_hints in ipa-inline-analysis.c. */
b9a58fc5 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
1297cbcd 58typedef int ipa_hints;
b9a58fc5 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
65struct agg_position_info
66{
67 HOST_WIDE_INT offset;
68 bool agg_contents;
69 bool by_ref;
70};
71
1297cbcd 72/* Representation of function body size and time depending on the call
b9a58fc5 73 context. We keep simple array of record, every containing of predicate
1297cbcd 74 and time/size to account. */
b9a58fc5 75struct 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. */
1297cbcd 88struct GTY(()) ipa_fn_summary
b9a58fc5 89{
d2c2513e 90 /* Keep all field empty so summary dumping works during its computation.
91 This is useful for debugging. */
92 ipa_fn_summary ()
93 : estimated_self_stack_size (0), self_size (0), min_size (0),
94 inlinable (false), single_caller (false),
95 fp_expressions (false), estimated_stack_size (false),
96 stack_frame_offset (false), time (0), size (0), conds (NULL),
97 size_time_table (NULL), loop_iterations (NULL), loop_stride (NULL),
98 array_index (NULL), growth (0), scc_no (0)
99 {
100 }
101
102 /* Copy constructor. */
103 ipa_fn_summary (const ipa_fn_summary &s)
104 : estimated_self_stack_size (s.estimated_self_stack_size),
105 self_size (s.self_size), min_size (s.min_size),
106 inlinable (s.inlinable), single_caller (s.single_caller),
107 fp_expressions (s.fp_expressions),
108 estimated_stack_size (s.estimated_stack_size),
109 stack_frame_offset (s.stack_frame_offset), time (s.time), size (s.size),
110 conds (s.conds), size_time_table (s.size_time_table),
111 loop_iterations (s.loop_iterations), loop_stride (s.loop_stride),
112 array_index (s.array_index), growth (s.growth), scc_no (s.scc_no)
113 {}
114
115 /* Default constructor. */
116 ~ipa_fn_summary ();
117
b9a58fc5 118 /* Information about the function body itself. */
119
120 /* Estimated stack frame consumption by the function. */
121 HOST_WIDE_INT estimated_self_stack_size;
122 /* Size of the function body. */
123 int self_size;
124 /* Minimal size increase after inlining. */
125 int min_size;
126
127 /* False when there something makes inlining impossible (such as va_arg). */
128 unsigned inlinable : 1;
b9a58fc5 129 /* True wen there is only one caller of the function before small function
130 inlining. */
131 unsigned int single_caller : 1;
132 /* True if function contains any floating point expressions. */
133 unsigned int fp_expressions : 1;
134
135 /* Information about function that will result after applying all the
136 inline decisions present in the callgraph. Generally kept up to
137 date only for functions that are not inline clones. */
138
139 /* Estimated stack frame consumption by the function. */
140 HOST_WIDE_INT estimated_stack_size;
1297cbcd 141 /* Expected offset of the stack frame of function. */
b9a58fc5 142 HOST_WIDE_INT stack_frame_offset;
143 /* Estimated size of the function after inlining. */
144 sreal GTY((skip)) time;
145 int size;
146
147 /* Conditional size/time information. The summaries are being
148 merged during inlining. */
149 conditions conds;
150 vec<size_time_entry, va_gc> *size_time_table;
151
152 /* Predicate on when some loop in the function becomes to have known
153 bounds. */
154 predicate * GTY((skip)) loop_iterations;
155 /* Predicate on when some loop in the function becomes to have known
156 stride. */
157 predicate * GTY((skip)) loop_stride;
158 /* Predicate on when some array indexes become constants. */
159 predicate * GTY((skip)) array_index;
160 /* Estimated growth for inlining all copies of the function before start
161 of small functions inlining.
162 This value will get out of date as the callers are duplicated, but
163 using up-to-date value in the badness metric mean a lot of extra
164 expenses. */
165 int growth;
166 /* Number of SCC on the beginning of inlining process. */
167 int scc_no;
168
b9a58fc5 169 /* Record time and size under given predicates. */
170 void account_size_time (int, sreal, const predicate &, const predicate &);
171
1297cbcd 172 /* We keep values scaled up, so fractional sizes can be accounted. */
173 static const int size_scale = 2;
b9a58fc5 174};
175
1add72d5 176class GTY((user)) ipa_fn_summary_t:
177 public fast_function_summary <ipa_fn_summary *, va_gc>
b9a58fc5 178{
179public:
1add72d5 180 ipa_fn_summary_t (symbol_table *symtab):
181 fast_function_summary <ipa_fn_summary *, va_gc> (symtab) {}
b9a58fc5 182
1297cbcd 183 static ipa_fn_summary_t *create_ggc (symbol_table *symtab)
b9a58fc5 184 {
1297cbcd 185 struct ipa_fn_summary_t *summary = new (ggc_alloc <ipa_fn_summary_t> ())
1add72d5 186 ipa_fn_summary_t (symtab);
b9a58fc5 187 summary->disable_insertion_hook ();
188 return summary;
189 }
190
d2c2513e 191 /* Remove ipa_fn_summary for all callees of NODE. */
192 void remove_callees (cgraph_node *node);
b9a58fc5 193
1297cbcd 194 virtual void insert (cgraph_node *, ipa_fn_summary *);
d2c2513e 195 virtual void remove (cgraph_node *node, ipa_fn_summary *)
196 {
197 remove_callees (node);
198 }
199
b9a58fc5 200 virtual void duplicate (cgraph_node *src, cgraph_node *dst,
1297cbcd 201 ipa_fn_summary *src_data, ipa_fn_summary *dst_data);
b9a58fc5 202};
203
1add72d5 204extern GTY(()) fast_function_summary <ipa_fn_summary *, va_gc>
205 *ipa_fn_summaries;
b9a58fc5 206
207/* Information kept about callgraph edges. */
208struct ipa_call_summary
209{
d2c2513e 210 /* Keep all field empty so summary dumping works during its computation.
211 This is useful for debugging. */
212 ipa_call_summary ()
213 : predicate (NULL), param (vNULL), call_stmt_size (0), call_stmt_time (0),
214 loop_depth (0), is_return_callee_uncaptured (false)
215 {
216 }
217
218 /* Copy constructor. */
219 ipa_call_summary (const ipa_call_summary &s):
220 predicate (s.predicate), param (s.param), call_stmt_size (s.call_stmt_size),
221 call_stmt_time (s.call_stmt_time), loop_depth (s.loop_depth),
222 is_return_callee_uncaptured (s.is_return_callee_uncaptured)
223 {
224 }
225
226 /* Default destructor. */
227 ~ipa_call_summary ();
228
b9a58fc5 229 class predicate *predicate;
230 /* Vector indexed by parameters. */
231 vec<inline_param_summary> param;
232 /* Estimated size and time of the call statement. */
233 int call_stmt_size;
234 int call_stmt_time;
235 /* Depth of loop nest, 0 means no nesting. */
236 unsigned int loop_depth;
bd5ef087 237 /* Indicates whether the caller returns the value of it's callee. */
238 bool is_return_callee_uncaptured;
b9a58fc5 239};
240
1add72d5 241class ipa_call_summary_t: public fast_call_summary <ipa_call_summary *, va_heap>
b9a58fc5 242{
243public:
1add72d5 244 ipa_call_summary_t (symbol_table *symtab):
245 fast_call_summary <ipa_call_summary *, va_heap> (symtab) {}
b9a58fc5 246
b9a58fc5 247 /* Hook that is called by summary when an edge is duplicated. */
248 virtual void duplicate (cgraph_edge *src, cgraph_edge *dst,
249 ipa_call_summary *src_data,
250 ipa_call_summary *dst_data);
251};
252
1add72d5 253extern fast_call_summary <ipa_call_summary *, va_heap> *ipa_call_summaries;
b9a58fc5 254
255/* In ipa-fnsummary.c */
1297cbcd 256void ipa_debug_fn_summary (struct cgraph_node *);
257void ipa_dump_fn_summaries (FILE *f);
258void ipa_dump_fn_summary (FILE *f, struct cgraph_node *node);
259void ipa_dump_hints (FILE *f, ipa_hints);
a2da7d8a 260void ipa_free_fn_summary (void);
b9a58fc5 261void inline_analyze_function (struct cgraph_node *node);
b9a58fc5 262void estimate_ipcp_clone_size_and_time (struct cgraph_node *,
263 vec<tree>,
264 vec<ipa_polymorphic_call_context>,
265 vec<ipa_agg_jump_function_p>,
266 int *, sreal *, sreal *,
1297cbcd 267 ipa_hints *);
268void ipa_merge_fn_summary_after_inlining (struct cgraph_edge *edge);
269void ipa_update_overall_fn_summary (struct cgraph_node *node);
270void compute_fn_summary (struct cgraph_node *, bool);
b9a58fc5 271
272
273void evaluate_properties_for_edge (struct cgraph_edge *e, bool inline_p,
274 clause_t *clause_ptr,
275 clause_t *nonspec_clause_ptr,
276 vec<tree> *known_vals_ptr,
277 vec<ipa_polymorphic_call_context>
278 *known_contexts_ptr,
279 vec<ipa_agg_jump_function_p> *);
280void estimate_node_size_and_time (struct cgraph_node *node,
281 clause_t possible_truths,
282 clause_t nonspec_possible_truths,
283 vec<tree> known_vals,
284 vec<ipa_polymorphic_call_context>,
285 vec<ipa_agg_jump_function_p> known_aggs,
286 int *ret_size, int *ret_min_size,
287 sreal *ret_time,
288 sreal *ret_nonspecialized_time,
1297cbcd 289 ipa_hints *ret_hints,
b9a58fc5 290 vec<inline_param_summary>
291 inline_param_summary);
292
a450b652 293void ipa_fnsummary_c_finalize (void);
294
b9a58fc5 295#endif /* GCC_IPA_FNSUMMARY_H */