1 /* IPA function body analysis.
2 Copyright (C) 2003-2019 Free Software Foundation, Inc.
3 Contributed by Jan Hubicka
5 This file is part of GCC.
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
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
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/>. */
21 #ifndef GCC_IPA_SUMMARY_H
22 #define GCC_IPA_SUMMARY_H
25 #include "ipa-predicate.h"
28 /* Hints are reasons why IPA heuristics should preffer specializing given
29 function. They are represtented as bitmap of the following values. */
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
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
58 typedef int ipa_hints
;
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
65 struct agg_position_info
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 class GTY(()) size_time_entry
78 /* Predicate for code to be executed. */
79 predicate exec_predicate
;
80 /* Predicate for value to be constant and optimized out in a specialized copy.
81 When deciding on specialization this makes it possible to see how much
82 the executed code paths will simplify. */
83 predicate nonconst_predicate
;
85 sreal
GTY((skip
)) time
;
88 /* Function inlining information. */
89 class GTY(()) ipa_fn_summary
92 /* Keep all field empty so summary dumping works during its computation.
93 This is useful for debugging. */
95 : estimated_self_stack_size (0), self_size (0), min_size (0),
96 inlinable (false), single_caller (false),
97 fp_expressions (false), estimated_stack_size (false),
98 stack_frame_offset (false), time (0), size (0), conds (NULL
),
99 size_time_table (NULL
), loop_iterations (NULL
), loop_stride (NULL
),
100 array_index (NULL
), growth (0), scc_no (0)
104 /* Copy constructor. */
105 ipa_fn_summary (const ipa_fn_summary
&s
)
106 : estimated_self_stack_size (s
.estimated_self_stack_size
),
107 self_size (s
.self_size
), min_size (s
.min_size
),
108 inlinable (s
.inlinable
), single_caller (s
.single_caller
),
109 fp_expressions (s
.fp_expressions
),
110 estimated_stack_size (s
.estimated_stack_size
),
111 stack_frame_offset (s
.stack_frame_offset
), time (s
.time
), size (s
.size
),
112 conds (s
.conds
), size_time_table (s
.size_time_table
),
113 loop_iterations (s
.loop_iterations
), loop_stride (s
.loop_stride
),
114 array_index (s
.array_index
), growth (s
.growth
), scc_no (s
.scc_no
)
117 /* Default constructor. */
120 /* Information about the function body itself. */
122 /* Estimated stack frame consumption by the function. */
123 HOST_WIDE_INT estimated_self_stack_size
;
124 /* Size of the function body. */
126 /* Minimal size increase after inlining. */
129 /* False when there something makes inlining impossible (such as va_arg). */
130 unsigned inlinable
: 1;
131 /* True wen there is only one caller of the function before small function
133 unsigned int single_caller
: 1;
134 /* True if function contains any floating point expressions. */
135 unsigned int fp_expressions
: 1;
137 /* Information about function that will result after applying all the
138 inline decisions present in the callgraph. Generally kept up to
139 date only for functions that are not inline clones. */
141 /* Estimated stack frame consumption by the function. */
142 HOST_WIDE_INT estimated_stack_size
;
143 /* Expected offset of the stack frame of function. */
144 HOST_WIDE_INT stack_frame_offset
;
145 /* Estimated size of the function after inlining. */
146 sreal
GTY((skip
)) time
;
149 /* Conditional size/time information. The summaries are being
150 merged during inlining. */
152 vec
<size_time_entry
, va_gc
> *size_time_table
;
154 /* Predicate on when some loop in the function becomes to have known
156 predicate
* GTY((skip
)) loop_iterations
;
157 /* Predicate on when some loop in the function becomes to have known
159 predicate
* GTY((skip
)) loop_stride
;
160 /* Predicate on when some array indexes become constants. */
161 predicate
* GTY((skip
)) array_index
;
162 /* Estimated growth for inlining all copies of the function before start
163 of small functions inlining.
164 This value will get out of date as the callers are duplicated, but
165 using up-to-date value in the badness metric mean a lot of extra
168 /* Number of SCC on the beginning of inlining process. */
171 /* Record time and size under given predicates. */
172 void account_size_time (int, sreal
, const predicate
&, const predicate
&);
174 /* We keep values scaled up, so fractional sizes can be accounted. */
175 static const int size_scale
= 2;
178 class GTY((user
)) ipa_fn_summary_t
:
179 public fast_function_summary
<ipa_fn_summary
*, va_gc
>
182 ipa_fn_summary_t (symbol_table
*symtab
):
183 fast_function_summary
<ipa_fn_summary
*, va_gc
> (symtab
) {}
185 static ipa_fn_summary_t
*create_ggc (symbol_table
*symtab
)
187 struct ipa_fn_summary_t
*summary
= new (ggc_alloc
<ipa_fn_summary_t
> ())
188 ipa_fn_summary_t (symtab
);
189 summary
->disable_insertion_hook ();
193 /* Remove ipa_fn_summary for all callees of NODE. */
194 void remove_callees (cgraph_node
*node
);
196 virtual void insert (cgraph_node
*, ipa_fn_summary
*);
197 virtual void remove (cgraph_node
*node
, ipa_fn_summary
*)
199 remove_callees (node
);
202 virtual void duplicate (cgraph_node
*src
, cgraph_node
*dst
,
203 ipa_fn_summary
*src_data
, ipa_fn_summary
*dst_data
);
206 extern GTY(()) fast_function_summary
<ipa_fn_summary
*, va_gc
>
209 /* Information kept about callgraph edges. */
210 class ipa_call_summary
213 /* Keep all field empty so summary dumping works during its computation.
214 This is useful for debugging. */
216 : predicate (NULL
), param (vNULL
), call_stmt_size (0), call_stmt_time (0),
217 loop_depth (0), is_return_callee_uncaptured (false)
221 /* Copy constructor. */
222 ipa_call_summary (const ipa_call_summary
&s
):
223 predicate (s
.predicate
), param (s
.param
), call_stmt_size (s
.call_stmt_size
),
224 call_stmt_time (s
.call_stmt_time
), loop_depth (s
.loop_depth
),
225 is_return_callee_uncaptured (s
.is_return_callee_uncaptured
)
229 /* Default destructor. */
230 ~ipa_call_summary ();
232 class predicate
*predicate
;
233 /* Vector indexed by parameters. */
234 vec
<inline_param_summary
> param
;
235 /* Estimated size and time of the call statement. */
238 /* Depth of loop nest, 0 means no nesting. */
239 unsigned int loop_depth
;
240 /* Indicates whether the caller returns the value of it's callee. */
241 bool is_return_callee_uncaptured
;
244 class ipa_call_summary_t
: public fast_call_summary
<ipa_call_summary
*, va_heap
>
247 ipa_call_summary_t (symbol_table
*symtab
):
248 fast_call_summary
<ipa_call_summary
*, va_heap
> (symtab
) {}
250 /* Hook that is called by summary when an edge is duplicated. */
251 virtual void duplicate (cgraph_edge
*src
, cgraph_edge
*dst
,
252 ipa_call_summary
*src_data
,
253 ipa_call_summary
*dst_data
);
256 extern fast_call_summary
<ipa_call_summary
*, va_heap
> *ipa_call_summaries
;
258 /* In ipa-fnsummary.c */
259 void ipa_debug_fn_summary (struct cgraph_node
*);
260 void ipa_dump_fn_summaries (FILE *f
);
261 void ipa_dump_fn_summary (FILE *f
, struct cgraph_node
*node
);
262 void ipa_dump_hints (FILE *f
, ipa_hints
);
263 void ipa_free_fn_summary (void);
264 void inline_analyze_function (struct cgraph_node
*node
);
265 void estimate_ipcp_clone_size_and_time (struct cgraph_node
*,
267 vec
<ipa_polymorphic_call_context
>,
268 vec
<ipa_agg_jump_function_p
>,
269 int *, sreal
*, sreal
*,
271 void ipa_merge_fn_summary_after_inlining (struct cgraph_edge
*edge
);
272 void ipa_update_overall_fn_summary (struct cgraph_node
*node
);
273 void compute_fn_summary (struct cgraph_node
*, bool);
276 void evaluate_properties_for_edge (struct cgraph_edge
*e
, bool inline_p
,
277 clause_t
*clause_ptr
,
278 clause_t
*nonspec_clause_ptr
,
279 vec
<tree
> *known_vals_ptr
,
280 vec
<ipa_polymorphic_call_context
>
282 vec
<ipa_agg_jump_function_p
> *);
283 void estimate_node_size_and_time (struct cgraph_node
*node
,
284 clause_t possible_truths
,
285 clause_t nonspec_possible_truths
,
286 vec
<tree
> known_vals
,
287 vec
<ipa_polymorphic_call_context
>,
288 vec
<ipa_agg_jump_function_p
> known_aggs
,
289 int *ret_size
, int *ret_min_size
,
291 sreal
*ret_nonspecialized_time
,
292 ipa_hints
*ret_hints
,
293 vec
<inline_param_summary
>
294 inline_param_summary
);
296 void ipa_fnsummary_c_finalize (void);
298 #endif /* GCC_IPA_FNSUMMARY_H */