GCC Middle and Back End API Reference
ipa-fnsummary.h
Go to the documentation of this file.
1/* IPA function body analysis.
2 Copyright (C) 2003-2026 Free Software Foundation, Inc.
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
28/* Hints are reasons why IPA heuristics should prefer specializing given
29 function. They are represented as bitmap of the following values. */
31 /* When specialization turns indirect call into a direct call,
32 it is good idea to do so. */
34 /* Inlining may make loop iterations or loop stride known. It is good idea
35 to do so because it enables loop optimizations. */
38 /* Inlining within same strongly connected component of callgraph is often
39 a loss due to increased stack frame usage and prologue setup costs. */
41 /* Inlining functions in strongly connected component is not such a great
42 win. */
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.cc. */
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.cc. */
51 /* We know that the callee is hot by profile. */
53 /* There is builtin_constant_p dependent on parameter which is usually
54 a strong hint to inline. */
56};
57
58typedef 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
66{
67 HOST_WIDE_INT offset;
69 bool by_ref;
72};
73
74/* Representation of function body size and time depending on the call
75 context. We keep simple array of record, every containing of predicate
76 and time/size to account. */
78{
79public:
80 /* Predicate for code to be executed. */
82 /* Predicate for value to be constant and optimized out in a specialized copy.
83 When deciding on specialization this makes it possible to see how much
84 the executed code paths will simplify. */
86 int size;
88};
89
90/* Summary about function and stack frame sizes. We keep this info
91 for inline clones and also for WPA streaming. For this reason this is not
92 part of ipa_fn_summary which exists only for offline functions. */
94{
95public:
96 /* Estimated stack frame consumption by the function. */
98 /* Size of the function body. */
100 /* Estimated size of the function after inlining. */
101 int size;
102
105 {
106 }
107};
108
109/* Structure to capture how frequently some interesting events occur given a
110 particular predicate. The structure is used to estimate how often we
111 encounter loops with known iteration count or stride in various
112 contexts. */
113
115{
116 /* The described event happens with this frequency... */
118 /* ...when this predicate evaluates to false. */
120};
121
122/* Function inlining information. */
124{
125public:
126 /* Keep all field empty so summary dumping works during its computation.
127 This is useful for debugging. */
140
141 /* Copy constructor. */
154
155 /* Default constructor. */
157
158 /* Information about the function body itself. */
159
160 /* Minimal size increase after inlining. */
162
163 /* False when there something makes inlining impossible (such as va_arg). */
164 unsigned inlinable : 1;
165 /* True wen there is only one caller of the function before small function
166 inlining. */
167 unsigned int single_caller : 1;
168 /* True if function contains any floating point expressions. */
169 unsigned int fp_expressions : 1;
170 /* Cache for analysis of can_early_inline_edge_p. */
172 /* Like fp_expressions field above, but it's to hold some target specific
173 information, such as some target specific isa flags. Note that for
174 offloading target compilers, this field isn't streamed. */
175 unsigned int target_info;
176
177 /* Information about function that will result after applying all the
178 inline decisions present in the callgraph. Generally kept up to
179 date only for functions that are not inline clones. */
180
181 /* Estimated stack frame consumption by the function. */
182 HOST_WIDE_INT estimated_stack_size;
183 /* Estimated runtime of function after inlining. */
184 sreal GTY((skip)) time;
185
186 /* Conditional size/time information. The summaries are being
187 merged during inlining. */
189 /* Normal code is accounted in size_time_table, while calls are
190 accounted in call_size_time_table. This is because calls
191 are often adjusted by IPA optimizations and thus this summary
192 is generated from call summary information when needed. */
194 /* Unlike size_time_table that is initialized for all summaries
195 call_size_time_table is allocated only for functions with
196 many calls. Use efficient vl_ptr storage. */
198
199 /* Predicates on when some loops in the function can have known bounds. */
201 /* Predicates on when some loops in the function can have known strides. */
203 /* Parameters tested by builtin_constant_p. */
205 /* Estimated growth for inlining all copies of the function before start
206 of small functions inlining.
207 This value will get out of date as the callers are duplicated, but
208 using up-to-date value in the badness metric mean a lot of extra
209 expenses. */
211 /* Number of SCC on the beginning of inlining process. */
213
214 /* Record time and size under given predicates. */
215 void account_size_time (int, sreal, const ipa_predicate &,
216 const ipa_predicate &,
217 bool call = false);
218
219 /* We keep values scaled up, so fractional sizes can be accounted. */
220 static const int size_scale = 2;
221 /* Maximal size of size_time_table before we start to be conservative. */
222 static const int max_size_time_table_size = 256;
223};
224
225class GTY((user)) ipa_fn_summary_t:
226 public fast_function_summary <ipa_fn_summary *, va_gc>
227{
228public:
231
233 {
234 class ipa_fn_summary_t *summary
236 summary->disable_insertion_hook ();
237 return summary;
238 }
239
240 /* Remove ipa_fn_summary for all callees of NODE. */
241 void remove_callees (cgraph_node *node);
242
243 void insert (cgraph_node *, ipa_fn_summary *) final override;
244 void remove (cgraph_node *node, ipa_fn_summary *) final override
245 {
247 }
248
249 void duplicate (cgraph_node *src, cgraph_node *dst,
250 ipa_fn_summary *src_data, ipa_fn_summary *dst_data)
251 final override;
252};
253
256
259{
260public:
263 {
264 disable_insertion_hook ();
265 }
266
268 ipa_size_summary *src_data,
269 ipa_size_summary *dst_data) final override
270 {
271 *dst_data = *src_data;
272 }
273};
274extern fast_function_summary <ipa_size_summary *, va_heap>
276
277/* Information kept about callgraph edges. */
279{
280public:
281 /* Keep all field empty so summary dumping works during its computation.
282 This is useful for debugging. */
288
289 /* Copy constructor. */
296
297 /* Default destructor. */
299
301 /* Vector indexed by parameters. */
303 /* Estimated size and time of the call statement. */
306 /* Depth of loop nest, 0 means no nesting. */
307 unsigned int loop_depth;
308 /* Indicates whether the caller returns the value of it's callee. */
310};
311
312class ipa_call_summary_t: public fast_call_summary <ipa_call_summary *, va_heap>
313{
314public:
317
318 /* Hook that is called by summary when an edge is duplicated. */
319 void duplicate (cgraph_edge *src, cgraph_edge *dst,
320 ipa_call_summary *src_data,
321 ipa_call_summary *dst_data) final override;
322};
323
324/* Estimated execution times, code sizes and other information about the
325 code executing a call described by ipa_call_context. */
326
328{
329 /* Estimated size needed to execute call in the given context. */
330 int size;
331
332 /* Minimal size needed for the call that is + independent on the call context
333 and can be used for fast estimates. */
335
336 /* Estimated time needed to execute call in the given context. */
338
339 /* Estimated time needed to execute the function when not ignoring
340 computations known to be constant in this context. */
342
343 /* Further discovered reasons why to inline or specialize the give calls. */
345
346 /* Frequency how often a loop with known number of iterations is encountered.
347 Calculated with hints. */
349
350 /* Frequency how often a loop with known strides is encountered. Calculated
351 with hints. */
353};
354
356
357/* This object describe a context of call. That is a summary of known
358 information about its parameters. Main purpose of this context is
359 to give more realistic estimations of function runtime, size and
360 inline hints. */
362{
363public:
365 clause_t possible_truths,
366 clause_t nonspec_possible_truths,
368 ipa_auto_call_arg_values *arg_values);
370 : m_node(NULL)
371 {
372 }
374 bool est_times = true, bool est_hints = true);
375 bool equal_to (const ipa_call_context &);
376 bool exists_p ()
377 {
378 return m_node != NULL;
379 }
380private:
381 /* Called function. */
383 /* Clause describing what predicate conditionals can be satisfied
384 in this context if function is inlined/specialized. */
386 /* Clause describing what predicate conditionals can be satisfied
387 in this context if function is kept offline. */
389 /* Inline summary maintains info about change probabilities. */
391
392 /* Even after having calculated clauses, the information about argument
393 values is used to resolve indirect calls. */
395
397};
398
399/* Variant of ipa_call_context that is stored in a cache over a longer period
400 of time. */
401
403{
404public:
405 void duplicate_from (const ipa_call_context &ctx);
406 void release ();
407};
408
409extern fast_call_summary <ipa_call_summary *, va_heap> *ipa_call_summaries;
410
411/* In ipa-fnsummary.cc */
412void ipa_debug_fn_summary (struct cgraph_node *);
413void ipa_dump_fn_summaries (FILE *f);
414void ipa_dump_fn_summary (FILE *f, struct cgraph_node *node);
415void ipa_dump_hints (FILE *f, ipa_hints);
416void ipa_free_fn_summary (void);
417void ipa_free_size_summary (void);
421 ipa_call_estimates *estimates);
423void ipa_update_overall_fn_summary (struct cgraph_node *node, bool reset = true);
424void compute_fn_summary (struct cgraph_node *, bool);
427
428
430 bool inline_p,
431 clause_t *clause_ptr,
432 clause_t *nonspec_clause_ptr,
434 bool compute_contexts);
435
436void ipa_fnsummary_cc_finalize (void);
437HOST_WIDE_INT ipa_get_stack_frame_offset (struct cgraph_node *node);
439
440/* Return true if EDGE is a cross module call. */
441
442inline bool
444{
445 /* Here we do not want to walk to alias target because ICF may create
446 cross-unit aliases. */
447 if (edge->caller->unit_id == edge->callee->unit_id)
448 return false;
449 /* If the call is to a (former) comdat function or s symbol with multiple
450 extern inline definitions then treat is as in-module call. */
451 if (edge->callee->merged_extern_inline || edge->callee->merged_comdat
452 || DECL_COMDAT (edge->callee->decl))
453 return false;
454 return true;
455}
456
457#endif /* GCC_IPA_FNSUMMARY_H */
symbol_table * symtab
Definition cgraph.cc:79
Definition vec.h:1667
Definition cgraph.h:1877
Definition symbol-summary.h:358
Definition ipa-prop.h:526
Definition ipa-fnsummary.h:403
void release()
Definition ipa-fnsummary.cc:4466
void duplicate_from(const ipa_call_context &ctx)
Definition ipa-fnsummary.cc:4394
Definition ipa-prop.h:562
Definition ipa-fnsummary.h:362
clause_t m_possible_truths
Definition ipa-fnsummary.h:385
vec< inline_param_summary > m_inline_param_summary
Definition ipa-fnsummary.h:390
cgraph_node * m_node
Definition ipa-fnsummary.h:382
bool equal_to(const ipa_call_context &)
Definition ipa-fnsummary.cc:4480
friend ipa_cached_call_context
Definition ipa-fnsummary.h:396
void estimate_size_and_time(ipa_call_estimates *estimates, bool est_times=true, bool est_hints=true)
Definition ipa-fnsummary.cc:4636
ipa_call_context(cgraph_node *node, clause_t possible_truths, clause_t nonspec_possible_truths, vec< inline_param_summary > inline_param_summary, ipa_auto_call_arg_values *arg_values)
Definition ipa-fnsummary.cc:4379
ipa_call_context()
Definition ipa-fnsummary.h:369
bool exists_p()
Definition ipa-fnsummary.h:376
clause_t m_nonspec_possible_truths
Definition ipa-fnsummary.h:388
ipa_call_arg_values m_avals
Definition ipa-fnsummary.h:394
ipa_call_summary_t(symbol_table *symtab)
Definition ipa-fnsummary.h:315
void duplicate(cgraph_edge *src, cgraph_edge *dst, ipa_call_summary *src_data, ipa_call_summary *dst_data) final override
Definition ipa-fnsummary.cc:1336
Definition ipa-fnsummary.h:279
bool is_return_callee_uncaptured
Definition ipa-fnsummary.h:309
unsigned int loop_depth
Definition ipa-fnsummary.h:307
int call_stmt_time
Definition ipa-fnsummary.h:305
ipa_call_summary(const ipa_call_summary &s)
Definition ipa-fnsummary.h:290
ipa_predicate * predicate
Definition ipa-fnsummary.h:300
int call_stmt_size
Definition ipa-fnsummary.h:304
vec< inline_param_summary > param
Definition ipa-fnsummary.h:302
ipa_call_summary()
Definition ipa-fnsummary.h:283
static ipa_fn_summary_t * create_ggc(symbol_table *symtab)
Definition ipa-fnsummary.h:232
ipa_fn_summary_t(symbol_table *symtab)
Definition ipa-fnsummary.h:229
void remove_callees(cgraph_node *node)
Definition ipa-fnsummary.cc:1133
void duplicate(cgraph_node *src, cgraph_node *dst, ipa_fn_summary *src_data, ipa_fn_summary *dst_data) final override
Definition ipa-fnsummary.cc:1174
void remove(cgraph_node *node, ipa_fn_summary *) final override
Definition ipa-fnsummary.h:244
Definition ipa-fnsummary.h:124
unsigned int target_info
Definition ipa-fnsummary.h:175
int scc_no
Definition ipa-fnsummary.h:212
static const int size_scale
Definition ipa-fnsummary.h:220
unsigned int safe_to_inline_to_always_inline
Definition ipa-fnsummary.h:171
HOST_WIDE_INT estimated_stack_size
Definition ipa-fnsummary.h:182
conditions conds
Definition ipa-fnsummary.h:188
vec< size_time_entry, va_heap, vl_ptr > call_size_time_table
Definition ipa-fnsummary.h:197
static const int max_size_time_table_size
Definition ipa-fnsummary.h:222
ipa_fn_summary(const ipa_fn_summary &s)
Definition ipa-fnsummary.h:142
sreal time
Definition ipa-fnsummary.h:184
void account_size_time(int, sreal, const ipa_predicate &, const ipa_predicate &, bool call=false)
Definition ipa-fnsummary.cc:170
int growth
Definition ipa-fnsummary.h:210
auto_vec< size_time_entry > size_time_table
Definition ipa-fnsummary.h:193
unsigned inlinable
Definition ipa-fnsummary.h:164
vec< ipa_freqcounting_predicate, va_gc > * loop_strides
Definition ipa-fnsummary.h:202
unsigned int fp_expressions
Definition ipa-fnsummary.h:169
int min_size
Definition ipa-fnsummary.h:161
vec< ipa_freqcounting_predicate, va_gc > * loop_iterations
Definition ipa-fnsummary.h:200
ipa_fn_summary()
Definition ipa-fnsummary.h:128
unsigned int single_caller
Definition ipa-fnsummary.h:167
vec< int, va_heap, vl_ptr > builtin_constant_p_parms
Definition ipa-fnsummary.h:204
Definition ipa-predicate.h:124
ipa_size_summary_t(symbol_table *symtab)
Definition ipa-fnsummary.h:261
void duplicate(cgraph_node *, cgraph_node *, ipa_size_summary *src_data, ipa_size_summary *dst_data) final override
Definition ipa-fnsummary.h:267
Definition ipa-fnsummary.h:94
int size
Definition ipa-fnsummary.h:101
HOST_WIDE_INT estimated_self_stack_size
Definition ipa-fnsummary.h:97
ipa_size_summary()
Definition ipa-fnsummary.h:103
int self_size
Definition ipa-fnsummary.h:99
Definition ipa-fnsummary.h:78
int size
Definition ipa-fnsummary.h:86
ipa_predicate exec_predicate
Definition ipa-fnsummary.h:81
sreal time
Definition ipa-fnsummary.h:87
ipa_predicate nonconst_predicate
Definition ipa-fnsummary.h:85
Definition sreal.h:41
Definition cgraph.h:2560
class edge_def * edge
Definition coretypes.h:356
#define GTY(x)
Definition coretypes.h:41
union tree_node * tree
Definition coretypes.h:97
static struct table_elt * insert(rtx, struct table_elt *, unsigned, machine_mode)
T * ggc_alloc_no_dtor(ALONE_CXX_MEM_STAT_INFO)
Definition ggc.h:209
void ipa_dump_fn_summaries(FILE *f)
Definition ipa-fnsummary.cc:1541
void ipa_free_fn_summary(void)
Definition ipa-fnsummary.cc:5722
HOST_WIDE_INT ipa_get_stack_frame_offset(struct cgraph_node *node)
Definition ipa-fnsummary.cc:4816
void ipa_dump_hints(FILE *f, ipa_hints hints)
Definition ipa-fnsummary.cc:108
fast_function_summary< ipa_size_summary *, va_heap > * ipa_size_summaries
Definition ipa-fnsummary.cc:99
void compute_fn_summary(struct cgraph_node *node, bool early)
Definition ipa-fnsummary.cc:3923
void ipa_dump_fn_summary(FILE *f, struct cgraph_node *node)
Definition ipa-fnsummary.cc:1448
void estimate_ipcp_clone_size_and_time(struct cgraph_node *node, ipa_auto_call_arg_values *avals, ipa_call_estimates *estimates)
Definition ipa-fnsummary.cc:4799
void ipa_free_size_summary(void)
Definition ipa-fnsummary.cc:5739
bool points_to_local_or_readonly_memory_p(tree t)
Definition ipa-fnsummary.cc:3169
fast_call_summary< ipa_call_summary *, va_heap > * ipa_call_summaries
Definition ipa-fnsummary.cc:100
void evaluate_properties_for_edge(struct cgraph_edge *e, bool inline_p, clause_t *clause_ptr, clause_t *nonspec_clause_ptr, ipa_auto_call_arg_values *avals, bool compute_contexts)
Definition ipa-fnsummary.cc:955
DEBUG_FUNCTION void ipa_debug_fn_summary(struct cgraph_node *node)
Definition ipa-fnsummary.cc:1535
fast_function_summary< ipa_fn_summary *, va_gc > * ipa_fn_summaries
Definition ipa-fnsummary.cc:98
void ipa_merge_fn_summary_after_inlining(struct cgraph_edge *edge)
Definition ipa-fnsummary.cc:5015
void ipa_update_overall_fn_summary(struct cgraph_node *node, bool reset)
Definition ipa-fnsummary.cc:5169
void inline_analyze_function(struct cgraph_node *node)
Definition ipa-fnsummary.cc:5214
bool refs_local_or_readonly_memory_p(tree t)
Definition ipa-fnsummary.cc:3143
void ipa_fnsummary_cc_finalize(void)
Definition ipa-fnsummary.cc:5896
void ipa_remove_from_growth_caches(struct cgraph_edge *edge)
Definition ipa-inline-analysis.cc:304
bool cross_module_call_p(struct cgraph_edge *edge)
Definition ipa-fnsummary.h:443
ipa_hints_vals
Definition ipa-fnsummary.h:30
@ INLINE_HINT_declared_inline
Definition ipa-fnsummary.h:46
@ INLINE_HINT_known_hot
Definition ipa-fnsummary.h:52
@ INLINE_HINT_same_scc
Definition ipa-fnsummary.h:40
@ INLINE_HINT_in_scc
Definition ipa-fnsummary.h:43
@ INLINE_HINT_builtin_constant_p
Definition ipa-fnsummary.h:55
@ INLINE_HINT_loop_iterations
Definition ipa-fnsummary.h:36
@ INLINE_HINT_loop_stride
Definition ipa-fnsummary.h:37
@ INLINE_HINT_cross_module
Definition ipa-fnsummary.h:50
@ INLINE_HINT_indirect_call
Definition ipa-fnsummary.h:33
int ipa_hints
Definition ipa-fnsummary.h:58
uint32_t clause_t
Definition ipa-predicate.h:122
vec< condition, va_gc > * conditions
Definition ipa-predicate.h:103
Definition custom-sarif-properties/state-graphs.h:33
Definition ipa-fnsummary.h:66
HOST_WIDE_INT offset
Definition ipa-fnsummary.h:67
bool agg_contents
Definition ipa-fnsummary.h:68
bool by_ref
Definition ipa-fnsummary.h:69
bool unknown_offset
Definition ipa-fnsummary.h:71
bool maybe_modified
Definition ipa-fnsummary.h:70
Definition cgraph.h:920
Definition ipa-predicate.h:76
Definition ipa-fnsummary.h:328
sreal loops_with_known_iterations
Definition ipa-fnsummary.h:348
int min_size
Definition ipa-fnsummary.h:334
ipa_hints hints
Definition ipa-fnsummary.h:344
sreal loops_with_known_strides
Definition ipa-fnsummary.h:352
sreal nonspecialized_time
Definition ipa-fnsummary.h:341
int size
Definition ipa-fnsummary.h:330
sreal time
Definition ipa-fnsummary.h:337
Definition ipa-fnsummary.h:115
sreal freq
Definition ipa-fnsummary.h:117
ipa_predicate * predicate
Definition ipa-fnsummary.h:119
Definition vec.h:359
Definition vec.h:283
Definition vec.h:450
#define NULL
Definition system.h:55
#define false
Definition system.h:832
#define DECL_COMDAT(NODE)
Definition tree.h:3606
constexpr vnull vNULL
Definition vec.h:569