1 /* Function summary pass.
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 /* Analysis of function bodies used by inter-procedural passes
23 We estimate for each function
24 - function body size and size after specializing into given context
25 - average function execution time in a given context
28 - call statement size, time and how often the parameters change
30 ipa_fn_summary data structures store above information locally (i.e.
31 parameters of the function itself) and globally (i.e. parameters of
32 the function created by applying all the inline decisions already
33 present in the callgraph).
35 We provide access to the ipa_fn_summary data structure and
36 basic logic updating the parameters when inlining is performed.
38 The summaries are context sensitive. Context means
39 1) partial assignment of known constant values of operands
40 2) whether function is inlined into the call or not.
41 It is easy to add more variants. To represent function size and time
42 that depends on context (i.e. it is known to be optimized away when
43 context is known either by inlining or from IP-CP and cloning),
46 estimate_edge_size_and_time can be used to query
47 function size/time in the given context. ipa_merge_fn_summary_after_inlining merges
48 properties of caller and callee after inlining.
50 Finally pass_inline_parameters is exported. This is used to drive
51 computation of function parameters used by the early inliner. IPA
52 inlined performs analysis via its analyze_function method. */
56 #include "coretypes.h"
60 #include "alloc-pool.h"
61 #include "tree-pass.h"
63 #include "tree-streamer.h"
65 #include "diagnostic.h"
66 #include "fold-const.h"
67 #include "print-tree.h"
68 #include "tree-inline.h"
69 #include "gimple-pretty-print.h"
71 #include "gimple-iterator.h"
73 #include "tree-ssa-loop-niter.h"
74 #include "tree-ssa-loop.h"
75 #include "symbol-summary.h"
77 #include "ipa-fnsummary.h"
79 #include "tree-scalar-evolution.h"
80 #include "ipa-utils.h"
81 #include "cfgexpand.h"
83 #include "stringpool.h"
87 fast_function_summary
<ipa_fn_summary
*, va_gc
> *ipa_fn_summaries
;
88 fast_function_summary
<ipa_size_summary
*, va_heap
> *ipa_size_summaries
;
89 fast_call_summary
<ipa_call_summary
*, va_heap
> *ipa_call_summaries
;
91 /* Edge predicates goes here. */
92 static object_allocator
<predicate
> edge_predicate_pool ("edge predicates");
97 ipa_dump_hints (FILE *f
, ipa_hints hints
)
101 fprintf (f
, "IPA hints:");
102 if (hints
& INLINE_HINT_indirect_call
)
104 hints
&= ~INLINE_HINT_indirect_call
;
105 fprintf (f
, " indirect_call");
107 if (hints
& INLINE_HINT_loop_iterations
)
109 hints
&= ~INLINE_HINT_loop_iterations
;
110 fprintf (f
, " loop_iterations");
112 if (hints
& INLINE_HINT_loop_stride
)
114 hints
&= ~INLINE_HINT_loop_stride
;
115 fprintf (f
, " loop_stride");
117 if (hints
& INLINE_HINT_same_scc
)
119 hints
&= ~INLINE_HINT_same_scc
;
120 fprintf (f
, " same_scc");
122 if (hints
& INLINE_HINT_in_scc
)
124 hints
&= ~INLINE_HINT_in_scc
;
125 fprintf (f
, " in_scc");
127 if (hints
& INLINE_HINT_cross_module
)
129 hints
&= ~INLINE_HINT_cross_module
;
130 fprintf (f
, " cross_module");
132 if (hints
& INLINE_HINT_declared_inline
)
134 hints
&= ~INLINE_HINT_declared_inline
;
135 fprintf (f
, " declared_inline");
137 if (hints
& INLINE_HINT_known_hot
)
139 hints
&= ~INLINE_HINT_known_hot
;
140 fprintf (f
, " known_hot");
146 /* Record SIZE and TIME to SUMMARY.
147 The accounted code will be executed when EXEC_PRED is true.
148 When NONCONST_PRED is false the code will evaulate to constant and
149 will get optimized out in specialized clones of the function.
150 If CALL is true account to call_size_time_table rather than
154 ipa_fn_summary::account_size_time (int size
, sreal time
,
155 const predicate
&exec_pred
,
156 const predicate
&nonconst_pred_in
,
162 predicate nonconst_pred
;
163 vec
<size_time_entry
, va_gc
> *table
= call
164 ? call_size_time_table
: size_time_table
;
166 if (exec_pred
== false)
169 nonconst_pred
= nonconst_pred_in
& exec_pred
;
171 if (nonconst_pred
== false)
174 /* We need to create initial empty unconitional clause, but otherwie
175 we don't need to account empty times and sizes. */
176 if (!size
&& time
== 0 && table
)
179 gcc_assert (time
>= 0);
181 for (i
= 0; vec_safe_iterate (table
, i
, &e
); i
++)
182 if (e
->exec_predicate
== exec_pred
183 && e
->nonconst_predicate
== nonconst_pred
)
188 if (i
== max_size_time_table_size
)
193 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
195 "\t\tReached limit on number of entries, "
196 "ignoring the predicate.");
198 if (dump_file
&& (dump_flags
& TDF_DETAILS
) && (time
!= 0 || size
))
201 "\t\tAccounting size:%3.2f, time:%3.2f on %spredicate exec:",
202 ((double) size
) / ipa_fn_summary::size_scale
,
203 (time
.to_double ()), found
? "" : "new ");
204 exec_pred
.dump (dump_file
, conds
, 0);
205 if (exec_pred
!= nonconst_pred
)
207 fprintf (dump_file
, " nonconst:");
208 nonconst_pred
.dump (dump_file
, conds
);
211 fprintf (dump_file
, "\n");
215 class size_time_entry new_entry
;
216 new_entry
.size
= size
;
217 new_entry
.time
= time
;
218 new_entry
.exec_predicate
= exec_pred
;
219 new_entry
.nonconst_predicate
= nonconst_pred
;
221 vec_safe_push (call_size_time_table
, new_entry
);
223 vec_safe_push (size_time_table
, new_entry
);
232 /* We proved E to be unreachable, redirect it to __bultin_unreachable. */
234 static struct cgraph_edge
*
235 redirect_to_unreachable (struct cgraph_edge
*e
)
237 struct cgraph_node
*callee
= !e
->inline_failed
? e
->callee
: NULL
;
238 struct cgraph_node
*target
= cgraph_node::get_create
239 (builtin_decl_implicit (BUILT_IN_UNREACHABLE
));
242 e
= e
->resolve_speculation (target
->decl
);
244 e
->make_direct (target
);
246 e
->redirect_callee (target
);
247 class ipa_call_summary
*es
= ipa_call_summaries
->get (e
);
248 e
->inline_failed
= CIF_UNREACHABLE
;
249 e
->count
= profile_count::zero ();
250 es
->call_stmt_size
= 0;
251 es
->call_stmt_time
= 0;
253 callee
->remove_symbol_and_inline_clones ();
257 /* Set predicate for edge E. */
260 edge_set_predicate (struct cgraph_edge
*e
, predicate
*predicate
)
262 /* If the edge is determined to be never executed, redirect it
263 to BUILTIN_UNREACHABLE to make it clear to IPA passes the call will
265 if (predicate
&& *predicate
== false
266 /* When handling speculative edges, we need to do the redirection
267 just once. Do it always on the direct edge, so we do not
268 attempt to resolve speculation while duplicating the edge. */
269 && (!e
->speculative
|| e
->callee
))
270 e
= redirect_to_unreachable (e
);
272 class ipa_call_summary
*es
= ipa_call_summaries
->get (e
);
273 if (predicate
&& *predicate
!= true)
276 es
->predicate
= edge_predicate_pool
.allocate ();
277 *es
->predicate
= *predicate
;
282 edge_predicate_pool
.remove (es
->predicate
);
283 es
->predicate
= NULL
;
287 /* Set predicate for hint *P. */
290 set_hint_predicate (predicate
**p
, predicate new_predicate
)
292 if (new_predicate
== false || new_predicate
== true)
295 edge_predicate_pool
.remove (*p
);
301 *p
= edge_predicate_pool
.allocate ();
307 /* Compute what conditions may or may not hold given invormation about
308 parameters. RET_CLAUSE returns truths that may hold in a specialized copy,
309 whie RET_NONSPEC_CLAUSE returns truths that may hold in an nonspecialized
310 copy when called in a given context. It is a bitmask of conditions. Bit
311 0 means that condition is known to be false, while bit 1 means that condition
312 may or may not be true. These differs - for example NOT_INLINED condition
313 is always false in the second and also builtin_constant_p tests cannot use
314 the fact that parameter is indeed a constant.
316 KNOWN_VALS is partial mapping of parameters of NODE to constant values.
317 KNOWN_AGGS is a vector of aggreggate known offset/value set for each
318 parameter. Return clause of possible truths. When INLINE_P is true, assume
319 that we are inlining.
321 ERROR_MARK means compile time invariant. */
324 evaluate_conditions_for_known_args (struct cgraph_node
*node
,
326 vec
<tree
> known_vals
,
327 vec
<value_range
> known_value_ranges
,
328 vec
<ipa_agg_value_set
> known_aggs
,
329 clause_t
*ret_clause
,
330 clause_t
*ret_nonspec_clause
)
332 clause_t clause
= inline_p
? 0 : 1 << predicate::not_inlined_condition
;
333 clause_t nonspec_clause
= 1 << predicate::not_inlined_condition
;
334 class ipa_fn_summary
*info
= ipa_fn_summaries
->get (node
);
338 for (i
= 0; vec_safe_iterate (info
->conds
, i
, &c
); i
++)
343 struct expr_eval_op
*op
;
345 /* We allow call stmt to have fewer arguments than the callee function
346 (especially for K&R style programs). So bound check here (we assume
347 known_aggs vector, if non-NULL, has the same length as
349 gcc_checking_assert (!known_aggs
.exists ()
350 || (known_vals
.length () == known_aggs
.length ()));
351 if (c
->operand_num
>= (int) known_vals
.length ())
353 clause
|= 1 << (i
+ predicate::first_dynamic_condition
);
354 nonspec_clause
|= 1 << (i
+ predicate::first_dynamic_condition
);
360 struct ipa_agg_value_set
*agg
;
362 if (c
->code
== predicate::changed
364 && (known_vals
[c
->operand_num
] == error_mark_node
))
367 if (known_aggs
.exists ())
369 agg
= &known_aggs
[c
->operand_num
];
370 val
= ipa_find_agg_cst_for_param (agg
, known_vals
[c
->operand_num
],
371 c
->offset
, c
->by_ref
);
378 val
= known_vals
[c
->operand_num
];
379 if (val
== error_mark_node
&& c
->code
!= predicate::changed
)
384 && (c
->code
== predicate::changed
385 || c
->code
== predicate::is_not_constant
))
387 clause
|= 1 << (i
+ predicate::first_dynamic_condition
);
388 nonspec_clause
|= 1 << (i
+ predicate::first_dynamic_condition
);
391 if (c
->code
== predicate::changed
)
393 nonspec_clause
|= 1 << (i
+ predicate::first_dynamic_condition
);
397 if (c
->code
== predicate::is_not_constant
)
399 nonspec_clause
|= 1 << (i
+ predicate::first_dynamic_condition
);
403 if (val
&& TYPE_SIZE (c
->type
) == TYPE_SIZE (TREE_TYPE (val
)))
405 if (c
->type
!= TREE_TYPE (val
))
406 val
= fold_unary (VIEW_CONVERT_EXPR
, c
->type
, val
);
407 for (j
= 0; vec_safe_iterate (c
->param_ops
, j
, &op
); j
++)
412 val
= fold_unary (op
->code
, op
->type
, val
);
413 else if (!op
->val
[1])
414 val
= fold_binary (op
->code
, op
->type
,
415 op
->index
? op
->val
[0] : val
,
416 op
->index
? val
: op
->val
[0]);
417 else if (op
->index
== 0)
418 val
= fold_ternary (op
->code
, op
->type
,
419 val
, op
->val
[0], op
->val
[1]);
420 else if (op
->index
== 1)
421 val
= fold_ternary (op
->code
, op
->type
,
422 op
->val
[0], val
, op
->val
[1]);
423 else if (op
->index
== 2)
424 val
= fold_ternary (op
->code
, op
->type
,
425 op
->val
[0], op
->val
[1], val
);
431 ? fold_binary_to_constant (c
->code
, boolean_type_node
, val
, c
->val
)
434 if (res
&& integer_zerop (res
))
436 if (res
&& integer_onep (res
))
438 clause
|= 1 << (i
+ predicate::first_dynamic_condition
);
439 nonspec_clause
|= 1 << (i
+ predicate::first_dynamic_condition
);
443 if (c
->operand_num
< (int) known_value_ranges
.length ()
445 && !known_value_ranges
[c
->operand_num
].undefined_p ()
446 && !known_value_ranges
[c
->operand_num
].varying_p ()
447 && TYPE_SIZE (c
->type
)
448 == TYPE_SIZE (known_value_ranges
[c
->operand_num
].type ())
449 && (!val
|| TREE_CODE (val
) != INTEGER_CST
))
451 value_range vr
= known_value_ranges
[c
->operand_num
];
452 if (!useless_type_conversion_p (c
->type
, vr
.type ()))
455 range_fold_unary_expr (&res
, NOP_EXPR
,
456 c
->type
, &vr
, vr
.type ());
461 for (j
= 0; vec_safe_iterate (c
->param_ops
, j
, &op
); j
++)
463 if (vr
.varying_p () || vr
.undefined_p ())
468 range_fold_unary_expr (&res
, op
->code
, op
->type
, &vr
, type
);
469 else if (!op
->val
[1])
471 value_range
op0 (op
->val
[0], op
->val
[0]);
472 range_fold_binary_expr (&res
, op
->code
, op
->type
,
473 op
->index
? &op0
: &vr
,
474 op
->index
? &vr
: &op0
);
481 if (!vr
.varying_p () && !vr
.undefined_p ())
484 value_range
val_vr (c
->val
, c
->val
);
485 range_fold_binary_expr (&res
, c
->code
, boolean_type_node
,
493 clause
|= 1 << (i
+ predicate::first_dynamic_condition
);
494 nonspec_clause
|= 1 << (i
+ predicate::first_dynamic_condition
);
496 *ret_clause
= clause
;
497 if (ret_nonspec_clause
)
498 *ret_nonspec_clause
= nonspec_clause
;
502 /* Work out what conditions might be true at invocation of E. */
505 evaluate_properties_for_edge (struct cgraph_edge
*e
, bool inline_p
,
506 clause_t
*clause_ptr
,
507 clause_t
*nonspec_clause_ptr
,
508 vec
<tree
> *known_vals_ptr
,
509 vec
<ipa_polymorphic_call_context
>
511 vec
<ipa_agg_value_set
> *known_aggs_ptr
)
513 struct cgraph_node
*callee
= e
->callee
->ultimate_alias_target ();
514 class ipa_fn_summary
*info
= ipa_fn_summaries
->get (callee
);
515 vec
<tree
> known_vals
= vNULL
;
516 auto_vec
<value_range
, 32> known_value_ranges
;
517 vec
<ipa_agg_value_set
> known_aggs
= vNULL
;
518 class ipa_edge_args
*args
;
521 *clause_ptr
= inline_p
? 0 : 1 << predicate::not_inlined_condition
;
523 known_vals_ptr
->create (0);
524 if (known_contexts_ptr
)
525 known_contexts_ptr
->create (0);
527 if (ipa_node_params_sum
528 && !e
->call_stmt_cannot_inline_p
529 && ((clause_ptr
&& info
->conds
) || known_vals_ptr
|| known_contexts_ptr
)
530 && (args
= IPA_EDGE_REF (e
)) != NULL
)
532 struct cgraph_node
*caller
;
533 class ipa_node_params
*caller_parms_info
, *callee_pi
;
534 class ipa_call_summary
*es
= ipa_call_summaries
->get (e
);
535 int i
, count
= ipa_get_cs_argument_count (args
);
537 if (e
->caller
->inlined_to
)
538 caller
= e
->caller
->inlined_to
;
541 caller_parms_info
= IPA_NODE_REF (caller
);
542 callee_pi
= IPA_NODE_REF (callee
);
544 if (count
&& (info
->conds
|| known_vals_ptr
))
545 known_vals
.safe_grow_cleared (count
);
546 if (count
&& info
->conds
)
547 known_value_ranges
.safe_grow_cleared (count
);
548 if (count
&& (info
->conds
|| known_aggs_ptr
))
549 known_aggs
.safe_grow_cleared (count
);
550 if (count
&& known_contexts_ptr
)
551 known_contexts_ptr
->safe_grow_cleared (count
);
554 for (i
= 0; i
< count
; i
++)
556 struct ipa_jump_func
*jf
= ipa_get_ith_jump_func (args
, i
);
557 tree cst
= ipa_value_from_jfunc (caller_parms_info
, jf
,
558 ipa_get_type (callee_pi
, i
));
560 if (!cst
&& e
->call_stmt
561 && i
< (int)gimple_call_num_args (e
->call_stmt
))
563 cst
= gimple_call_arg (e
->call_stmt
, i
);
564 if (!is_gimple_min_invariant (cst
))
569 gcc_checking_assert (TREE_CODE (cst
) != TREE_BINFO
);
570 if (known_vals
.exists ())
573 else if (inline_p
&& !es
->param
[i
].change_prob
)
574 known_vals
[i
] = error_mark_node
;
576 if (known_contexts_ptr
)
577 (*known_contexts_ptr
)[i
]
578 = ipa_context_from_jfunc (caller_parms_info
, e
, i
, jf
);
580 known_aggs
[i
] = ipa_agg_value_set_from_jfunc (caller_parms_info
,
583 known_value_ranges
[i
]
584 = ipa_value_range_from_jfunc (caller_parms_info
, e
, jf
,
585 ipa_get_type (callee_pi
, i
));
588 gcc_assert (callee
->thunk
.thunk_p
);
590 else if (e
->call_stmt
&& !e
->call_stmt_cannot_inline_p
591 && ((clause_ptr
&& info
->conds
) || known_vals_ptr
))
593 int i
, count
= (int)gimple_call_num_args (e
->call_stmt
);
595 if (count
&& (info
->conds
|| known_vals_ptr
))
596 known_vals
.safe_grow_cleared (count
);
597 for (i
= 0; i
< count
; i
++)
599 tree cst
= gimple_call_arg (e
->call_stmt
, i
);
600 if (!is_gimple_min_invariant (cst
))
607 evaluate_conditions_for_known_args (callee
, inline_p
,
610 known_aggs
, clause_ptr
,
614 *known_vals_ptr
= known_vals
;
616 known_vals
.release ();
619 *known_aggs_ptr
= known_aggs
;
621 ipa_release_agg_values (known_aggs
);
625 /* Allocate the function summary. */
628 ipa_fn_summary_alloc (void)
630 gcc_checking_assert (!ipa_fn_summaries
);
631 ipa_size_summaries
= new fast_function_summary
<ipa_size_summary
*, va_heap
>
633 ipa_fn_summaries
= ipa_fn_summary_t::create_ggc (symtab
);
634 ipa_call_summaries
= new ipa_call_summary_t (symtab
);
637 ipa_call_summary::~ipa_call_summary ()
640 edge_predicate_pool
.remove (predicate
);
645 ipa_fn_summary::~ipa_fn_summary ()
648 edge_predicate_pool
.remove (loop_iterations
);
650 edge_predicate_pool
.remove (loop_stride
);
652 vec_free (size_time_table
);
653 vec_free (call_size_time_table
);
657 ipa_fn_summary_t::remove_callees (cgraph_node
*node
)
660 for (e
= node
->callees
; e
; e
= e
->next_callee
)
661 ipa_call_summaries
->remove (e
);
662 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
663 ipa_call_summaries
->remove (e
);
666 /* Same as remap_predicate_after_duplication but handle hint predicate *P.
667 Additionally care about allocating new memory slot for updated predicate
668 and set it to NULL when it becomes true or false (and thus uninteresting).
672 remap_hint_predicate_after_duplication (predicate
**p
,
673 clause_t possible_truths
)
675 predicate new_predicate
;
680 new_predicate
= (*p
)->remap_after_duplication (possible_truths
);
681 /* We do not want to free previous predicate; it is used by node origin. */
683 set_hint_predicate (p
, new_predicate
);
687 /* Hook that is called by cgraph.c when a node is duplicated. */
689 ipa_fn_summary_t::duplicate (cgraph_node
*src
,
692 ipa_fn_summary
*info
)
694 new (info
) ipa_fn_summary (*ipa_fn_summaries
->get (src
));
695 /* TODO: as an optimization, we may avoid copying conditions
696 that are known to be false or true. */
697 info
->conds
= vec_safe_copy (info
->conds
);
699 /* When there are any replacements in the function body, see if we can figure
700 out that something was optimized out. */
701 if (ipa_node_params_sum
&& dst
->clone
.tree_map
)
703 vec
<size_time_entry
, va_gc
> *entry
= info
->size_time_table
;
704 /* Use SRC parm info since it may not be copied yet. */
705 class ipa_node_params
*parms_info
= IPA_NODE_REF (src
);
706 vec
<tree
> known_vals
= vNULL
;
707 int count
= ipa_get_param_count (parms_info
);
709 clause_t possible_truths
;
710 predicate true_pred
= true;
712 int optimized_out_size
= 0;
713 bool inlined_to_p
= false;
714 struct cgraph_edge
*edge
, *next
;
716 info
->size_time_table
= 0;
717 known_vals
.safe_grow_cleared (count
);
718 for (i
= 0; i
< count
; i
++)
720 struct ipa_replace_map
*r
;
722 for (j
= 0; vec_safe_iterate (dst
->clone
.tree_map
, j
, &r
); j
++)
724 if (r
->parm_num
== i
)
726 known_vals
[i
] = r
->new_tree
;
731 evaluate_conditions_for_known_args (dst
, false,
736 /* We are going to specialize,
737 so ignore nonspec truths. */
739 known_vals
.release ();
741 info
->account_size_time (0, 0, true_pred
, true_pred
);
743 /* Remap size_time vectors.
744 Simplify the predicate by prunning out alternatives that are known
746 TODO: as on optimization, we can also eliminate conditions known
748 for (i
= 0; vec_safe_iterate (entry
, i
, &e
); i
++)
750 predicate new_exec_pred
;
751 predicate new_nonconst_pred
;
752 new_exec_pred
= e
->exec_predicate
.remap_after_duplication
754 new_nonconst_pred
= e
->nonconst_predicate
.remap_after_duplication
756 if (new_exec_pred
== false || new_nonconst_pred
== false)
757 optimized_out_size
+= e
->size
;
759 info
->account_size_time (e
->size
, e
->time
, new_exec_pred
,
763 /* Remap edge predicates with the same simplification as above.
764 Also copy constantness arrays. */
765 for (edge
= dst
->callees
; edge
; edge
= next
)
767 predicate new_predicate
;
768 class ipa_call_summary
*es
= ipa_call_summaries
->get (edge
);
769 next
= edge
->next_callee
;
771 if (!edge
->inline_failed
)
775 new_predicate
= es
->predicate
->remap_after_duplication
777 if (new_predicate
== false && *es
->predicate
!= false)
778 optimized_out_size
+= es
->call_stmt_size
* ipa_fn_summary::size_scale
;
779 edge_set_predicate (edge
, &new_predicate
);
782 /* Remap indirect edge predicates with the same simplificaiton as above.
783 Also copy constantness arrays. */
784 for (edge
= dst
->indirect_calls
; edge
; edge
= next
)
786 predicate new_predicate
;
787 class ipa_call_summary
*es
= ipa_call_summaries
->get (edge
);
788 next
= edge
->next_callee
;
790 gcc_checking_assert (edge
->inline_failed
);
793 new_predicate
= es
->predicate
->remap_after_duplication
795 if (new_predicate
== false && *es
->predicate
!= false)
796 optimized_out_size
+= es
->call_stmt_size
* ipa_fn_summary::size_scale
;
797 edge_set_predicate (edge
, &new_predicate
);
799 remap_hint_predicate_after_duplication (&info
->loop_iterations
,
801 remap_hint_predicate_after_duplication (&info
->loop_stride
,
804 /* If inliner or someone after inliner will ever start producing
805 non-trivial clones, we will get trouble with lack of information
806 about updating self sizes, because size vectors already contains
807 sizes of the calees. */
808 gcc_assert (!inlined_to_p
|| !optimized_out_size
);
812 info
->size_time_table
= vec_safe_copy (info
->size_time_table
);
813 if (info
->loop_iterations
)
815 predicate p
= *info
->loop_iterations
;
816 info
->loop_iterations
= NULL
;
817 set_hint_predicate (&info
->loop_iterations
, p
);
819 if (info
->loop_stride
)
821 predicate p
= *info
->loop_stride
;
822 info
->loop_stride
= NULL
;
823 set_hint_predicate (&info
->loop_stride
, p
);
826 if (!dst
->inlined_to
)
827 ipa_update_overall_fn_summary (dst
);
831 /* Hook that is called by cgraph.c when a node is duplicated. */
834 ipa_call_summary_t::duplicate (struct cgraph_edge
*src
,
835 struct cgraph_edge
*dst
,
836 class ipa_call_summary
*srcinfo
,
837 class ipa_call_summary
*info
)
839 new (info
) ipa_call_summary (*srcinfo
);
840 info
->predicate
= NULL
;
841 edge_set_predicate (dst
, srcinfo
->predicate
);
842 info
->param
= srcinfo
->param
.copy ();
843 if (!dst
->indirect_unknown_callee
&& src
->indirect_unknown_callee
)
845 info
->call_stmt_size
-= (eni_size_weights
.indirect_call_cost
846 - eni_size_weights
.call_cost
);
847 info
->call_stmt_time
-= (eni_time_weights
.indirect_call_cost
848 - eni_time_weights
.call_cost
);
852 /* Dump edge summaries associated to NODE and recursively to all clones.
856 dump_ipa_call_summary (FILE *f
, int indent
, struct cgraph_node
*node
,
857 class ipa_fn_summary
*info
)
859 struct cgraph_edge
*edge
;
860 for (edge
= node
->callees
; edge
; edge
= edge
->next_callee
)
862 class ipa_call_summary
*es
= ipa_call_summaries
->get (edge
);
863 struct cgraph_node
*callee
= edge
->callee
->ultimate_alias_target ();
867 "%*s%s/%i %s\n%*s freq:%4.2f",
868 indent
, "", callee
->name (), callee
->order
,
870 ? "inlined" : cgraph_inline_failed_string (edge
-> inline_failed
),
871 indent
, "", edge
->sreal_frequency ().to_double ());
874 fprintf (f
, " loop depth:%2i size:%2i time: %2i",
875 es
->loop_depth
, es
->call_stmt_size
, es
->call_stmt_time
);
877 ipa_fn_summary
*s
= ipa_fn_summaries
->get (callee
);
878 ipa_size_summary
*ss
= ipa_size_summaries
->get (callee
);
880 fprintf (f
, " callee size:%2i stack:%2i",
881 (int) (ss
->size
/ ipa_fn_summary::size_scale
),
882 (int) s
->estimated_stack_size
);
884 if (es
&& es
->predicate
)
886 fprintf (f
, " predicate: ");
887 es
->predicate
->dump (f
, info
->conds
);
891 if (es
&& es
->param
.exists ())
892 for (i
= 0; i
< (int) es
->param
.length (); i
++)
894 int prob
= es
->param
[i
].change_prob
;
897 fprintf (f
, "%*s op%i is compile time invariant\n",
899 else if (prob
!= REG_BR_PROB_BASE
)
900 fprintf (f
, "%*s op%i change %f%% of time\n", indent
+ 2, "", i
,
901 prob
* 100.0 / REG_BR_PROB_BASE
);
903 if (!edge
->inline_failed
)
905 ipa_size_summary
*ss
= ipa_size_summaries
->get (callee
);
906 fprintf (f
, "%*sStack frame offset %i, callee self size %i\n",
908 (int) ipa_get_stack_frame_offset (callee
),
909 (int) ss
->estimated_self_stack_size
);
910 dump_ipa_call_summary (f
, indent
+ 2, callee
, info
);
913 for (edge
= node
->indirect_calls
; edge
; edge
= edge
->next_callee
)
915 class ipa_call_summary
*es
= ipa_call_summaries
->get (edge
);
916 fprintf (f
, "%*sindirect call loop depth:%2i freq:%4.2f size:%2i"
920 edge
->sreal_frequency ().to_double (), es
->call_stmt_size
,
924 fprintf (f
, "predicate: ");
925 es
->predicate
->dump (f
, info
->conds
);
934 ipa_dump_fn_summary (FILE *f
, struct cgraph_node
*node
)
936 if (node
->definition
)
938 class ipa_fn_summary
*s
= ipa_fn_summaries
->get (node
);
939 class ipa_size_summary
*ss
= ipa_size_summaries
->get (node
);
944 fprintf (f
, "IPA function summary for %s", node
->dump_name ());
945 if (DECL_DISREGARD_INLINE_LIMITS (node
->decl
))
946 fprintf (f
, " always_inline");
948 fprintf (f
, " inlinable");
949 if (s
->fp_expressions
)
950 fprintf (f
, " fp_expression");
951 fprintf (f
, "\n global time: %f\n", s
->time
.to_double ());
952 fprintf (f
, " self size: %i\n", ss
->self_size
);
953 fprintf (f
, " global size: %i\n", ss
->size
);
954 fprintf (f
, " min size: %i\n", s
->min_size
);
955 fprintf (f
, " self stack: %i\n",
956 (int) ss
->estimated_self_stack_size
);
957 fprintf (f
, " global stack: %i\n", (int) s
->estimated_stack_size
);
959 fprintf (f
, " estimated growth:%i\n", (int) s
->growth
);
961 fprintf (f
, " In SCC: %i\n", (int) s
->scc_no
);
962 for (i
= 0; vec_safe_iterate (s
->size_time_table
, i
, &e
); i
++)
964 fprintf (f
, " size:%f, time:%f",
965 (double) e
->size
/ ipa_fn_summary::size_scale
,
966 e
->time
.to_double ());
967 if (e
->exec_predicate
!= true)
969 fprintf (f
, ", executed if:");
970 e
->exec_predicate
.dump (f
, s
->conds
, 0);
972 if (e
->exec_predicate
!= e
->nonconst_predicate
)
974 fprintf (f
, ", nonconst if:");
975 e
->nonconst_predicate
.dump (f
, s
->conds
, 0);
979 if (s
->loop_iterations
)
981 fprintf (f
, " loop iterations:");
982 s
->loop_iterations
->dump (f
, s
->conds
);
986 fprintf (f
, " loop stride:");
987 s
->loop_stride
->dump (f
, s
->conds
);
989 fprintf (f
, " calls:\n");
990 dump_ipa_call_summary (f
, 4, node
, s
);
994 fprintf (f
, "IPA summary for %s is missing.\n", node
->dump_name ());
999 ipa_debug_fn_summary (struct cgraph_node
*node
)
1001 ipa_dump_fn_summary (stderr
, node
);
1005 ipa_dump_fn_summaries (FILE *f
)
1007 struct cgraph_node
*node
;
1009 FOR_EACH_DEFINED_FUNCTION (node
)
1010 if (!node
->inlined_to
)
1011 ipa_dump_fn_summary (f
, node
);
1014 /* Callback of walk_aliased_vdefs. Flags that it has been invoked to the
1015 boolean variable pointed to by DATA. */
1018 mark_modified (ao_ref
*ao ATTRIBUTE_UNUSED
, tree vdef ATTRIBUTE_UNUSED
,
1021 bool *b
= (bool *) data
;
1026 /* If OP refers to value of function parameter, return the corresponding
1027 parameter. If non-NULL, the size of the memory load (or the SSA_NAME of the
1028 PARM_DECL) will be stored to *SIZE_P in that case too. */
1031 unmodified_parm_1 (ipa_func_body_info
*fbi
, gimple
*stmt
, tree op
,
1034 /* SSA_NAME referring to parm default def? */
1035 if (TREE_CODE (op
) == SSA_NAME
1036 && SSA_NAME_IS_DEFAULT_DEF (op
)
1037 && TREE_CODE (SSA_NAME_VAR (op
)) == PARM_DECL
)
1040 *size_p
= tree_to_poly_int64 (TYPE_SIZE (TREE_TYPE (op
)));
1041 return SSA_NAME_VAR (op
);
1043 /* Non-SSA parm reference? */
1044 if (TREE_CODE (op
) == PARM_DECL
)
1046 bool modified
= false;
1049 ao_ref_init (&refd
, op
);
1050 int walked
= walk_aliased_vdefs (&refd
, gimple_vuse (stmt
),
1051 mark_modified
, &modified
, NULL
, NULL
,
1052 fbi
->aa_walk_budget
+ 1);
1055 fbi
->aa_walk_budget
= 0;
1061 *size_p
= tree_to_poly_int64 (TYPE_SIZE (TREE_TYPE (op
)));
1068 /* If OP refers to value of function parameter, return the corresponding
1069 parameter. Also traverse chains of SSA register assignments. If non-NULL,
1070 the size of the memory load (or the SSA_NAME of the PARM_DECL) will be
1071 stored to *SIZE_P in that case too. */
1074 unmodified_parm (ipa_func_body_info
*fbi
, gimple
*stmt
, tree op
,
1077 tree res
= unmodified_parm_1 (fbi
, stmt
, op
, size_p
);
1081 if (TREE_CODE (op
) == SSA_NAME
1082 && !SSA_NAME_IS_DEFAULT_DEF (op
)
1083 && gimple_assign_single_p (SSA_NAME_DEF_STMT (op
)))
1084 return unmodified_parm (fbi
, SSA_NAME_DEF_STMT (op
),
1085 gimple_assign_rhs1 (SSA_NAME_DEF_STMT (op
)),
1090 /* If OP refers to a value of a function parameter or value loaded from an
1091 aggregate passed to a parameter (either by value or reference), return TRUE
1092 and store the number of the parameter to *INDEX_P, the access size into
1093 *SIZE_P, and information whether and how it has been loaded from an
1094 aggregate into *AGGPOS. INFO describes the function parameters, STMT is the
1095 statement in which OP is used or loaded. */
1098 unmodified_parm_or_parm_agg_item (struct ipa_func_body_info
*fbi
,
1099 gimple
*stmt
, tree op
, int *index_p
,
1101 struct agg_position_info
*aggpos
)
1103 tree res
= unmodified_parm_1 (fbi
, stmt
, op
, size_p
);
1105 gcc_checking_assert (aggpos
);
1108 *index_p
= ipa_get_param_decl_index (fbi
->info
, res
);
1111 aggpos
->agg_contents
= false;
1112 aggpos
->by_ref
= false;
1116 if (TREE_CODE (op
) == SSA_NAME
)
1118 if (SSA_NAME_IS_DEFAULT_DEF (op
)
1119 || !gimple_assign_single_p (SSA_NAME_DEF_STMT (op
)))
1121 stmt
= SSA_NAME_DEF_STMT (op
);
1122 op
= gimple_assign_rhs1 (stmt
);
1123 if (!REFERENCE_CLASS_P (op
))
1124 return unmodified_parm_or_parm_agg_item (fbi
, stmt
, op
, index_p
, size_p
,
1128 aggpos
->agg_contents
= true;
1129 return ipa_load_from_parm_agg (fbi
, fbi
->info
->descriptors
,
1130 stmt
, op
, index_p
, &aggpos
->offset
,
1131 size_p
, &aggpos
->by_ref
);
1134 /* See if statement might disappear after inlining.
1135 0 - means not eliminated
1136 1 - half of statements goes away
1137 2 - for sure it is eliminated.
1138 We are not terribly sophisticated, basically looking for simple abstraction
1139 penalty wrappers. */
1142 eliminated_by_inlining_prob (ipa_func_body_info
*fbi
, gimple
*stmt
)
1144 enum gimple_code code
= gimple_code (stmt
);
1145 enum tree_code rhs_code
;
1155 if (gimple_num_ops (stmt
) != 2)
1158 rhs_code
= gimple_assign_rhs_code (stmt
);
1160 /* Casts of parameters, loads from parameters passed by reference
1161 and stores to return value or parameters are often free after
1162 inlining dua to SRA and further combining.
1163 Assume that half of statements goes away. */
1164 if (CONVERT_EXPR_CODE_P (rhs_code
)
1165 || rhs_code
== VIEW_CONVERT_EXPR
1166 || rhs_code
== ADDR_EXPR
1167 || gimple_assign_rhs_class (stmt
) == GIMPLE_SINGLE_RHS
)
1169 tree rhs
= gimple_assign_rhs1 (stmt
);
1170 tree lhs
= gimple_assign_lhs (stmt
);
1171 tree inner_rhs
= get_base_address (rhs
);
1172 tree inner_lhs
= get_base_address (lhs
);
1173 bool rhs_free
= false;
1174 bool lhs_free
= false;
1181 /* Reads of parameter are expected to be free. */
1182 if (unmodified_parm (fbi
, stmt
, inner_rhs
, NULL
))
1184 /* Match expressions of form &this->field. Those will most likely
1185 combine with something upstream after inlining. */
1186 else if (TREE_CODE (inner_rhs
) == ADDR_EXPR
)
1188 tree op
= get_base_address (TREE_OPERAND (inner_rhs
, 0));
1189 if (TREE_CODE (op
) == PARM_DECL
)
1191 else if (TREE_CODE (op
) == MEM_REF
1192 && unmodified_parm (fbi
, stmt
, TREE_OPERAND (op
, 0),
1197 /* When parameter is not SSA register because its address is taken
1198 and it is just copied into one, the statement will be completely
1199 free after inlining (we will copy propagate backward). */
1200 if (rhs_free
&& is_gimple_reg (lhs
))
1203 /* Reads of parameters passed by reference
1204 expected to be free (i.e. optimized out after inlining). */
1205 if (TREE_CODE (inner_rhs
) == MEM_REF
1206 && unmodified_parm (fbi
, stmt
, TREE_OPERAND (inner_rhs
, 0), NULL
))
1209 /* Copying parameter passed by reference into gimple register is
1210 probably also going to copy propagate, but we can't be quite
1212 if (rhs_free
&& is_gimple_reg (lhs
))
1215 /* Writes to parameters, parameters passed by value and return value
1216 (either dirrectly or passed via invisible reference) are free.
1218 TODO: We ought to handle testcase like
1219 struct a {int a,b;};
1221 retrurnsturct (void)
1227 This translate into:
1242 For that we either need to copy ipa-split logic detecting writes
1244 if (TREE_CODE (inner_lhs
) == PARM_DECL
1245 || TREE_CODE (inner_lhs
) == RESULT_DECL
1246 || (TREE_CODE (inner_lhs
) == MEM_REF
1247 && (unmodified_parm (fbi
, stmt
, TREE_OPERAND (inner_lhs
, 0),
1249 || (TREE_CODE (TREE_OPERAND (inner_lhs
, 0)) == SSA_NAME
1250 && SSA_NAME_VAR (TREE_OPERAND (inner_lhs
, 0))
1251 && TREE_CODE (SSA_NAME_VAR (TREE_OPERAND
1253 0))) == RESULT_DECL
))))
1256 && (is_gimple_reg (rhs
) || is_gimple_min_invariant (rhs
)))
1258 if (lhs_free
&& rhs_free
)
1267 /* Analyze EXPR if it represents a series of simple operations performed on
1268 a function parameter and return true if so. FBI, STMT, EXPR, INDEX_P and
1269 AGGPOS have the same meaning like in unmodified_parm_or_parm_agg_item.
1270 Type of the parameter or load from an aggregate via the parameter is
1271 stored in *TYPE_P. Operations on the parameter are recorded to
1272 PARAM_OPS_P if it is not NULL. */
1275 decompose_param_expr (struct ipa_func_body_info
*fbi
,
1276 gimple
*stmt
, tree expr
,
1277 int *index_p
, tree
*type_p
,
1278 struct agg_position_info
*aggpos
,
1279 expr_eval_ops
*param_ops_p
= NULL
)
1281 int op_limit
= param_ipa_max_param_expr_ops
;
1285 *param_ops_p
= NULL
;
1289 expr_eval_op eval_op
;
1291 unsigned cst_count
= 0;
1293 if (unmodified_parm_or_parm_agg_item (fbi
, stmt
, expr
, index_p
, NULL
,
1296 tree type
= TREE_TYPE (expr
);
1298 if (aggpos
->agg_contents
)
1300 /* Stop if containing bit-field. */
1301 if (TREE_CODE (expr
) == BIT_FIELD_REF
1302 || contains_bitfld_component_ref_p (expr
))
1310 if (TREE_CODE (expr
) != SSA_NAME
|| SSA_NAME_IS_DEFAULT_DEF (expr
))
1313 if (!is_gimple_assign (stmt
= SSA_NAME_DEF_STMT (expr
)))
1316 switch (gimple_assign_rhs_class (stmt
))
1318 case GIMPLE_SINGLE_RHS
:
1319 expr
= gimple_assign_rhs1 (stmt
);
1322 case GIMPLE_UNARY_RHS
:
1326 case GIMPLE_BINARY_RHS
:
1330 case GIMPLE_TERNARY_RHS
:
1338 /* Stop if expression is too complex. */
1339 if (op_count
++ == op_limit
)
1344 eval_op
.code
= gimple_assign_rhs_code (stmt
);
1345 eval_op
.type
= TREE_TYPE (gimple_assign_lhs (stmt
));
1346 eval_op
.val
[0] = NULL_TREE
;
1347 eval_op
.val
[1] = NULL_TREE
;
1351 for (unsigned i
= 0; i
< rhs_count
; i
++)
1353 tree op
= gimple_op (stmt
, i
+ 1);
1355 gcc_assert (op
&& !TYPE_P (op
));
1356 if (is_gimple_ip_invariant (op
))
1358 if (++cst_count
== rhs_count
)
1361 eval_op
.val
[cst_count
- 1] = op
;
1365 /* Found a non-constant operand, and record its index in rhs
1372 /* Found more than one non-constant operands. */
1378 vec_safe_insert (*param_ops_p
, 0, eval_op
);
1381 /* Failed to decompose, free resource and return. */
1384 vec_free (*param_ops_p
);
1389 /* If BB ends by a conditional we can turn into predicates, attach corresponding
1390 predicates to the CFG edges. */
1393 set_cond_stmt_execution_predicate (struct ipa_func_body_info
*fbi
,
1394 class ipa_fn_summary
*summary
,
1395 class ipa_node_params
*params_summary
,
1401 struct agg_position_info aggpos
;
1402 enum tree_code code
, inverted_code
;
1407 expr_eval_ops param_ops
;
1409 last
= last_stmt (bb
);
1410 if (!last
|| gimple_code (last
) != GIMPLE_COND
)
1412 if (!is_gimple_ip_invariant (gimple_cond_rhs (last
)))
1414 op
= gimple_cond_lhs (last
);
1416 if (decompose_param_expr (fbi
, last
, op
, &index
, ¶m_type
, &aggpos
,
1419 code
= gimple_cond_code (last
);
1420 inverted_code
= invert_tree_comparison (code
, HONOR_NANS (op
));
1422 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
1424 enum tree_code this_code
= (e
->flags
& EDGE_TRUE_VALUE
1425 ? code
: inverted_code
);
1426 /* invert_tree_comparison will return ERROR_MARK on FP
1427 comparsions that are not EQ/NE instead of returning proper
1428 unordered one. Be sure it is not confused with NON_CONSTANT.
1430 And if the edge's target is the final block of diamond CFG graph
1431 of this conditional statement, we do not need to compute
1432 predicate for the edge because the final block's predicate must
1433 be at least as that of the first block of the statement. */
1434 if (this_code
!= ERROR_MARK
1435 && !dominated_by_p (CDI_POST_DOMINATORS
, bb
, e
->dest
))
1438 = add_condition (summary
, params_summary
, index
,
1439 param_type
, &aggpos
,
1440 this_code
, gimple_cond_rhs (last
), param_ops
);
1441 e
->aux
= edge_predicate_pool
.allocate ();
1442 *(predicate
*) e
->aux
= p
;
1445 vec_free (param_ops
);
1448 if (TREE_CODE (op
) != SSA_NAME
)
1451 if (builtin_constant_p (op))
1455 Here we can predicate nonconstant_code. We can't
1456 really handle constant_code since we have no predicate
1457 for this and also the constant code is not known to be
1458 optimized away when inliner doen't see operand is constant.
1459 Other optimizers might think otherwise. */
1460 if (gimple_cond_code (last
) != NE_EXPR
1461 || !integer_zerop (gimple_cond_rhs (last
)))
1463 set_stmt
= SSA_NAME_DEF_STMT (op
);
1464 if (!gimple_call_builtin_p (set_stmt
, BUILT_IN_CONSTANT_P
)
1465 || gimple_call_num_args (set_stmt
) != 1)
1467 op2
= gimple_call_arg (set_stmt
, 0);
1468 if (!decompose_param_expr (fbi
, set_stmt
, op2
, &index
, ¶m_type
, &aggpos
))
1470 FOR_EACH_EDGE (e
, ei
, bb
->succs
) if (e
->flags
& EDGE_FALSE_VALUE
)
1472 predicate p
= add_condition (summary
, params_summary
, index
,
1473 param_type
, &aggpos
,
1474 predicate::is_not_constant
, NULL_TREE
);
1475 e
->aux
= edge_predicate_pool
.allocate ();
1476 *(predicate
*) e
->aux
= p
;
1481 /* If BB ends by a switch we can turn into predicates, attach corresponding
1482 predicates to the CFG edges. */
1485 set_switch_stmt_execution_predicate (struct ipa_func_body_info
*fbi
,
1486 class ipa_fn_summary
*summary
,
1487 class ipa_node_params
*params_summary
,
1493 struct agg_position_info aggpos
;
1499 expr_eval_ops param_ops
;
1501 lastg
= last_stmt (bb
);
1502 if (!lastg
|| gimple_code (lastg
) != GIMPLE_SWITCH
)
1504 gswitch
*last
= as_a
<gswitch
*> (lastg
);
1505 op
= gimple_switch_index (last
);
1506 if (!decompose_param_expr (fbi
, last
, op
, &index
, ¶m_type
, &aggpos
,
1510 auto_vec
<std::pair
<tree
, tree
> > ranges
;
1511 tree type
= TREE_TYPE (op
);
1512 int bound_limit
= param_ipa_max_switch_predicate_bounds
;
1513 int bound_count
= 0;
1514 wide_int vr_wmin
, vr_wmax
;
1515 value_range_kind vr_type
= get_range_info (op
, &vr_wmin
, &vr_wmax
);
1517 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
1519 e
->aux
= edge_predicate_pool
.allocate ();
1520 *(predicate
*) e
->aux
= false;
1523 e
= gimple_switch_edge (cfun
, last
, 0);
1524 /* Set BOUND_COUNT to maximum count to bypass computing predicate for
1525 default case if its target basic block is in convergence point of all
1526 switch cases, which can be determined by checking whether it
1527 post-dominates the switch statement. */
1528 if (dominated_by_p (CDI_POST_DOMINATORS
, bb
, e
->dest
))
1529 bound_count
= INT_MAX
;
1531 n
= gimple_switch_num_labels (last
);
1532 for (case_idx
= 1; case_idx
< n
; ++case_idx
)
1534 tree cl
= gimple_switch_label (last
, case_idx
);
1535 tree min
= CASE_LOW (cl
);
1536 tree max
= CASE_HIGH (cl
);
1539 e
= gimple_switch_edge (cfun
, last
, case_idx
);
1541 /* The case value might not have same type as switch expression,
1542 extend the value based on the expression type. */
1543 if (TREE_TYPE (min
) != type
)
1544 min
= wide_int_to_tree (type
, wi::to_wide (min
));
1548 else if (TREE_TYPE (max
) != type
)
1549 max
= wide_int_to_tree (type
, wi::to_wide (max
));
1551 /* The case's target basic block is in convergence point of all switch
1552 cases, its predicate should be at least as that of the switch
1554 if (dominated_by_p (CDI_POST_DOMINATORS
, bb
, e
->dest
))
1556 else if (min
== max
)
1557 p
= add_condition (summary
, params_summary
, index
, param_type
,
1558 &aggpos
, EQ_EXPR
, min
, param_ops
);
1562 p1
= add_condition (summary
, params_summary
, index
, param_type
,
1563 &aggpos
, GE_EXPR
, min
, param_ops
);
1564 p2
= add_condition (summary
, params_summary
,index
, param_type
,
1565 &aggpos
, LE_EXPR
, max
, param_ops
);
1568 *(class predicate
*) e
->aux
1569 = p
.or_with (summary
->conds
, *(class predicate
*) e
->aux
);
1571 /* If there are too many disjoint case ranges, predicate for default
1572 case might become too complicated. So add a limit here. */
1573 if (bound_count
> bound_limit
)
1576 bool new_range
= true;
1578 if (!ranges
.is_empty ())
1580 wide_int curr_wmin
= wi::to_wide (min
);
1581 wide_int last_wmax
= wi::to_wide (ranges
.last ().second
);
1583 /* Merge case ranges if they are continuous. */
1584 if (curr_wmin
== last_wmax
+ 1)
1586 else if (vr_type
== VR_ANTI_RANGE
)
1588 /* If two disjoint case ranges can be connected by anti-range
1589 of switch index, combine them to one range. */
1590 if (wi::lt_p (vr_wmax
, curr_wmin
- 1, TYPE_SIGN (type
)))
1591 vr_type
= VR_UNDEFINED
;
1592 else if (wi::le_p (vr_wmin
, last_wmax
+ 1, TYPE_SIGN (type
)))
1597 /* Create/extend a case range. And we count endpoints of range set,
1598 this number nearly equals to number of conditions that we will create
1599 for predicate of default case. */
1602 bound_count
+= (min
== max
) ? 1 : 2;
1603 ranges
.safe_push (std::make_pair (min
, max
));
1607 bound_count
+= (ranges
.last ().first
== ranges
.last ().second
);
1608 ranges
.last ().second
= max
;
1612 e
= gimple_switch_edge (cfun
, last
, 0);
1613 if (bound_count
> bound_limit
)
1615 *(class predicate
*) e
->aux
= true;
1616 vec_free (param_ops
);
1620 predicate p_seg
= true;
1621 predicate p_all
= false;
1623 if (vr_type
!= VR_RANGE
)
1625 vr_wmin
= wi::to_wide (TYPE_MIN_VALUE (type
));
1626 vr_wmax
= wi::to_wide (TYPE_MAX_VALUE (type
));
1629 /* Construct predicate to represent default range set that is negation of
1630 all case ranges. Case range is classified as containing single/non-single
1631 values. Suppose a piece of case ranges in the following.
1633 [D1...D2] [S1] ... [Sn] [D3...D4]
1635 To represent default case's range sets between two non-single value
1636 case ranges (From D2 to D3), we construct predicate as:
1638 D2 < x < D3 && x != S1 && ... && x != Sn
1640 for (size_t i
= 0; i
< ranges
.length (); i
++)
1642 tree min
= ranges
[i
].first
;
1643 tree max
= ranges
[i
].second
;
1646 p_seg
&= add_condition (summary
, params_summary
, index
,
1647 param_type
, &aggpos
, NE_EXPR
,
1651 /* Do not create sub-predicate for range that is beyond low bound
1653 if (wi::lt_p (vr_wmin
, wi::to_wide (min
), TYPE_SIGN (type
)))
1655 p_seg
&= add_condition (summary
, params_summary
, index
,
1656 param_type
, &aggpos
,
1657 LT_EXPR
, min
, param_ops
);
1658 p_all
= p_all
.or_with (summary
->conds
, p_seg
);
1661 /* Do not create sub-predicate for range that is beyond up bound
1663 if (wi::le_p (vr_wmax
, wi::to_wide (max
), TYPE_SIGN (type
)))
1669 p_seg
= add_condition (summary
, params_summary
, index
,
1670 param_type
, &aggpos
, GT_EXPR
,
1675 p_all
= p_all
.or_with (summary
->conds
, p_seg
);
1676 *(class predicate
*) e
->aux
1677 = p_all
.or_with (summary
->conds
, *(class predicate
*) e
->aux
);
1679 vec_free (param_ops
);
1683 /* For each BB in NODE attach to its AUX pointer predicate under
1684 which it is executable. */
1687 compute_bb_predicates (struct ipa_func_body_info
*fbi
,
1688 struct cgraph_node
*node
,
1689 class ipa_fn_summary
*summary
,
1690 class ipa_node_params
*params_summary
)
1692 struct function
*my_function
= DECL_STRUCT_FUNCTION (node
->decl
);
1696 FOR_EACH_BB_FN (bb
, my_function
)
1698 set_cond_stmt_execution_predicate (fbi
, summary
, params_summary
, bb
);
1699 set_switch_stmt_execution_predicate (fbi
, summary
, params_summary
, bb
);
1702 /* Entry block is always executable. */
1703 ENTRY_BLOCK_PTR_FOR_FN (my_function
)->aux
1704 = edge_predicate_pool
.allocate ();
1705 *(predicate
*) ENTRY_BLOCK_PTR_FOR_FN (my_function
)->aux
= true;
1707 /* A simple dataflow propagation of predicates forward in the CFG.
1708 TODO: work in reverse postorder. */
1712 FOR_EACH_BB_FN (bb
, my_function
)
1714 predicate p
= false;
1717 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
1721 predicate this_bb_predicate
1722 = *(predicate
*) e
->src
->aux
;
1724 this_bb_predicate
&= (*(class predicate
*) e
->aux
);
1725 p
= p
.or_with (summary
->conds
, this_bb_predicate
);
1732 basic_block pdom_bb
;
1737 bb
->aux
= edge_predicate_pool
.allocate ();
1738 *((predicate
*) bb
->aux
) = p
;
1740 else if (p
!= *(predicate
*) bb
->aux
)
1742 /* This OR operation is needed to ensure monotonous data flow
1743 in the case we hit the limit on number of clauses and the
1744 and/or operations above give approximate answers. */
1745 p
= p
.or_with (summary
->conds
, *(predicate
*)bb
->aux
);
1746 if (p
!= *(predicate
*) bb
->aux
)
1749 *((predicate
*) bb
->aux
) = p
;
1753 /* For switch/if statement, we can OR-combine predicates of all
1754 its cases/branches to get predicate for basic block in their
1755 convergence point, but sometimes this will generate very
1756 complicated predicate. Actually, we can get simplified
1757 predicate in another way by using the fact that predicate
1758 for a basic block must also hold true for its post dominators.
1759 To be specific, basic block in convergence point of
1760 conditional statement should include predicate of the
1762 pdom_bb
= get_immediate_dominator (CDI_POST_DOMINATORS
, bb
);
1763 if (pdom_bb
== EXIT_BLOCK_PTR_FOR_FN (my_function
) || !pdom_bb
)
1765 else if (!pdom_bb
->aux
)
1768 pdom_bb
->aux
= edge_predicate_pool
.allocate ();
1769 *((predicate
*) pdom_bb
->aux
) = p
;
1771 else if (p
!= *(predicate
*) pdom_bb
->aux
)
1773 p
= p
.or_with (summary
->conds
, *(predicate
*)pdom_bb
->aux
);
1774 if (p
!= *(predicate
*) pdom_bb
->aux
)
1777 *((predicate
*) pdom_bb
->aux
) = p
;
1786 /* Return predicate specifying when the STMT might have result that is not
1787 a compile time constant. */
1790 will_be_nonconstant_expr_predicate (ipa_func_body_info
*fbi
,
1791 class ipa_fn_summary
*summary
,
1792 class ipa_node_params
*params_summary
,
1794 vec
<predicate
> nonconstant_names
)
1799 while (UNARY_CLASS_P (expr
))
1800 expr
= TREE_OPERAND (expr
, 0);
1802 parm
= unmodified_parm (fbi
, NULL
, expr
, NULL
);
1803 if (parm
&& (index
= ipa_get_param_decl_index (fbi
->info
, parm
)) >= 0)
1804 return add_condition (summary
, params_summary
, index
, TREE_TYPE (parm
), NULL
,
1805 predicate::changed
, NULL_TREE
);
1806 if (is_gimple_min_invariant (expr
))
1808 if (TREE_CODE (expr
) == SSA_NAME
)
1809 return nonconstant_names
[SSA_NAME_VERSION (expr
)];
1810 if (BINARY_CLASS_P (expr
) || COMPARISON_CLASS_P (expr
))
1813 = will_be_nonconstant_expr_predicate (fbi
, summary
,
1815 TREE_OPERAND (expr
, 0),
1821 = will_be_nonconstant_expr_predicate (fbi
, summary
,
1823 TREE_OPERAND (expr
, 1),
1825 return p1
.or_with (summary
->conds
, p2
);
1827 else if (TREE_CODE (expr
) == COND_EXPR
)
1830 = will_be_nonconstant_expr_predicate (fbi
, summary
,
1832 TREE_OPERAND (expr
, 0),
1838 = will_be_nonconstant_expr_predicate (fbi
, summary
,
1840 TREE_OPERAND (expr
, 1),
1844 p1
= p1
.or_with (summary
->conds
, p2
);
1845 p2
= will_be_nonconstant_expr_predicate (fbi
, summary
,
1847 TREE_OPERAND (expr
, 2),
1849 return p2
.or_with (summary
->conds
, p1
);
1851 else if (TREE_CODE (expr
) == CALL_EXPR
)
1862 /* Return predicate specifying when the STMT might have result that is not
1863 a compile time constant. */
1866 will_be_nonconstant_predicate (struct ipa_func_body_info
*fbi
,
1867 class ipa_fn_summary
*summary
,
1868 class ipa_node_params
*params_summary
,
1870 vec
<predicate
> nonconstant_names
)
1875 tree param_type
= NULL_TREE
;
1876 predicate op_non_const
;
1879 struct agg_position_info aggpos
;
1881 /* What statments might be optimized away
1882 when their arguments are constant. */
1883 if (gimple_code (stmt
) != GIMPLE_ASSIGN
1884 && gimple_code (stmt
) != GIMPLE_COND
1885 && gimple_code (stmt
) != GIMPLE_SWITCH
1886 && (gimple_code (stmt
) != GIMPLE_CALL
1887 || !(gimple_call_flags (stmt
) & ECF_CONST
)))
1890 /* Stores will stay anyway. */
1891 if (gimple_store_p (stmt
))
1894 is_load
= gimple_assign_load_p (stmt
);
1896 /* Loads can be optimized when the value is known. */
1899 tree op
= gimple_assign_rhs1 (stmt
);
1900 if (!decompose_param_expr (fbi
, stmt
, op
, &base_index
, ¶m_type
,
1907 /* See if we understand all operands before we start
1908 adding conditionals. */
1909 FOR_EACH_SSA_TREE_OPERAND (use
, stmt
, iter
, SSA_OP_USE
)
1911 tree parm
= unmodified_parm (fbi
, stmt
, use
, NULL
);
1912 /* For arguments we can build a condition. */
1913 if (parm
&& ipa_get_param_decl_index (fbi
->info
, parm
) >= 0)
1915 if (TREE_CODE (use
) != SSA_NAME
)
1917 /* If we know when operand is constant,
1918 we still can say something useful. */
1919 if (nonconstant_names
[SSA_NAME_VERSION (use
)] != true)
1926 add_condition (summary
, params_summary
,
1927 base_index
, param_type
, &aggpos
,
1928 predicate::changed
, NULL_TREE
);
1930 op_non_const
= false;
1931 FOR_EACH_SSA_TREE_OPERAND (use
, stmt
, iter
, SSA_OP_USE
)
1933 tree parm
= unmodified_parm (fbi
, stmt
, use
, NULL
);
1936 if (parm
&& (index
= ipa_get_param_decl_index (fbi
->info
, parm
)) >= 0)
1938 if (index
!= base_index
)
1939 p
= add_condition (summary
, params_summary
, index
,
1940 TREE_TYPE (parm
), NULL
,
1941 predicate::changed
, NULL_TREE
);
1946 p
= nonconstant_names
[SSA_NAME_VERSION (use
)];
1947 op_non_const
= p
.or_with (summary
->conds
, op_non_const
);
1949 if ((gimple_code (stmt
) == GIMPLE_ASSIGN
|| gimple_code (stmt
) == GIMPLE_CALL
)
1950 && gimple_op (stmt
, 0)
1951 && TREE_CODE (gimple_op (stmt
, 0)) == SSA_NAME
)
1952 nonconstant_names
[SSA_NAME_VERSION (gimple_op (stmt
, 0))]
1954 return op_non_const
;
1957 struct record_modified_bb_info
1964 /* Value is initialized in INIT_BB and used in USE_BB. We want to copute
1965 probability how often it changes between USE_BB.
1966 INIT_BB->count/USE_BB->count is an estimate, but if INIT_BB
1967 is in different loop nest, we can do better.
1968 This is all just estimate. In theory we look for minimal cut separating
1969 INIT_BB and USE_BB, but we only want to anticipate loop invariant motion
1973 get_minimal_bb (basic_block init_bb
, basic_block use_bb
)
1975 class loop
*l
= find_common_loop (init_bb
->loop_father
, use_bb
->loop_father
);
1976 if (l
&& l
->header
->count
< init_bb
->count
)
1981 /* Callback of walk_aliased_vdefs. Records basic blocks where the value may be
1982 set except for info->stmt. */
1985 record_modified (ao_ref
*ao ATTRIBUTE_UNUSED
, tree vdef
, void *data
)
1987 struct record_modified_bb_info
*info
=
1988 (struct record_modified_bb_info
*) data
;
1989 if (SSA_NAME_DEF_STMT (vdef
) == info
->stmt
)
1991 if (gimple_clobber_p (SSA_NAME_DEF_STMT (vdef
)))
1993 bitmap_set_bit (info
->bb_set
,
1994 SSA_NAME_IS_DEFAULT_DEF (vdef
)
1995 ? ENTRY_BLOCK_PTR_FOR_FN (cfun
)->index
1997 (gimple_bb (SSA_NAME_DEF_STMT (vdef
)),
1998 gimple_bb (info
->stmt
))->index
);
2001 fprintf (dump_file
, " Param ");
2002 print_generic_expr (dump_file
, info
->op
, TDF_SLIM
);
2003 fprintf (dump_file
, " changed at bb %i, minimal: %i stmt: ",
2004 gimple_bb (SSA_NAME_DEF_STMT (vdef
))->index
,
2006 (gimple_bb (SSA_NAME_DEF_STMT (vdef
)),
2007 gimple_bb (info
->stmt
))->index
);
2008 print_gimple_stmt (dump_file
, SSA_NAME_DEF_STMT (vdef
), 0);
2013 /* Return probability (based on REG_BR_PROB_BASE) that I-th parameter of STMT
2014 will change since last invocation of STMT.
2016 Value 0 is reserved for compile time invariants.
2017 For common parameters it is REG_BR_PROB_BASE. For loop invariants it
2018 ought to be REG_BR_PROB_BASE / estimated_iters. */
2021 param_change_prob (ipa_func_body_info
*fbi
, gimple
*stmt
, int i
)
2023 tree op
= gimple_call_arg (stmt
, i
);
2024 basic_block bb
= gimple_bb (stmt
);
2026 if (TREE_CODE (op
) == WITH_SIZE_EXPR
)
2027 op
= TREE_OPERAND (op
, 0);
2029 tree base
= get_base_address (op
);
2031 /* Global invariants never change. */
2032 if (is_gimple_min_invariant (base
))
2035 /* We would have to do non-trivial analysis to really work out what
2036 is the probability of value to change (i.e. when init statement
2037 is in a sibling loop of the call).
2039 We do an conservative estimate: when call is executed N times more often
2040 than the statement defining value, we take the frequency 1/N. */
2041 if (TREE_CODE (base
) == SSA_NAME
)
2043 profile_count init_count
;
2045 if (!bb
->count
.nonzero_p ())
2046 return REG_BR_PROB_BASE
;
2048 if (SSA_NAME_IS_DEFAULT_DEF (base
))
2049 init_count
= ENTRY_BLOCK_PTR_FOR_FN (cfun
)->count
;
2051 init_count
= get_minimal_bb
2052 (gimple_bb (SSA_NAME_DEF_STMT (base
)),
2053 gimple_bb (stmt
))->count
;
2055 if (init_count
< bb
->count
)
2056 return MAX ((init_count
.to_sreal_scale (bb
->count
)
2057 * REG_BR_PROB_BASE
).to_int (), 1);
2058 return REG_BR_PROB_BASE
;
2063 profile_count max
= ENTRY_BLOCK_PTR_FOR_FN (cfun
)->count
;
2064 struct record_modified_bb_info info
;
2065 tree init
= ctor_for_folding (base
);
2067 if (init
!= error_mark_node
)
2069 if (!bb
->count
.nonzero_p ())
2070 return REG_BR_PROB_BASE
;
2073 fprintf (dump_file
, " Analyzing param change probability of ");
2074 print_generic_expr (dump_file
, op
, TDF_SLIM
);
2075 fprintf (dump_file
, "\n");
2077 ao_ref_init (&refd
, op
);
2080 info
.bb_set
= BITMAP_ALLOC (NULL
);
2082 = walk_aliased_vdefs (&refd
, gimple_vuse (stmt
), record_modified
, &info
,
2083 NULL
, NULL
, fbi
->aa_walk_budget
);
2084 if (walked
< 0 || bitmap_bit_p (info
.bb_set
, bb
->index
))
2089 fprintf (dump_file
, " Ran out of AA walking budget.\n");
2091 fprintf (dump_file
, " Set in same BB as used.\n");
2093 BITMAP_FREE (info
.bb_set
);
2094 return REG_BR_PROB_BASE
;
2099 /* Lookup the most frequent update of the value and believe that
2100 it dominates all the other; precise analysis here is difficult. */
2101 EXECUTE_IF_SET_IN_BITMAP (info
.bb_set
, 0, index
, bi
)
2102 max
= max
.max (BASIC_BLOCK_FOR_FN (cfun
, index
)->count
);
2105 fprintf (dump_file
, " Set with count ");
2106 max
.dump (dump_file
);
2107 fprintf (dump_file
, " and used with count ");
2108 bb
->count
.dump (dump_file
);
2109 fprintf (dump_file
, " freq %f\n",
2110 max
.to_sreal_scale (bb
->count
).to_double ());
2113 BITMAP_FREE (info
.bb_set
);
2114 if (max
< bb
->count
)
2115 return MAX ((max
.to_sreal_scale (bb
->count
)
2116 * REG_BR_PROB_BASE
).to_int (), 1);
2117 return REG_BR_PROB_BASE
;
2121 /* Find whether a basic block BB is the final block of a (half) diamond CFG
2122 sub-graph and if the predicate the condition depends on is known. If so,
2123 return true and store the pointer the predicate in *P. */
2126 phi_result_unknown_predicate (ipa_func_body_info
*fbi
,
2127 ipa_fn_summary
*summary
,
2128 class ipa_node_params
*params_summary
,
2131 vec
<predicate
> nonconstant_names
)
2135 basic_block first_bb
= NULL
;
2138 if (single_pred_p (bb
))
2144 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
2146 if (single_succ_p (e
->src
))
2148 if (!single_pred_p (e
->src
))
2151 first_bb
= single_pred (e
->src
);
2152 else if (single_pred (e
->src
) != first_bb
)
2159 else if (e
->src
!= first_bb
)
2167 stmt
= last_stmt (first_bb
);
2169 || gimple_code (stmt
) != GIMPLE_COND
2170 || !is_gimple_ip_invariant (gimple_cond_rhs (stmt
)))
2173 *p
= will_be_nonconstant_expr_predicate (fbi
, summary
, params_summary
,
2174 gimple_cond_lhs (stmt
),
2182 /* Given a PHI statement in a function described by inline properties SUMMARY
2183 and *P being the predicate describing whether the selected PHI argument is
2184 known, store a predicate for the result of the PHI statement into
2185 NONCONSTANT_NAMES, if possible. */
2188 predicate_for_phi_result (class ipa_fn_summary
*summary
, gphi
*phi
,
2190 vec
<predicate
> nonconstant_names
)
2194 for (i
= 0; i
< gimple_phi_num_args (phi
); i
++)
2196 tree arg
= gimple_phi_arg (phi
, i
)->def
;
2197 if (!is_gimple_min_invariant (arg
))
2199 gcc_assert (TREE_CODE (arg
) == SSA_NAME
);
2200 *p
= p
->or_with (summary
->conds
,
2201 nonconstant_names
[SSA_NAME_VERSION (arg
)]);
2207 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
2209 fprintf (dump_file
, "\t\tphi predicate: ");
2210 p
->dump (dump_file
, summary
->conds
);
2212 nonconstant_names
[SSA_NAME_VERSION (gimple_phi_result (phi
))] = *p
;
2215 /* For a typical usage of __builtin_expect (a<b, 1), we
2216 may introduce an extra relation stmt:
2217 With the builtin, we have
2220 t3 = __builtin_expect (t2, 1);
2223 Without the builtin, we have
2226 This affects the size/time estimation and may have
2227 an impact on the earlier inlining.
2228 Here find this pattern and fix it up later. */
2231 find_foldable_builtin_expect (basic_block bb
)
2233 gimple_stmt_iterator bsi
;
2235 for (bsi
= gsi_start_bb (bb
); !gsi_end_p (bsi
); gsi_next (&bsi
))
2237 gimple
*stmt
= gsi_stmt (bsi
);
2238 if (gimple_call_builtin_p (stmt
, BUILT_IN_EXPECT
)
2239 || gimple_call_builtin_p (stmt
, BUILT_IN_EXPECT_WITH_PROBABILITY
)
2240 || gimple_call_internal_p (stmt
, IFN_BUILTIN_EXPECT
))
2242 tree var
= gimple_call_lhs (stmt
);
2243 tree arg
= gimple_call_arg (stmt
, 0);
2244 use_operand_p use_p
;
2251 gcc_assert (TREE_CODE (var
) == SSA_NAME
);
2253 while (TREE_CODE (arg
) == SSA_NAME
)
2255 gimple
*stmt_tmp
= SSA_NAME_DEF_STMT (arg
);
2256 if (!is_gimple_assign (stmt_tmp
))
2258 switch (gimple_assign_rhs_code (stmt_tmp
))
2277 arg
= gimple_assign_rhs1 (stmt_tmp
);
2280 if (match
&& single_imm_use (var
, &use_p
, &use_stmt
)
2281 && gimple_code (use_stmt
) == GIMPLE_COND
)
2288 /* Return true when the basic blocks contains only clobbers followed by RESX.
2289 Such BBs are kept around to make removal of dead stores possible with
2290 presence of EH and will be optimized out by optimize_clobbers later in the
2293 NEED_EH is used to recurse in case the clobber has non-EH predecestors
2294 that can be clobber only, too.. When it is false, the RESX is not necessary
2295 on the end of basic block. */
2298 clobber_only_eh_bb_p (basic_block bb
, bool need_eh
= true)
2300 gimple_stmt_iterator gsi
= gsi_last_bb (bb
);
2306 if (gsi_end_p (gsi
))
2308 if (gimple_code (gsi_stmt (gsi
)) != GIMPLE_RESX
)
2312 else if (!single_succ_p (bb
))
2315 for (; !gsi_end_p (gsi
); gsi_prev (&gsi
))
2317 gimple
*stmt
= gsi_stmt (gsi
);
2318 if (is_gimple_debug (stmt
))
2320 if (gimple_clobber_p (stmt
))
2322 if (gimple_code (stmt
) == GIMPLE_LABEL
)
2327 /* See if all predecestors are either throws or clobber only BBs. */
2328 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
2329 if (!(e
->flags
& EDGE_EH
)
2330 && !clobber_only_eh_bb_p (e
->src
, false))
2336 /* Return true if STMT compute a floating point expression that may be affected
2337 by -ffast-math and similar flags. */
2340 fp_expression_p (gimple
*stmt
)
2345 FOR_EACH_SSA_TREE_OPERAND (op
, stmt
, i
, SSA_OP_DEF
|SSA_OP_USE
)
2346 if (FLOAT_TYPE_P (TREE_TYPE (op
)))
2351 /* Analyze function body for NODE.
2352 EARLY indicates run from early optimization pipeline. */
2355 analyze_function_body (struct cgraph_node
*node
, bool early
)
2357 sreal time
= param_uninlined_function_time
;
2358 /* Estimate static overhead for function prologue/epilogue and alignment. */
2359 int size
= param_uninlined_function_insns
;
2360 /* Benefits are scaled by probability of elimination that is in range
2363 struct function
*my_function
= DECL_STRUCT_FUNCTION (node
->decl
);
2365 class ipa_fn_summary
*info
= ipa_fn_summaries
->get_create (node
);
2366 class ipa_node_params
*params_summary
= early
? NULL
: IPA_NODE_REF (node
);
2367 predicate bb_predicate
;
2368 struct ipa_func_body_info fbi
;
2369 vec
<predicate
> nonconstant_names
= vNULL
;
2372 gimple
*fix_builtin_expect_stmt
;
2374 gcc_assert (my_function
&& my_function
->cfg
);
2375 gcc_assert (cfun
== my_function
);
2377 memset(&fbi
, 0, sizeof(fbi
));
2378 vec_free (info
->conds
);
2380 vec_free (info
->size_time_table
);
2381 info
->size_time_table
= NULL
;
2383 /* When optimizing and analyzing for IPA inliner, initialize loop optimizer
2384 so we can produce proper inline hints.
2386 When optimizing and analyzing for early inliner, initialize node params
2387 so we can produce correct BB predicates. */
2389 if (opt_for_fn (node
->decl
, optimize
))
2391 calculate_dominance_info (CDI_DOMINATORS
);
2392 calculate_dominance_info (CDI_POST_DOMINATORS
);
2394 loop_optimizer_init (LOOPS_NORMAL
| LOOPS_HAVE_RECORDED_EXITS
);
2397 ipa_check_create_node_params ();
2398 ipa_initialize_node_params (node
);
2401 if (ipa_node_params_sum
)
2404 fbi
.info
= IPA_NODE_REF (node
);
2405 fbi
.bb_infos
= vNULL
;
2406 fbi
.bb_infos
.safe_grow_cleared (last_basic_block_for_fn (cfun
));
2407 fbi
.param_count
= count_formal_params (node
->decl
);
2408 fbi
.aa_walk_budget
= param_ipa_max_aa_steps
;
2410 nonconstant_names
.safe_grow_cleared
2411 (SSANAMES (my_function
)->length ());
2416 fprintf (dump_file
, "\nAnalyzing function body size: %s\n",
2419 /* When we run into maximal number of entries, we assign everything to the
2420 constant truth case. Be sure to have it in list. */
2421 bb_predicate
= true;
2422 info
->account_size_time (0, 0, bb_predicate
, bb_predicate
);
2424 bb_predicate
= predicate::not_inlined ();
2425 info
->account_size_time (param_uninlined_function_insns
2426 * ipa_fn_summary::size_scale
,
2427 param_uninlined_function_time
,
2432 compute_bb_predicates (&fbi
, node
, info
, params_summary
);
2433 order
= XNEWVEC (int, n_basic_blocks_for_fn (cfun
));
2434 nblocks
= pre_and_rev_post_order_compute (NULL
, order
, false);
2435 for (n
= 0; n
< nblocks
; n
++)
2437 bb
= BASIC_BLOCK_FOR_FN (cfun
, order
[n
]);
2438 freq
= bb
->count
.to_sreal_scale (ENTRY_BLOCK_PTR_FOR_FN (cfun
)->count
);
2439 if (clobber_only_eh_bb_p (bb
))
2441 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
2442 fprintf (dump_file
, "\n Ignoring BB %i;"
2443 " it will be optimized away by cleanup_clobbers\n",
2448 /* TODO: Obviously predicates can be propagated down across CFG. */
2452 bb_predicate
= *(predicate
*) bb
->aux
;
2454 bb_predicate
= false;
2457 bb_predicate
= true;
2459 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
2461 fprintf (dump_file
, "\n BB %i predicate:", bb
->index
);
2462 bb_predicate
.dump (dump_file
, info
->conds
);
2465 if (fbi
.info
&& nonconstant_names
.exists ())
2467 predicate phi_predicate
;
2468 bool first_phi
= true;
2470 for (gphi_iterator bsi
= gsi_start_phis (bb
); !gsi_end_p (bsi
);
2474 && !phi_result_unknown_predicate (&fbi
, info
,
2481 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
2483 fprintf (dump_file
, " ");
2484 print_gimple_stmt (dump_file
, gsi_stmt (bsi
), 0);
2486 predicate_for_phi_result (info
, bsi
.phi (), &phi_predicate
,
2491 fix_builtin_expect_stmt
= find_foldable_builtin_expect (bb
);
2493 for (gimple_stmt_iterator bsi
= gsi_start_nondebug_bb (bb
);
2494 !gsi_end_p (bsi
); gsi_next_nondebug (&bsi
))
2496 gimple
*stmt
= gsi_stmt (bsi
);
2497 int this_size
= estimate_num_insns (stmt
, &eni_size_weights
);
2498 int this_time
= estimate_num_insns (stmt
, &eni_time_weights
);
2500 predicate will_be_nonconstant
;
2502 /* This relation stmt should be folded after we remove
2503 buildin_expect call. Adjust the cost here. */
2504 if (stmt
== fix_builtin_expect_stmt
)
2510 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
2512 fprintf (dump_file
, " ");
2513 print_gimple_stmt (dump_file
, stmt
, 0);
2514 fprintf (dump_file
, "\t\tfreq:%3.2f size:%3i time:%3i\n",
2515 freq
.to_double (), this_size
,
2519 if (is_gimple_call (stmt
)
2520 && !gimple_call_internal_p (stmt
))
2522 struct cgraph_edge
*edge
= node
->get_edge (stmt
);
2523 ipa_call_summary
*es
= ipa_call_summaries
->get_create (edge
);
2525 /* Special case: results of BUILT_IN_CONSTANT_P will be always
2526 resolved as constant. We however don't want to optimize
2527 out the cgraph edges. */
2528 if (nonconstant_names
.exists ()
2529 && gimple_call_builtin_p (stmt
, BUILT_IN_CONSTANT_P
)
2530 && gimple_call_lhs (stmt
)
2531 && TREE_CODE (gimple_call_lhs (stmt
)) == SSA_NAME
)
2533 predicate false_p
= false;
2534 nonconstant_names
[SSA_NAME_VERSION (gimple_call_lhs (stmt
))]
2537 if (ipa_node_params_sum
)
2539 int count
= gimple_call_num_args (stmt
);
2543 es
->param
.safe_grow_cleared (count
);
2544 for (i
= 0; i
< count
; i
++)
2546 int prob
= param_change_prob (&fbi
, stmt
, i
);
2547 gcc_assert (prob
>= 0 && prob
<= REG_BR_PROB_BASE
);
2548 es
->param
[i
].change_prob
= prob
;
2552 es
->call_stmt_size
= this_size
;
2553 es
->call_stmt_time
= this_time
;
2554 es
->loop_depth
= bb_loop_depth (bb
);
2555 edge_set_predicate (edge
, &bb_predicate
);
2556 if (edge
->speculative
)
2558 cgraph_edge
*direct
, *indirect
;
2560 edge
->speculative_call_info (direct
, indirect
, ref
);
2561 gcc_assert (direct
== edge
);
2562 ipa_call_summary
*es2
2563 = ipa_call_summaries
->get_create (indirect
);
2564 ipa_call_summaries
->duplicate (edge
, indirect
,
2569 /* TODO: When conditional jump or swithc is known to be constant, but
2570 we did not translate it into the predicates, we really can account
2571 just maximum of the possible paths. */
2574 = will_be_nonconstant_predicate (&fbi
, info
, params_summary
,
2575 stmt
, nonconstant_names
);
2577 will_be_nonconstant
= true;
2578 if (this_time
|| this_size
)
2580 sreal final_time
= (sreal
)this_time
* freq
;
2582 prob
= eliminated_by_inlining_prob (&fbi
, stmt
);
2583 if (prob
== 1 && dump_file
&& (dump_flags
& TDF_DETAILS
))
2585 "\t\t50%% will be eliminated by inlining\n");
2586 if (prob
== 2 && dump_file
&& (dump_flags
& TDF_DETAILS
))
2587 fprintf (dump_file
, "\t\tWill be eliminated by inlining\n");
2589 class predicate p
= bb_predicate
& will_be_nonconstant
;
2591 /* We can ignore statement when we proved it is never going
2592 to happen, but we cannot do that for call statements
2593 because edges are accounted specially. */
2595 if (*(is_gimple_call (stmt
) ? &bb_predicate
: &p
) != false)
2601 /* We account everything but the calls. Calls have their own
2602 size/time info attached to cgraph edges. This is necessary
2603 in order to make the cost disappear after inlining. */
2604 if (!is_gimple_call (stmt
))
2608 predicate ip
= bb_predicate
& predicate::not_inlined ();
2609 info
->account_size_time (this_size
* prob
,
2610 (final_time
* prob
) / 2, ip
,
2614 info
->account_size_time (this_size
* (2 - prob
),
2615 (final_time
* (2 - prob
) / 2),
2620 if (!info
->fp_expressions
&& fp_expression_p (stmt
))
2622 info
->fp_expressions
= true;
2624 fprintf (dump_file
, " fp_expression set\n");
2628 /* Account cost of address calculations in the statements. */
2629 for (unsigned int i
= 0; i
< gimple_num_ops (stmt
); i
++)
2631 for (tree op
= gimple_op (stmt
, i
);
2632 op
&& handled_component_p (op
);
2633 op
= TREE_OPERAND (op
, 0))
2634 if ((TREE_CODE (op
) == ARRAY_REF
2635 || TREE_CODE (op
) == ARRAY_RANGE_REF
)
2636 && TREE_CODE (TREE_OPERAND (op
, 1)) == SSA_NAME
)
2638 predicate p
= bb_predicate
;
2640 p
= p
& will_be_nonconstant_expr_predicate
2641 (&fbi
, info
, params_summary
,
2642 TREE_OPERAND (op
, 1),
2650 "\t\tAccounting address calculation.\n");
2651 info
->account_size_time (ipa_fn_summary::size_scale
,
2663 if (nonconstant_names
.exists () && !early
)
2666 predicate loop_iterations
= true;
2667 predicate loop_stride
= true;
2669 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
2670 flow_loops_dump (dump_file
, NULL
, 0);
2672 FOR_EACH_LOOP (loop
, 0)
2677 class tree_niter_desc niter_desc
;
2678 bb_predicate
= *(predicate
*) loop
->header
->aux
;
2680 exits
= get_loop_exit_edges (loop
);
2681 FOR_EACH_VEC_ELT (exits
, j
, ex
)
2682 if (number_of_iterations_exit (loop
, ex
, &niter_desc
, false)
2683 && !is_gimple_min_invariant (niter_desc
.niter
))
2685 predicate will_be_nonconstant
2686 = will_be_nonconstant_expr_predicate (&fbi
, info
,
2690 if (will_be_nonconstant
!= true)
2691 will_be_nonconstant
= bb_predicate
& will_be_nonconstant
;
2692 if (will_be_nonconstant
!= true
2693 && will_be_nonconstant
!= false)
2694 /* This is slightly inprecise. We may want to represent each
2695 loop with independent predicate. */
2696 loop_iterations
&= will_be_nonconstant
;
2701 /* To avoid quadratic behavior we analyze stride predicates only
2702 with respect to the containing loop. Thus we simply iterate
2703 over all defs in the outermost loop body. */
2704 for (loop
= loops_for_fn (cfun
)->tree_root
->inner
;
2705 loop
!= NULL
; loop
= loop
->next
)
2707 basic_block
*body
= get_loop_body (loop
);
2708 for (unsigned i
= 0; i
< loop
->num_nodes
; i
++)
2710 gimple_stmt_iterator gsi
;
2711 bb_predicate
= *(predicate
*) body
[i
]->aux
;
2712 for (gsi
= gsi_start_bb (body
[i
]); !gsi_end_p (gsi
);
2715 gimple
*stmt
= gsi_stmt (gsi
);
2717 if (!is_gimple_assign (stmt
))
2720 tree def
= gimple_assign_lhs (stmt
);
2721 if (TREE_CODE (def
) != SSA_NAME
)
2725 if (!simple_iv (loop_containing_stmt (stmt
),
2726 loop_containing_stmt (stmt
),
2728 || is_gimple_min_invariant (iv
.step
))
2731 predicate will_be_nonconstant
2732 = will_be_nonconstant_expr_predicate (&fbi
, info
,
2736 if (will_be_nonconstant
!= true)
2737 will_be_nonconstant
= bb_predicate
& will_be_nonconstant
;
2738 if (will_be_nonconstant
!= true
2739 && will_be_nonconstant
!= false)
2740 /* This is slightly inprecise. We may want to represent
2741 each loop with independent predicate. */
2742 loop_stride
= loop_stride
& will_be_nonconstant
;
2747 ipa_fn_summary
*s
= ipa_fn_summaries
->get (node
);
2748 set_hint_predicate (&s
->loop_iterations
, loop_iterations
);
2749 set_hint_predicate (&s
->loop_stride
, loop_stride
);
2752 FOR_ALL_BB_FN (bb
, my_function
)
2758 edge_predicate_pool
.remove ((predicate
*)bb
->aux
);
2760 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
2763 edge_predicate_pool
.remove ((predicate
*) e
->aux
);
2767 ipa_fn_summary
*s
= ipa_fn_summaries
->get (node
);
2768 ipa_size_summary
*ss
= ipa_size_summaries
->get (node
);
2770 ss
->self_size
= size
;
2771 nonconstant_names
.release ();
2772 ipa_release_body_info (&fbi
);
2773 if (opt_for_fn (node
->decl
, optimize
))
2776 loop_optimizer_finalize ();
2777 else if (!ipa_edge_args_sum
)
2778 ipa_free_all_node_params ();
2779 free_dominance_info (CDI_DOMINATORS
);
2780 free_dominance_info (CDI_POST_DOMINATORS
);
2784 fprintf (dump_file
, "\n");
2785 ipa_dump_fn_summary (dump_file
, node
);
2790 /* Compute function summary.
2791 EARLY is true when we compute parameters during early opts. */
2794 compute_fn_summary (struct cgraph_node
*node
, bool early
)
2796 HOST_WIDE_INT self_stack_size
;
2797 struct cgraph_edge
*e
;
2799 gcc_assert (!node
->inlined_to
);
2801 if (!ipa_fn_summaries
)
2802 ipa_fn_summary_alloc ();
2804 /* Create a new ipa_fn_summary. */
2805 ((ipa_fn_summary_t
*)ipa_fn_summaries
)->remove_callees (node
);
2806 ipa_fn_summaries
->remove (node
);
2807 class ipa_fn_summary
*info
= ipa_fn_summaries
->get_create (node
);
2808 class ipa_size_summary
*size_info
= ipa_size_summaries
->get_create (node
);
2810 /* Estimate the stack size for the function if we're optimizing. */
2811 self_stack_size
= optimize
&& !node
->thunk
.thunk_p
2812 ? estimated_stack_frame_size (node
) : 0;
2813 size_info
->estimated_self_stack_size
= self_stack_size
;
2814 info
->estimated_stack_size
= self_stack_size
;
2816 if (node
->thunk
.thunk_p
)
2818 ipa_call_summary
*es
= ipa_call_summaries
->get_create (node
->callees
);
2821 node
->can_change_signature
= false;
2822 es
->call_stmt_size
= eni_size_weights
.call_cost
;
2823 es
->call_stmt_time
= eni_time_weights
.call_cost
;
2824 info
->account_size_time (ipa_fn_summary::size_scale
2825 * param_uninlined_function_thunk_insns
,
2826 param_uninlined_function_thunk_time
, t
, t
);
2827 t
= predicate::not_inlined ();
2828 info
->account_size_time (2 * ipa_fn_summary::size_scale
, 0, t
, t
);
2829 ipa_update_overall_fn_summary (node
);
2830 size_info
->self_size
= size_info
->size
;
2831 if (stdarg_p (TREE_TYPE (node
->decl
)))
2833 info
->inlinable
= false;
2834 node
->callees
->inline_failed
= CIF_VARIADIC_THUNK
;
2837 info
->inlinable
= true;
2841 /* Even is_gimple_min_invariant rely on current_function_decl. */
2842 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
2844 /* Can this function be inlined at all? */
2845 if (!opt_for_fn (node
->decl
, optimize
)
2846 && !lookup_attribute ("always_inline",
2847 DECL_ATTRIBUTES (node
->decl
)))
2848 info
->inlinable
= false;
2850 info
->inlinable
= tree_inlinable_function_p (node
->decl
);
2852 /* Type attributes can use parameter indices to describe them. */
2853 if (TYPE_ATTRIBUTES (TREE_TYPE (node
->decl
))
2854 /* Likewise for #pragma omp declare simd functions or functions
2855 with simd attribute. */
2856 || lookup_attribute ("omp declare simd",
2857 DECL_ATTRIBUTES (node
->decl
)))
2858 node
->can_change_signature
= false;
2861 /* Otherwise, inlinable functions always can change signature. */
2862 if (info
->inlinable
)
2863 node
->can_change_signature
= true;
2866 /* Functions calling builtin_apply cannot change signature. */
2867 for (e
= node
->callees
; e
; e
= e
->next_callee
)
2869 tree
cdecl = e
->callee
->decl
;
2870 if (fndecl_built_in_p (cdecl, BUILT_IN_APPLY_ARGS
)
2871 || fndecl_built_in_p (cdecl, BUILT_IN_VA_START
))
2874 node
->can_change_signature
= !e
;
2877 analyze_function_body (node
, early
);
2880 for (e
= node
->callees
; e
; e
= e
->next_callee
)
2881 if (e
->callee
->comdat_local_p ())
2883 node
->calls_comdat_local
= (e
!= NULL
);
2885 /* Inlining characteristics are maintained by the cgraph_mark_inline. */
2886 size_info
->size
= size_info
->self_size
;
2887 info
->estimated_stack_size
= size_info
->estimated_self_stack_size
;
2889 /* Code above should compute exactly the same result as
2890 ipa_update_overall_fn_summary but because computation happens in
2891 different order the roundoff errors result in slight changes. */
2892 ipa_update_overall_fn_summary (node
);
2893 /* In LTO mode we may have speculative edges set. */
2894 gcc_assert (in_lto_p
|| size_info
->size
== size_info
->self_size
);
2898 /* Compute parameters of functions used by inliner using
2899 current_function_decl. */
2902 compute_fn_summary_for_current (void)
2904 compute_fn_summary (cgraph_node::get (current_function_decl
), true);
2908 /* Estimate benefit devirtualizing indirect edge IE, provided KNOWN_VALS,
2909 KNOWN_CONTEXTS and KNOWN_AGGS. */
2912 estimate_edge_devirt_benefit (struct cgraph_edge
*ie
,
2913 int *size
, int *time
,
2914 vec
<tree
> known_vals
,
2915 vec
<ipa_polymorphic_call_context
> known_contexts
,
2916 vec
<ipa_agg_value_set
> known_aggs
)
2919 struct cgraph_node
*callee
;
2920 class ipa_fn_summary
*isummary
;
2921 enum availability avail
;
2924 if (!known_vals
.exists () && !known_contexts
.exists ())
2926 if (!opt_for_fn (ie
->caller
->decl
, flag_indirect_inlining
))
2929 target
= ipa_get_indirect_edge_target (ie
, known_vals
, known_contexts
,
2930 known_aggs
, &speculative
);
2931 if (!target
|| speculative
)
2934 /* Account for difference in cost between indirect and direct calls. */
2935 *size
-= (eni_size_weights
.indirect_call_cost
- eni_size_weights
.call_cost
);
2936 *time
-= (eni_time_weights
.indirect_call_cost
- eni_time_weights
.call_cost
);
2937 gcc_checking_assert (*time
>= 0);
2938 gcc_checking_assert (*size
>= 0);
2940 callee
= cgraph_node::get (target
);
2941 if (!callee
|| !callee
->definition
)
2943 callee
= callee
->function_symbol (&avail
);
2944 if (avail
< AVAIL_AVAILABLE
)
2946 isummary
= ipa_fn_summaries
->get (callee
);
2947 if (isummary
== NULL
)
2950 return isummary
->inlinable
;
2953 /* Increase SIZE, MIN_SIZE (if non-NULL) and TIME for size and time needed to
2954 handle edge E with probability PROB.
2955 Set HINTS if edge may be devirtualized.
2956 KNOWN_VALS, KNOWN_AGGS and KNOWN_CONTEXTS describe context of the call
2960 estimate_edge_size_and_time (struct cgraph_edge
*e
, int *size
, int *min_size
,
2962 vec
<tree
> known_vals
,
2963 vec
<ipa_polymorphic_call_context
> known_contexts
,
2964 vec
<ipa_agg_value_set
> known_aggs
,
2967 class ipa_call_summary
*es
= ipa_call_summaries
->get (e
);
2968 int call_size
= es
->call_stmt_size
;
2969 int call_time
= es
->call_stmt_time
;
2972 if (!e
->callee
&& hints
&& e
->maybe_hot_p ()
2973 && estimate_edge_devirt_benefit (e
, &call_size
, &call_time
,
2974 known_vals
, known_contexts
, known_aggs
))
2975 *hints
|= INLINE_HINT_indirect_call
;
2976 cur_size
= call_size
* ipa_fn_summary::size_scale
;
2979 *min_size
+= cur_size
;
2981 *time
+= ((sreal
)call_time
) * e
->sreal_frequency ();
2985 /* Increase SIZE, MIN_SIZE and TIME for size and time needed to handle all
2986 calls in NODE. POSSIBLE_TRUTHS, KNOWN_VALS, KNOWN_AGGS and KNOWN_CONTEXTS
2987 describe context of the call site.
2989 Helper for estimate_calls_size_and_time which does the same but
2990 (in most cases) faster. */
2993 estimate_calls_size_and_time_1 (struct cgraph_node
*node
, int *size
,
2994 int *min_size
, sreal
*time
,
2996 clause_t possible_truths
,
2997 vec
<tree
> known_vals
,
2998 vec
<ipa_polymorphic_call_context
> known_contexts
,
2999 vec
<ipa_agg_value_set
> known_aggs
)
3001 struct cgraph_edge
*e
;
3002 for (e
= node
->callees
; e
; e
= e
->next_callee
)
3004 if (!e
->inline_failed
)
3006 gcc_checking_assert (!ipa_call_summaries
->get (e
));
3007 estimate_calls_size_and_time_1 (e
->callee
, size
, min_size
, time
,
3010 known_vals
, known_contexts
,
3014 class ipa_call_summary
*es
= ipa_call_summaries
->get (e
);
3016 /* Do not care about zero sized builtins. */
3017 if (!es
->call_stmt_size
)
3019 gcc_checking_assert (!es
->call_stmt_time
);
3023 || es
->predicate
->evaluate (possible_truths
))
3025 /* Predicates of calls shall not use NOT_CHANGED codes,
3026 sowe do not need to compute probabilities. */
3027 estimate_edge_size_and_time (e
, size
,
3028 es
->predicate
? NULL
: min_size
,
3030 known_vals
, known_contexts
,
3034 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
3036 class ipa_call_summary
*es
= ipa_call_summaries
->get (e
);
3038 || es
->predicate
->evaluate (possible_truths
))
3039 estimate_edge_size_and_time (e
, size
,
3040 es
->predicate
? NULL
: min_size
,
3042 known_vals
, known_contexts
, known_aggs
,
3047 /* Populate sum->call_size_time_table for edges from NODE. */
3050 summarize_calls_size_and_time (struct cgraph_node
*node
,
3051 ipa_fn_summary
*sum
)
3053 struct cgraph_edge
*e
;
3054 for (e
= node
->callees
; e
; e
= e
->next_callee
)
3056 if (!e
->inline_failed
)
3058 gcc_checking_assert (!ipa_call_summaries
->get (e
));
3059 summarize_calls_size_and_time (e
->callee
, sum
);
3065 estimate_edge_size_and_time (e
, &size
, NULL
, &time
,
3066 vNULL
, vNULL
, vNULL
, NULL
);
3068 struct predicate pred
= true;
3069 class ipa_call_summary
*es
= ipa_call_summaries
->get (e
);
3072 pred
= *es
->predicate
;
3073 sum
->account_size_time (size
, time
, pred
, pred
, true);
3075 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
3080 estimate_edge_size_and_time (e
, &size
, NULL
, &time
,
3081 vNULL
, vNULL
, vNULL
, NULL
);
3082 struct predicate pred
= true;
3083 class ipa_call_summary
*es
= ipa_call_summaries
->get (e
);
3086 pred
= *es
->predicate
;
3087 sum
->account_size_time (size
, time
, pred
, pred
, true);
3091 /* Increase SIZE, MIN_SIZE and TIME for size and time needed to handle all
3092 calls in NODE. POSSIBLE_TRUTHS, KNOWN_VALS, KNOWN_AGGS and KNOWN_CONTEXTS
3093 describe context of the call site. */
3096 estimate_calls_size_and_time (struct cgraph_node
*node
, int *size
,
3097 int *min_size
, sreal
*time
,
3099 clause_t possible_truths
,
3100 vec
<tree
> known_vals
,
3101 vec
<ipa_polymorphic_call_context
> known_contexts
,
3102 vec
<ipa_agg_value_set
> known_aggs
)
3104 class ipa_fn_summary
*sum
= ipa_fn_summaries
->get (node
);
3105 bool use_table
= true;
3107 gcc_assert (node
->callees
|| node
->indirect_calls
);
3109 /* During early inlining we do not calculate info for very
3110 large functions and thus there is no need for producing
3112 if (!ipa_node_params_sum
)
3114 /* Do not calculate summaries for simple wrappers; it is waste
3116 else if (node
->callees
&& node
->indirect_calls
3117 && node
->callees
->inline_failed
&& !node
->callees
->next_callee
)
3119 /* If there is an indirect edge that may be optimized, we need
3120 to go the slow way. */
3121 else if ((known_vals
.length ()
3122 || known_contexts
.length ()
3123 || known_aggs
.length ()) && hints
)
3125 class ipa_node_params
*params_summary
= IPA_NODE_REF (node
);
3126 unsigned int nargs
= params_summary
3127 ? ipa_get_param_count (params_summary
) : 0;
3129 for (unsigned int i
= 0; i
< nargs
&& use_table
; i
++)
3131 if (ipa_is_param_used_by_indirect_call (params_summary
, i
)
3132 && ((known_vals
.length () > i
&& known_vals
[i
])
3133 || (known_aggs
.length () > i
3134 && known_aggs
[i
].items
.length ())))
3136 else if (ipa_is_param_used_by_polymorphic_call (params_summary
, i
)
3137 && (known_contexts
.length () > i
3138 && !known_contexts
[i
].useless_p ()))
3143 /* Fast path is via the call size time table. */
3146 /* Build summary if it is absent. */
3147 if (!sum
->call_size_time_table
)
3149 predicate true_pred
= true;
3150 sum
->account_size_time (0, 0, true_pred
, true_pred
, true);
3151 summarize_calls_size_and_time (node
, sum
);
3154 int old_size
= *size
;
3155 sreal old_time
= time
? *time
: 0;
3158 *min_size
+= (*sum
->call_size_time_table
)[0].size
;
3163 /* Walk the table and account sizes and times. */
3164 for (i
= 0; vec_safe_iterate (sum
->call_size_time_table
, i
, &e
);
3166 if (e
->exec_predicate
.evaluate (possible_truths
))
3173 /* Be careful and see if both methods agree. */
3174 if ((flag_checking
|| dump_file
)
3175 /* Do not try to sanity check when we know we lost some
3177 && sum
->call_size_time_table
->length ()
3178 < ipa_fn_summary::max_size_time_table_size
)
3180 estimate_calls_size_and_time_1 (node
, &old_size
, NULL
, &old_time
, NULL
,
3181 possible_truths
, known_vals
,
3182 known_contexts
, known_aggs
);
3183 gcc_assert (*size
== old_size
);
3184 if (time
&& (*time
- old_time
> 1 || *time
- old_time
< -1)
3186 fprintf (dump_file
, "Time mismatch in call summary %f!=%f",
3187 old_time
.to_double (),
3188 time
->to_double ());
3191 /* Slow path by walking all edges. */
3193 estimate_calls_size_and_time_1 (node
, size
, min_size
, time
, hints
,
3194 possible_truths
, known_vals
, known_contexts
,
3198 /* Default constructor for ipa call context.
3199 Memory alloction of known_vals, known_contexts
3200 and known_aggs vectors is owned by the caller, but can
3201 be release by ipa_call_context::release.
3203 inline_param_summary is owned by the caller. */
3204 ipa_call_context::ipa_call_context (cgraph_node
*node
,
3205 clause_t possible_truths
,
3206 clause_t nonspec_possible_truths
,
3207 vec
<tree
> known_vals
,
3208 vec
<ipa_polymorphic_call_context
>
3210 vec
<ipa_agg_value_set
> known_aggs
,
3211 vec
<inline_param_summary
>
3212 inline_param_summary
)
3213 : m_node (node
), m_possible_truths (possible_truths
),
3214 m_nonspec_possible_truths (nonspec_possible_truths
),
3215 m_inline_param_summary (inline_param_summary
),
3216 m_known_vals (known_vals
),
3217 m_known_contexts (known_contexts
),
3218 m_known_aggs (known_aggs
)
3222 /* Set THIS to be a duplicate of CTX. Copy all relevant info. */
3225 ipa_call_context::duplicate_from (const ipa_call_context
&ctx
)
3227 m_node
= ctx
.m_node
;
3228 m_possible_truths
= ctx
.m_possible_truths
;
3229 m_nonspec_possible_truths
= ctx
.m_nonspec_possible_truths
;
3230 class ipa_node_params
*params_summary
= IPA_NODE_REF (m_node
);
3231 unsigned int nargs
= params_summary
3232 ? ipa_get_param_count (params_summary
) : 0;
3234 m_inline_param_summary
= vNULL
;
3235 /* Copy the info only if there is at least one useful entry. */
3236 if (ctx
.m_inline_param_summary
.exists ())
3238 unsigned int n
= MIN (ctx
.m_inline_param_summary
.length (), nargs
);
3240 for (unsigned int i
= 0; i
< n
; i
++)
3241 if (ipa_is_param_used_by_ipa_predicates (params_summary
, i
)
3242 && !ctx
.m_inline_param_summary
[i
].useless_p ())
3244 m_inline_param_summary
3245 = ctx
.m_inline_param_summary
.copy ();
3249 m_known_vals
= vNULL
;
3250 if (ctx
.m_known_vals
.exists ())
3252 unsigned int n
= MIN (ctx
.m_known_vals
.length (), nargs
);
3254 for (unsigned int i
= 0; i
< n
; i
++)
3255 if (ipa_is_param_used_by_indirect_call (params_summary
, i
)
3256 && ctx
.m_known_vals
[i
])
3258 m_known_vals
= ctx
.m_known_vals
.copy ();
3263 m_known_contexts
= vNULL
;
3264 if (ctx
.m_known_contexts
.exists ())
3266 unsigned int n
= MIN (ctx
.m_known_contexts
.length (), nargs
);
3268 for (unsigned int i
= 0; i
< n
; i
++)
3269 if (ipa_is_param_used_by_polymorphic_call (params_summary
, i
)
3270 && !ctx
.m_known_contexts
[i
].useless_p ())
3272 m_known_contexts
= ctx
.m_known_contexts
.copy ();
3277 m_known_aggs
= vNULL
;
3278 if (ctx
.m_known_aggs
.exists ())
3280 unsigned int n
= MIN (ctx
.m_known_aggs
.length (), nargs
);
3282 for (unsigned int i
= 0; i
< n
; i
++)
3283 if (ipa_is_param_used_by_indirect_call (params_summary
, i
)
3284 && !ctx
.m_known_aggs
[i
].is_empty ())
3286 m_known_aggs
= ipa_copy_agg_values (ctx
.m_known_aggs
);
3292 /* Release memory used by known_vals/contexts/aggs vectors.
3293 If ALL is true release also inline_param_summary.
3294 This happens when context was previously duplciated to be stored
3298 ipa_call_context::release (bool all
)
3300 /* See if context is initialized at first place. */
3303 m_known_vals
.release ();
3304 m_known_contexts
.release ();
3305 ipa_release_agg_values (m_known_aggs
);
3307 m_inline_param_summary
.release ();
3310 /* Return true if CTX describes the same call context as THIS. */
3313 ipa_call_context::equal_to (const ipa_call_context
&ctx
)
3315 if (m_node
!= ctx
.m_node
3316 || m_possible_truths
!= ctx
.m_possible_truths
3317 || m_nonspec_possible_truths
!= ctx
.m_nonspec_possible_truths
)
3320 class ipa_node_params
*params_summary
= IPA_NODE_REF (m_node
);
3321 unsigned int nargs
= params_summary
3322 ? ipa_get_param_count (params_summary
) : 0;
3324 if (m_inline_param_summary
.exists () || ctx
.m_inline_param_summary
.exists ())
3326 for (unsigned int i
= 0; i
< nargs
; i
++)
3328 if (!ipa_is_param_used_by_ipa_predicates (params_summary
, i
))
3330 if (i
>= m_inline_param_summary
.length ()
3331 || m_inline_param_summary
[i
].useless_p ())
3333 if (i
< ctx
.m_inline_param_summary
.length ()
3334 && !ctx
.m_inline_param_summary
[i
].useless_p ())
3338 if (i
>= ctx
.m_inline_param_summary
.length ()
3339 || ctx
.m_inline_param_summary
[i
].useless_p ())
3341 if (i
< m_inline_param_summary
.length ()
3342 && !m_inline_param_summary
[i
].useless_p ())
3346 if (!m_inline_param_summary
[i
].equal_to
3347 (ctx
.m_inline_param_summary
[i
]))
3351 if (m_known_vals
.exists () || ctx
.m_known_vals
.exists ())
3353 for (unsigned int i
= 0; i
< nargs
; i
++)
3355 if (!ipa_is_param_used_by_indirect_call (params_summary
, i
))
3357 if (i
>= m_known_vals
.length () || !m_known_vals
[i
])
3359 if (i
< ctx
.m_known_vals
.length () && ctx
.m_known_vals
[i
])
3363 if (i
>= ctx
.m_known_vals
.length () || !ctx
.m_known_vals
[i
])
3365 if (i
< m_known_vals
.length () && m_known_vals
[i
])
3369 if (m_known_vals
[i
] != ctx
.m_known_vals
[i
])
3373 if (m_known_contexts
.exists () || ctx
.m_known_contexts
.exists ())
3375 for (unsigned int i
= 0; i
< nargs
; i
++)
3377 if (!ipa_is_param_used_by_polymorphic_call (params_summary
, i
))
3379 if (i
>= m_known_contexts
.length ()
3380 || m_known_contexts
[i
].useless_p ())
3382 if (i
< ctx
.m_known_contexts
.length ()
3383 && !ctx
.m_known_contexts
[i
].useless_p ())
3387 if (i
>= ctx
.m_known_contexts
.length ()
3388 || ctx
.m_known_contexts
[i
].useless_p ())
3390 if (i
< m_known_contexts
.length ()
3391 && !m_known_contexts
[i
].useless_p ())
3395 if (!m_known_contexts
[i
].equal_to
3396 (ctx
.m_known_contexts
[i
]))
3400 if (m_known_aggs
.exists () || ctx
.m_known_aggs
.exists ())
3402 for (unsigned int i
= 0; i
< nargs
; i
++)
3404 if (!ipa_is_param_used_by_indirect_call (params_summary
, i
))
3406 if (i
>= m_known_aggs
.length () || m_known_aggs
[i
].is_empty ())
3408 if (i
< ctx
.m_known_aggs
.length ()
3409 && !ctx
.m_known_aggs
[i
].is_empty ())
3413 if (i
>= ctx
.m_known_aggs
.length ()
3414 || ctx
.m_known_aggs
[i
].is_empty ())
3416 if (i
< m_known_aggs
.length ()
3417 && !m_known_aggs
[i
].is_empty ())
3421 if (!m_known_aggs
[i
].equal_to (ctx
.m_known_aggs
[i
]))
3428 /* Estimate size and time needed to execute call in the given context.
3429 Additionally detemine hints determined by the context. Finally compute
3430 minimal size needed for the call that is independent on the call context and
3431 can be used for fast estimates. Return the values in RET_SIZE,
3432 RET_MIN_SIZE, RET_TIME and RET_HINTS. */
3435 ipa_call_context::estimate_size_and_time (int *ret_size
,
3438 sreal
*ret_nonspecialized_time
,
3439 ipa_hints
*ret_hints
)
3441 class ipa_fn_summary
*info
= ipa_fn_summaries
->get (m_node
);
3446 ipa_hints hints
= 0;
3449 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
3452 fprintf (dump_file
, " Estimating body: %s/%i\n"
3453 " Known to be false: ", m_node
->name (),
3456 for (i
= predicate::not_inlined_condition
;
3457 i
< (predicate::first_dynamic_condition
3458 + (int) vec_safe_length (info
->conds
)); i
++)
3459 if (!(m_possible_truths
& (1 << i
)))
3462 fprintf (dump_file
, ", ");
3464 dump_condition (dump_file
, info
->conds
, i
);
3468 if (m_node
->callees
|| m_node
->indirect_calls
)
3469 estimate_calls_size_and_time (m_node
, &size
, &min_size
,
3470 ret_time
? &time
: NULL
,
3471 ret_hints
? &hints
: NULL
, m_possible_truths
,
3472 m_known_vals
, m_known_contexts
, m_known_aggs
);
3474 sreal nonspecialized_time
= time
;
3476 min_size
+= (*info
->size_time_table
)[0].size
;
3477 for (i
= 0; vec_safe_iterate (info
->size_time_table
, i
, &e
); i
++)
3479 bool exec
= e
->exec_predicate
.evaluate (m_nonspec_possible_truths
);
3481 /* Because predicates are conservative, it can happen that nonconst is 1
3485 bool nonconst
= e
->nonconst_predicate
.evaluate (m_possible_truths
);
3487 gcc_checking_assert (e
->time
>= 0);
3488 gcc_checking_assert (time
>= 0);
3490 /* We compute specialized size only because size of nonspecialized
3491 copy is context independent.
3493 The difference between nonspecialized execution and specialized is
3494 that nonspecialized is not going to have optimized out computations
3495 known to be constant in a specialized setting. */
3500 nonspecialized_time
+= e
->time
;
3503 else if (!m_inline_param_summary
.exists ())
3510 int prob
= e
->nonconst_predicate
.probability
3511 (info
->conds
, m_possible_truths
,
3512 m_inline_param_summary
);
3513 gcc_checking_assert (prob
>= 0);
3514 gcc_checking_assert (prob
<= REG_BR_PROB_BASE
);
3515 if (prob
== REG_BR_PROB_BASE
)
3518 time
+= e
->time
* prob
/ REG_BR_PROB_BASE
;
3520 gcc_checking_assert (time
>= 0);
3523 gcc_checking_assert ((*info
->size_time_table
)[0].exec_predicate
== true);
3524 gcc_checking_assert ((*info
->size_time_table
)[0].nonconst_predicate
== true);
3525 gcc_checking_assert (min_size
>= 0);
3526 gcc_checking_assert (size
>= 0);
3527 gcc_checking_assert (time
>= 0);
3528 /* nonspecialized_time should be always bigger than specialized time.
3529 Roundoff issues however may get into the way. */
3530 gcc_checking_assert ((nonspecialized_time
- time
* 99 / 100) >= -1);
3532 /* Roundoff issues may make specialized time bigger than nonspecialized
3533 time. We do not really want that to happen because some heurstics
3534 may get confused by seeing negative speedups. */
3535 if (time
> nonspecialized_time
)
3536 time
= nonspecialized_time
;
3540 if (info
->loop_iterations
3541 && !info
->loop_iterations
->evaluate (m_possible_truths
))
3542 hints
|= INLINE_HINT_loop_iterations
;
3543 if (info
->loop_stride
3544 && !info
->loop_stride
->evaluate (m_possible_truths
))
3545 hints
|= INLINE_HINT_loop_stride
;
3547 hints
|= INLINE_HINT_in_scc
;
3548 if (DECL_DECLARED_INLINE_P (m_node
->decl
))
3549 hints
|= INLINE_HINT_declared_inline
;
3552 size
= RDIV (size
, ipa_fn_summary::size_scale
);
3553 min_size
= RDIV (min_size
, ipa_fn_summary::size_scale
);
3555 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
3556 fprintf (dump_file
, "\n size:%i time:%f nonspec time:%f\n", (int) size
,
3557 time
.to_double (), nonspecialized_time
.to_double ());
3560 if (ret_nonspecialized_time
)
3561 *ret_nonspecialized_time
= nonspecialized_time
;
3565 *ret_min_size
= min_size
;
3572 /* Estimate size and time needed to execute callee of EDGE assuming that
3573 parameters known to be constant at caller of EDGE are propagated.
3574 KNOWN_VALS and KNOWN_CONTEXTS are vectors of assumed known constant values
3575 and types for parameters. */
3578 estimate_ipcp_clone_size_and_time (struct cgraph_node
*node
,
3579 vec
<tree
> known_vals
,
3580 vec
<ipa_polymorphic_call_context
>
3582 vec
<ipa_agg_value_set
> known_aggs
,
3583 int *ret_size
, sreal
*ret_time
,
3584 sreal
*ret_nonspec_time
,
3587 clause_t clause
, nonspec_clause
;
3589 /* TODO: Also pass known value ranges. */
3590 evaluate_conditions_for_known_args (node
, false, known_vals
, vNULL
,
3591 known_aggs
, &clause
, &nonspec_clause
);
3592 ipa_call_context
ctx (node
, clause
, nonspec_clause
,
3593 known_vals
, known_contexts
,
3595 ctx
.estimate_size_and_time (ret_size
, NULL
, ret_time
,
3596 ret_nonspec_time
, hints
);
3599 /* Return stack frame offset where frame of NODE is supposed to start inside
3600 of the function it is inlined to.
3601 Return 0 for functions that are not inlined. */
3604 ipa_get_stack_frame_offset (struct cgraph_node
*node
)
3606 HOST_WIDE_INT offset
= 0;
3607 if (!node
->inlined_to
)
3609 node
= node
->callers
->caller
;
3612 offset
+= ipa_size_summaries
->get (node
)->estimated_self_stack_size
;
3613 if (!node
->inlined_to
)
3615 node
= node
->callers
->caller
;
3620 /* Update summary information of inline clones after inlining.
3621 Compute peak stack usage. */
3624 inline_update_callee_summaries (struct cgraph_node
*node
, int depth
)
3626 struct cgraph_edge
*e
;
3628 ipa_propagate_frequency (node
);
3629 for (e
= node
->callees
; e
; e
= e
->next_callee
)
3631 if (!e
->inline_failed
)
3632 inline_update_callee_summaries (e
->callee
, depth
);
3634 ipa_call_summaries
->get (e
)->loop_depth
+= depth
;
3636 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
3637 ipa_call_summaries
->get (e
)->loop_depth
+= depth
;
3640 /* Update change_prob of EDGE after INLINED_EDGE has been inlined.
3641 When function A is inlined in B and A calls C with parameter that
3642 changes with probability PROB1 and C is known to be passthroug
3643 of argument if B that change with probability PROB2, the probability
3644 of change is now PROB1*PROB2. */
3647 remap_edge_change_prob (struct cgraph_edge
*inlined_edge
,
3648 struct cgraph_edge
*edge
)
3650 if (ipa_node_params_sum
)
3653 class ipa_edge_args
*args
= IPA_EDGE_REF (edge
);
3656 class ipa_call_summary
*es
= ipa_call_summaries
->get (edge
);
3657 class ipa_call_summary
*inlined_es
3658 = ipa_call_summaries
->get (inlined_edge
);
3660 if (es
->param
.length () == 0)
3663 for (i
= 0; i
< ipa_get_cs_argument_count (args
); i
++)
3665 struct ipa_jump_func
*jfunc
= ipa_get_ith_jump_func (args
, i
);
3666 if (jfunc
->type
== IPA_JF_PASS_THROUGH
3667 || jfunc
->type
== IPA_JF_ANCESTOR
)
3669 int id
= jfunc
->type
== IPA_JF_PASS_THROUGH
3670 ? ipa_get_jf_pass_through_formal_id (jfunc
)
3671 : ipa_get_jf_ancestor_formal_id (jfunc
);
3672 if (id
< (int) inlined_es
->param
.length ())
3674 int prob1
= es
->param
[i
].change_prob
;
3675 int prob2
= inlined_es
->param
[id
].change_prob
;
3676 int prob
= combine_probabilities (prob1
, prob2
);
3678 if (prob1
&& prob2
&& !prob
)
3681 es
->param
[i
].change_prob
= prob
;
3688 /* Update edge summaries of NODE after INLINED_EDGE has been inlined.
3690 Remap predicates of callees of NODE. Rest of arguments match
3693 Also update change probabilities. */
3696 remap_edge_summaries (struct cgraph_edge
*inlined_edge
,
3697 struct cgraph_node
*node
,
3698 class ipa_fn_summary
*info
,
3699 class ipa_node_params
*params_summary
,
3700 class ipa_fn_summary
*callee_info
,
3701 vec
<int> operand_map
,
3702 vec
<int> offset_map
,
3703 clause_t possible_truths
,
3704 predicate
*toplev_predicate
)
3706 struct cgraph_edge
*e
, *next
;
3707 for (e
= node
->callees
; e
; e
= next
)
3710 next
= e
->next_callee
;
3712 if (e
->inline_failed
)
3714 class ipa_call_summary
*es
= ipa_call_summaries
->get (e
);
3715 remap_edge_change_prob (inlined_edge
, e
);
3719 p
= es
->predicate
->remap_after_inlining
3720 (info
, params_summary
,
3721 callee_info
, operand_map
,
3722 offset_map
, possible_truths
,
3724 edge_set_predicate (e
, &p
);
3727 edge_set_predicate (e
, toplev_predicate
);
3730 remap_edge_summaries (inlined_edge
, e
->callee
, info
,
3731 params_summary
, callee_info
,
3732 operand_map
, offset_map
, possible_truths
,
3735 for (e
= node
->indirect_calls
; e
; e
= next
)
3737 class ipa_call_summary
*es
= ipa_call_summaries
->get (e
);
3739 next
= e
->next_callee
;
3741 remap_edge_change_prob (inlined_edge
, e
);
3744 p
= es
->predicate
->remap_after_inlining
3745 (info
, params_summary
,
3746 callee_info
, operand_map
, offset_map
,
3747 possible_truths
, *toplev_predicate
);
3748 edge_set_predicate (e
, &p
);
3751 edge_set_predicate (e
, toplev_predicate
);
3755 /* Same as remap_predicate, but set result into hint *HINT. */
3758 remap_hint_predicate (class ipa_fn_summary
*info
,
3759 class ipa_node_params
*params_summary
,
3760 class ipa_fn_summary
*callee_info
,
3762 vec
<int> operand_map
,
3763 vec
<int> offset_map
,
3764 clause_t possible_truths
,
3765 predicate
*toplev_predicate
)
3771 p
= (*hint
)->remap_after_inlining
3772 (info
, params_summary
, callee_info
,
3773 operand_map
, offset_map
,
3774 possible_truths
, *toplev_predicate
);
3775 if (p
!= false && p
!= true)
3778 set_hint_predicate (hint
, p
);
3784 /* We inlined EDGE. Update summary of the function we inlined into. */
3787 ipa_merge_fn_summary_after_inlining (struct cgraph_edge
*edge
)
3789 ipa_fn_summary
*callee_info
= ipa_fn_summaries
->get (edge
->callee
);
3790 struct cgraph_node
*to
= (edge
->caller
->inlined_to
3791 ? edge
->caller
->inlined_to
: edge
->caller
);
3792 class ipa_fn_summary
*info
= ipa_fn_summaries
->get (to
);
3793 clause_t clause
= 0; /* not_inline is known to be false. */
3795 auto_vec
<int, 8> operand_map
;
3796 auto_vec
<int, 8> offset_map
;
3798 predicate toplev_predicate
;
3799 class ipa_call_summary
*es
= ipa_call_summaries
->get (edge
);
3800 class ipa_node_params
*params_summary
= (ipa_node_params_sum
3801 ? IPA_NODE_REF (to
) : NULL
);
3804 toplev_predicate
= *es
->predicate
;
3806 toplev_predicate
= true;
3808 info
->fp_expressions
|= callee_info
->fp_expressions
;
3810 if (callee_info
->conds
)
3811 evaluate_properties_for_edge (edge
, true, &clause
,
3812 NULL
, NULL
, NULL
, NULL
);
3813 if (ipa_node_params_sum
&& callee_info
->conds
)
3815 class ipa_edge_args
*args
= IPA_EDGE_REF (edge
);
3816 int count
= args
? ipa_get_cs_argument_count (args
) : 0;
3821 operand_map
.safe_grow_cleared (count
);
3822 offset_map
.safe_grow_cleared (count
);
3824 for (i
= 0; i
< count
; i
++)
3826 struct ipa_jump_func
*jfunc
= ipa_get_ith_jump_func (args
, i
);
3829 /* TODO: handle non-NOPs when merging. */
3830 if (jfunc
->type
== IPA_JF_PASS_THROUGH
)
3832 if (ipa_get_jf_pass_through_operation (jfunc
) == NOP_EXPR
)
3833 map
= ipa_get_jf_pass_through_formal_id (jfunc
);
3834 if (!ipa_get_jf_pass_through_agg_preserved (jfunc
))
3837 else if (jfunc
->type
== IPA_JF_ANCESTOR
)
3839 HOST_WIDE_INT offset
= ipa_get_jf_ancestor_offset (jfunc
);
3840 if (offset
>= 0 && offset
< INT_MAX
)
3842 map
= ipa_get_jf_ancestor_formal_id (jfunc
);
3843 if (!ipa_get_jf_ancestor_agg_preserved (jfunc
))
3845 offset_map
[i
] = offset
;
3848 operand_map
[i
] = map
;
3849 gcc_assert (map
< ipa_get_param_count (params_summary
));
3852 sreal freq
= edge
->sreal_frequency ();
3853 for (i
= 0; vec_safe_iterate (callee_info
->size_time_table
, i
, &e
); i
++)
3856 p
= e
->exec_predicate
.remap_after_inlining
3857 (info
, params_summary
,
3858 callee_info
, operand_map
,
3861 predicate nonconstp
;
3862 nonconstp
= e
->nonconst_predicate
.remap_after_inlining
3863 (info
, params_summary
,
3864 callee_info
, operand_map
,
3867 if (p
!= false && nonconstp
!= false)
3869 sreal add_time
= ((sreal
)e
->time
* freq
);
3870 int prob
= e
->nonconst_predicate
.probability (callee_info
->conds
,
3872 if (prob
!= REG_BR_PROB_BASE
)
3873 add_time
= add_time
* prob
/ REG_BR_PROB_BASE
;
3874 if (prob
!= REG_BR_PROB_BASE
3875 && dump_file
&& (dump_flags
& TDF_DETAILS
))
3877 fprintf (dump_file
, "\t\tScaling time by probability:%f\n",
3878 (double) prob
/ REG_BR_PROB_BASE
);
3880 info
->account_size_time (e
->size
, add_time
, p
, nonconstp
);
3883 remap_edge_summaries (edge
, edge
->callee
, info
, params_summary
,
3884 callee_info
, operand_map
,
3885 offset_map
, clause
, &toplev_predicate
);
3886 remap_hint_predicate (info
, params_summary
, callee_info
,
3887 &callee_info
->loop_iterations
,
3888 operand_map
, offset_map
, clause
, &toplev_predicate
);
3889 remap_hint_predicate (info
, params_summary
, callee_info
,
3890 &callee_info
->loop_stride
,
3891 operand_map
, offset_map
, clause
, &toplev_predicate
);
3893 HOST_WIDE_INT stack_frame_offset
= ipa_get_stack_frame_offset (edge
->callee
);
3894 HOST_WIDE_INT peak
= stack_frame_offset
+ callee_info
->estimated_stack_size
;
3896 if (info
->estimated_stack_size
< peak
)
3897 info
->estimated_stack_size
= peak
;
3899 inline_update_callee_summaries (edge
->callee
, es
->loop_depth
);
3901 /* Free summaries that are not maintained for inline clones/edges. */
3902 ipa_call_summaries
->remove (edge
);
3903 ipa_fn_summaries
->remove (edge
->callee
);
3904 ipa_remove_from_growth_caches (edge
);
3907 /* For performance reasons ipa_merge_fn_summary_after_inlining is not updating
3908 overall size and time. Recompute it. */
3911 ipa_update_overall_fn_summary (struct cgraph_node
*node
)
3913 class ipa_fn_summary
*info
= ipa_fn_summaries
->get (node
);
3914 class ipa_size_summary
*size_info
= ipa_size_summaries
->get (node
);
3918 size_info
->size
= 0;
3920 for (i
= 0; vec_safe_iterate (info
->size_time_table
, i
, &e
); i
++)
3922 size_info
->size
+= e
->size
;
3923 info
->time
+= e
->time
;
3925 info
->min_size
= (*info
->size_time_table
)[0].size
;
3926 vec_free (info
->call_size_time_table
);
3927 if (node
->callees
|| node
->indirect_calls
)
3928 estimate_calls_size_and_time (node
, &size_info
->size
, &info
->min_size
,
3930 ~(clause_t
) (1 << predicate::false_condition
),
3931 vNULL
, vNULL
, vNULL
);
3932 size_info
->size
= RDIV (size_info
->size
, ipa_fn_summary::size_scale
);
3933 info
->min_size
= RDIV (info
->min_size
, ipa_fn_summary::size_scale
);
3937 /* This function performs intraprocedural analysis in NODE that is required to
3938 inline indirect calls. */
3941 inline_indirect_intraprocedural_analysis (struct cgraph_node
*node
)
3943 ipa_analyze_node (node
);
3944 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
3946 ipa_print_node_params (dump_file
, node
);
3947 ipa_print_node_jump_functions (dump_file
, node
);
3952 /* Note function body size. */
3955 inline_analyze_function (struct cgraph_node
*node
)
3957 push_cfun (DECL_STRUCT_FUNCTION (node
->decl
));
3960 fprintf (dump_file
, "\nAnalyzing function: %s/%u\n",
3961 node
->name (), node
->order
);
3962 if (opt_for_fn (node
->decl
, optimize
) && !node
->thunk
.thunk_p
)
3963 inline_indirect_intraprocedural_analysis (node
);
3964 compute_fn_summary (node
, false);
3967 struct cgraph_edge
*e
;
3968 for (e
= node
->callees
; e
; e
= e
->next_callee
)
3969 e
->inline_failed
= CIF_FUNCTION_NOT_OPTIMIZED
;
3970 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
3971 e
->inline_failed
= CIF_FUNCTION_NOT_OPTIMIZED
;
3978 /* Called when new function is inserted to callgraph late. */
3981 ipa_fn_summary_t::insert (struct cgraph_node
*node
, ipa_fn_summary
*)
3983 inline_analyze_function (node
);
3986 /* Note function body size. */
3989 ipa_fn_summary_generate (void)
3991 struct cgraph_node
*node
;
3993 FOR_EACH_DEFINED_FUNCTION (node
)
3994 if (DECL_STRUCT_FUNCTION (node
->decl
))
3995 node
->versionable
= tree_versionable_function_p (node
->decl
);
3997 ipa_fn_summary_alloc ();
3999 ipa_fn_summaries
->enable_insertion_hook ();
4001 ipa_register_cgraph_hooks ();
4003 FOR_EACH_DEFINED_FUNCTION (node
)
4005 && (flag_generate_lto
|| flag_generate_offload
|| flag_wpa
4006 || opt_for_fn (node
->decl
, optimize
)))
4007 inline_analyze_function (node
);
4011 /* Write inline summary for edge E to OB. */
4014 read_ipa_call_summary (class lto_input_block
*ib
, struct cgraph_edge
*e
,
4017 class ipa_call_summary
*es
= prevails
4018 ? ipa_call_summaries
->get_create (e
) : NULL
;
4022 int size
= streamer_read_uhwi (ib
);
4023 int time
= streamer_read_uhwi (ib
);
4024 int depth
= streamer_read_uhwi (ib
);
4028 es
->call_stmt_size
= size
;
4029 es
->call_stmt_time
= time
;
4030 es
->loop_depth
= depth
;
4033 bitpack_d bp
= streamer_read_bitpack (ib
);
4035 es
->is_return_callee_uncaptured
= bp_unpack_value (&bp
, 1);
4037 bp_unpack_value (&bp
, 1);
4041 edge_set_predicate (e
, &p
);
4042 length
= streamer_read_uhwi (ib
);
4043 if (length
&& es
&& e
->possibly_call_in_translation_unit_p ())
4045 es
->param
.safe_grow_cleared (length
);
4046 for (i
= 0; i
< length
; i
++)
4047 es
->param
[i
].change_prob
= streamer_read_uhwi (ib
);
4051 for (i
= 0; i
< length
; i
++)
4052 streamer_read_uhwi (ib
);
4057 /* Stream in inline summaries from the section. */
4060 inline_read_section (struct lto_file_decl_data
*file_data
, const char *data
,
4063 const struct lto_function_header
*header
=
4064 (const struct lto_function_header
*) data
;
4065 const int cfg_offset
= sizeof (struct lto_function_header
);
4066 const int main_offset
= cfg_offset
+ header
->cfg_size
;
4067 const int string_offset
= main_offset
+ header
->main_size
;
4068 class data_in
*data_in
;
4069 unsigned int i
, count2
, j
;
4070 unsigned int f_count
;
4072 lto_input_block
ib ((const char *) data
+ main_offset
, header
->main_size
,
4073 file_data
->mode_table
);
4076 lto_data_in_create (file_data
, (const char *) data
+ string_offset
,
4077 header
->string_size
, vNULL
);
4078 f_count
= streamer_read_uhwi (&ib
);
4079 for (i
= 0; i
< f_count
; i
++)
4082 struct cgraph_node
*node
;
4083 class ipa_fn_summary
*info
;
4084 class ipa_node_params
*params_summary
;
4085 class ipa_size_summary
*size_info
;
4086 lto_symtab_encoder_t encoder
;
4087 struct bitpack_d bp
;
4088 struct cgraph_edge
*e
;
4091 index
= streamer_read_uhwi (&ib
);
4092 encoder
= file_data
->symtab_node_encoder
;
4093 node
= dyn_cast
<cgraph_node
*> (lto_symtab_encoder_deref (encoder
,
4095 info
= node
->prevailing_p () ? ipa_fn_summaries
->get_create (node
) : NULL
;
4096 params_summary
= node
->prevailing_p () ? IPA_NODE_REF (node
) : NULL
;
4097 size_info
= node
->prevailing_p ()
4098 ? ipa_size_summaries
->get_create (node
) : NULL
;
4100 int stack_size
= streamer_read_uhwi (&ib
);
4101 int size
= streamer_read_uhwi (&ib
);
4102 sreal time
= sreal::stream_in (&ib
);
4106 info
->estimated_stack_size
4107 = size_info
->estimated_self_stack_size
= stack_size
;
4108 size_info
->size
= size_info
->self_size
= size
;
4112 bp
= streamer_read_bitpack (&ib
);
4115 info
->inlinable
= bp_unpack_value (&bp
, 1);
4116 info
->fp_expressions
= bp_unpack_value (&bp
, 1);
4120 bp_unpack_value (&bp
, 1);
4121 bp_unpack_value (&bp
, 1);
4124 count2
= streamer_read_uhwi (&ib
);
4125 gcc_assert (!info
|| !info
->conds
);
4127 vec_safe_reserve_exact (info
->conds
, count2
);
4128 for (j
= 0; j
< count2
; j
++)
4131 unsigned int k
, count3
;
4132 c
.operand_num
= streamer_read_uhwi (&ib
);
4133 c
.code
= (enum tree_code
) streamer_read_uhwi (&ib
);
4134 c
.type
= stream_read_tree (&ib
, data_in
);
4135 c
.val
= stream_read_tree (&ib
, data_in
);
4136 bp
= streamer_read_bitpack (&ib
);
4137 c
.agg_contents
= bp_unpack_value (&bp
, 1);
4138 c
.by_ref
= bp_unpack_value (&bp
, 1);
4140 c
.offset
= streamer_read_uhwi (&ib
);
4141 count3
= streamer_read_uhwi (&ib
);
4144 vec_safe_reserve_exact (c
.param_ops
, count3
);
4146 ipa_set_param_used_by_ipa_predicates
4147 (params_summary
, c
.operand_num
, true);
4148 for (k
= 0; k
< count3
; k
++)
4150 struct expr_eval_op op
;
4151 enum gimple_rhs_class rhs_class
;
4152 op
.code
= (enum tree_code
) streamer_read_uhwi (&ib
);
4153 op
.type
= stream_read_tree (&ib
, data_in
);
4154 switch (rhs_class
= get_gimple_rhs_class (op
.code
))
4156 case GIMPLE_UNARY_RHS
:
4158 op
.val
[0] = NULL_TREE
;
4159 op
.val
[1] = NULL_TREE
;
4162 case GIMPLE_BINARY_RHS
:
4163 case GIMPLE_TERNARY_RHS
:
4164 bp
= streamer_read_bitpack (&ib
);
4165 op
.index
= bp_unpack_value (&bp
, 2);
4166 op
.val
[0] = stream_read_tree (&ib
, data_in
);
4167 if (rhs_class
== GIMPLE_BINARY_RHS
)
4168 op
.val
[1] = NULL_TREE
;
4170 op
.val
[1] = stream_read_tree (&ib
, data_in
);
4174 fatal_error (UNKNOWN_LOCATION
,
4175 "invalid fnsummary in LTO stream");
4178 c
.param_ops
->quick_push (op
);
4181 info
->conds
->quick_push (c
);
4183 count2
= streamer_read_uhwi (&ib
);
4184 gcc_assert (!info
|| !info
->size_time_table
);
4186 vec_safe_reserve_exact (info
->size_time_table
, count2
);
4187 for (j
= 0; j
< count2
; j
++)
4189 class size_time_entry e
;
4191 e
.size
= streamer_read_uhwi (&ib
);
4192 e
.time
= sreal::stream_in (&ib
);
4193 e
.exec_predicate
.stream_in (&ib
);
4194 e
.nonconst_predicate
.stream_in (&ib
);
4197 info
->size_time_table
->quick_push (e
);
4202 set_hint_predicate (&info
->loop_iterations
, p
);
4205 set_hint_predicate (&info
->loop_stride
, p
);
4206 for (e
= node
->callees
; e
; e
= e
->next_callee
)
4207 read_ipa_call_summary (&ib
, e
, info
!= NULL
);
4208 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
4209 read_ipa_call_summary (&ib
, e
, info
!= NULL
);
4212 lto_free_section_data (file_data
, LTO_section_ipa_fn_summary
, NULL
, data
,
4214 lto_data_in_delete (data_in
);
4218 /* Read inline summary. Jump functions are shared among ipa-cp
4219 and inliner, so when ipa-cp is active, we don't need to write them
4223 ipa_fn_summary_read (void)
4225 struct lto_file_decl_data
**file_data_vec
= lto_get_file_decl_data ();
4226 struct lto_file_decl_data
*file_data
;
4229 ipa_fn_summary_alloc ();
4231 while ((file_data
= file_data_vec
[j
++]))
4235 = lto_get_summary_section_data (file_data
, LTO_section_ipa_fn_summary
,
4238 inline_read_section (file_data
, data
, len
);
4240 /* Fatal error here. We do not want to support compiling ltrans units
4241 with different version of compiler or different flags than the WPA
4242 unit, so this should never happen. */
4243 fatal_error (input_location
,
4244 "ipa inline summary is missing in input file");
4246 ipa_register_cgraph_hooks ();
4248 ipa_prop_read_jump_functions ();
4250 gcc_assert (ipa_fn_summaries
);
4251 ipa_fn_summaries
->enable_insertion_hook ();
4255 /* Write inline summary for edge E to OB. */
4258 write_ipa_call_summary (struct output_block
*ob
, struct cgraph_edge
*e
)
4260 class ipa_call_summary
*es
= ipa_call_summaries
->get (e
);
4263 streamer_write_uhwi (ob
, es
->call_stmt_size
);
4264 streamer_write_uhwi (ob
, es
->call_stmt_time
);
4265 streamer_write_uhwi (ob
, es
->loop_depth
);
4267 bitpack_d bp
= bitpack_create (ob
->main_stream
);
4268 bp_pack_value (&bp
, es
->is_return_callee_uncaptured
, 1);
4269 streamer_write_bitpack (&bp
);
4272 es
->predicate
->stream_out (ob
);
4274 streamer_write_uhwi (ob
, 0);
4275 streamer_write_uhwi (ob
, es
->param
.length ());
4276 for (i
= 0; i
< (int) es
->param
.length (); i
++)
4277 streamer_write_uhwi (ob
, es
->param
[i
].change_prob
);
4281 /* Write inline summary for node in SET.
4282 Jump functions are shared among ipa-cp and inliner, so when ipa-cp is
4283 active, we don't need to write them twice. */
4286 ipa_fn_summary_write (void)
4288 struct output_block
*ob
= create_output_block (LTO_section_ipa_fn_summary
);
4289 lto_symtab_encoder_t encoder
= ob
->decl_state
->symtab_node_encoder
;
4290 unsigned int count
= 0;
4293 for (i
= 0; i
< lto_symtab_encoder_size (encoder
); i
++)
4295 symtab_node
*snode
= lto_symtab_encoder_deref (encoder
, i
);
4296 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (snode
);
4297 if (cnode
&& cnode
->definition
&& !cnode
->alias
)
4300 streamer_write_uhwi (ob
, count
);
4302 for (i
= 0; i
< lto_symtab_encoder_size (encoder
); i
++)
4304 symtab_node
*snode
= lto_symtab_encoder_deref (encoder
, i
);
4305 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (snode
);
4306 if (cnode
&& cnode
->definition
&& !cnode
->alias
)
4308 class ipa_fn_summary
*info
= ipa_fn_summaries
->get (cnode
);
4309 class ipa_size_summary
*size_info
= ipa_size_summaries
->get (cnode
);
4310 struct bitpack_d bp
;
4311 struct cgraph_edge
*edge
;
4314 struct condition
*c
;
4316 streamer_write_uhwi (ob
, lto_symtab_encoder_encode (encoder
, cnode
));
4317 streamer_write_hwi (ob
, size_info
->estimated_self_stack_size
);
4318 streamer_write_hwi (ob
, size_info
->self_size
);
4319 info
->time
.stream_out (ob
);
4320 bp
= bitpack_create (ob
->main_stream
);
4321 bp_pack_value (&bp
, info
->inlinable
, 1);
4322 bp_pack_value (&bp
, false, 1);
4323 bp_pack_value (&bp
, info
->fp_expressions
, 1);
4324 streamer_write_bitpack (&bp
);
4325 streamer_write_uhwi (ob
, vec_safe_length (info
->conds
));
4326 for (i
= 0; vec_safe_iterate (info
->conds
, i
, &c
); i
++)
4329 struct expr_eval_op
*op
;
4331 streamer_write_uhwi (ob
, c
->operand_num
);
4332 streamer_write_uhwi (ob
, c
->code
);
4333 stream_write_tree (ob
, c
->type
, true);
4334 stream_write_tree (ob
, c
->val
, true);
4335 bp
= bitpack_create (ob
->main_stream
);
4336 bp_pack_value (&bp
, c
->agg_contents
, 1);
4337 bp_pack_value (&bp
, c
->by_ref
, 1);
4338 streamer_write_bitpack (&bp
);
4339 if (c
->agg_contents
)
4340 streamer_write_uhwi (ob
, c
->offset
);
4341 streamer_write_uhwi (ob
, vec_safe_length (c
->param_ops
));
4342 for (j
= 0; vec_safe_iterate (c
->param_ops
, j
, &op
); j
++)
4344 streamer_write_uhwi (ob
, op
->code
);
4345 stream_write_tree (ob
, op
->type
, true);
4348 bp
= bitpack_create (ob
->main_stream
);
4349 bp_pack_value (&bp
, op
->index
, 2);
4350 streamer_write_bitpack (&bp
);
4351 stream_write_tree (ob
, op
->val
[0], true);
4353 stream_write_tree (ob
, op
->val
[1], true);
4357 streamer_write_uhwi (ob
, vec_safe_length (info
->size_time_table
));
4358 for (i
= 0; vec_safe_iterate (info
->size_time_table
, i
, &e
); i
++)
4360 streamer_write_uhwi (ob
, e
->size
);
4361 e
->time
.stream_out (ob
);
4362 e
->exec_predicate
.stream_out (ob
);
4363 e
->nonconst_predicate
.stream_out (ob
);
4365 if (info
->loop_iterations
)
4366 info
->loop_iterations
->stream_out (ob
);
4368 streamer_write_uhwi (ob
, 0);
4369 if (info
->loop_stride
)
4370 info
->loop_stride
->stream_out (ob
);
4372 streamer_write_uhwi (ob
, 0);
4373 for (edge
= cnode
->callees
; edge
; edge
= edge
->next_callee
)
4374 write_ipa_call_summary (ob
, edge
);
4375 for (edge
= cnode
->indirect_calls
; edge
; edge
= edge
->next_callee
)
4376 write_ipa_call_summary (ob
, edge
);
4379 streamer_write_char_stream (ob
->main_stream
, 0);
4380 produce_asm (ob
, NULL
);
4381 destroy_output_block (ob
);
4384 ipa_prop_write_jump_functions ();
4388 /* Release function summary. */
4391 ipa_free_fn_summary (void)
4393 if (!ipa_call_summaries
)
4395 ggc_delete (ipa_fn_summaries
);
4396 ipa_fn_summaries
= NULL
;
4397 delete ipa_call_summaries
;
4398 ipa_call_summaries
= NULL
;
4399 edge_predicate_pool
.release ();
4400 /* During IPA this is one of largest datastructures to release. */
4405 /* Release function summary. */
4408 ipa_free_size_summary (void)
4410 if (!ipa_size_summaries
)
4412 delete ipa_size_summaries
;
4413 ipa_size_summaries
= NULL
;
4418 const pass_data pass_data_local_fn_summary
=
4420 GIMPLE_PASS
, /* type */
4421 "local-fnsummary", /* name */
4422 OPTGROUP_INLINE
, /* optinfo_flags */
4423 TV_INLINE_PARAMETERS
, /* tv_id */
4424 0, /* properties_required */
4425 0, /* properties_provided */
4426 0, /* properties_destroyed */
4427 0, /* todo_flags_start */
4428 0, /* todo_flags_finish */
4431 class pass_local_fn_summary
: public gimple_opt_pass
4434 pass_local_fn_summary (gcc::context
*ctxt
)
4435 : gimple_opt_pass (pass_data_local_fn_summary
, ctxt
)
4438 /* opt_pass methods: */
4439 opt_pass
* clone () { return new pass_local_fn_summary (m_ctxt
); }
4440 virtual unsigned int execute (function
*)
4442 return compute_fn_summary_for_current ();
4445 }; // class pass_local_fn_summary
4450 make_pass_local_fn_summary (gcc::context
*ctxt
)
4452 return new pass_local_fn_summary (ctxt
);
4456 /* Free inline summary. */
4460 const pass_data pass_data_ipa_free_fn_summary
=
4462 SIMPLE_IPA_PASS
, /* type */
4463 "free-fnsummary", /* name */
4464 OPTGROUP_NONE
, /* optinfo_flags */
4465 TV_IPA_FREE_INLINE_SUMMARY
, /* tv_id */
4466 0, /* properties_required */
4467 0, /* properties_provided */
4468 0, /* properties_destroyed */
4469 0, /* todo_flags_start */
4470 0, /* todo_flags_finish */
4473 class pass_ipa_free_fn_summary
: public simple_ipa_opt_pass
4476 pass_ipa_free_fn_summary (gcc::context
*ctxt
)
4477 : simple_ipa_opt_pass (pass_data_ipa_free_fn_summary
, ctxt
),
4481 /* opt_pass methods: */
4482 opt_pass
*clone () { return new pass_ipa_free_fn_summary (m_ctxt
); }
4483 void set_pass_param (unsigned int n
, bool param
)
4485 gcc_assert (n
== 0);
4488 virtual bool gate (function
*) { return true; }
4489 virtual unsigned int execute (function
*)
4491 ipa_free_fn_summary ();
4493 ipa_free_size_summary ();
4499 }; // class pass_ipa_free_fn_summary
4503 simple_ipa_opt_pass
*
4504 make_pass_ipa_free_fn_summary (gcc::context
*ctxt
)
4506 return new pass_ipa_free_fn_summary (ctxt
);
4511 const pass_data pass_data_ipa_fn_summary
=
4513 IPA_PASS
, /* type */
4514 "fnsummary", /* name */
4515 OPTGROUP_INLINE
, /* optinfo_flags */
4516 TV_IPA_FNSUMMARY
, /* tv_id */
4517 0, /* properties_required */
4518 0, /* properties_provided */
4519 0, /* properties_destroyed */
4520 0, /* todo_flags_start */
4521 ( TODO_dump_symtab
), /* todo_flags_finish */
4524 class pass_ipa_fn_summary
: public ipa_opt_pass_d
4527 pass_ipa_fn_summary (gcc::context
*ctxt
)
4528 : ipa_opt_pass_d (pass_data_ipa_fn_summary
, ctxt
,
4529 ipa_fn_summary_generate
, /* generate_summary */
4530 ipa_fn_summary_write
, /* write_summary */
4531 ipa_fn_summary_read
, /* read_summary */
4532 NULL
, /* write_optimization_summary */
4533 NULL
, /* read_optimization_summary */
4534 NULL
, /* stmt_fixup */
4535 0, /* function_transform_todo_flags_start */
4536 NULL
, /* function_transform */
4537 NULL
) /* variable_transform */
4540 /* opt_pass methods: */
4541 virtual unsigned int execute (function
*) { return 0; }
4543 }; // class pass_ipa_fn_summary
4548 make_pass_ipa_fn_summary (gcc::context
*ctxt
)
4550 return new pass_ipa_fn_summary (ctxt
);
4553 /* Reset all state within ipa-fnsummary.c so that we can rerun the compiler
4554 within the same process. For use by toplev::finalize. */
4557 ipa_fnsummary_c_finalize (void)
4559 ipa_free_fn_summary ();