1 /* Inlining decision heuristics.
2 Copyright (C) 2003, 2004, 2007, 2008, 2009, 2010, 2011
3 Free Software Foundation, Inc.
4 Contributed by Jan Hubicka
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 /* Analysis used by the inliner and other passes limiting code size growth.
24 We estimate for each function
26 - average function execution time
27 - inlining size benefit (that is how much of function body size
28 and its call sequence is expected to disappear by inlining)
29 - inlining time benefit
32 - call statement size and time
34 inlinie_summary datastructures store above information locally (i.e.
35 parameters of the function itself) and globally (i.e. parameters of
36 the function created by applying all the inline decisions already
37 present in the callgraph).
39 We provide accestor to the inline_summary datastructure and
40 basic logic updating the parameters when inlining is performed.
42 The summaries are context sensitive. Context means
43 1) partial assignment of known constant values of operands
44 2) whether function is inlined into the call or not.
45 It is easy to add more variants. To represent function size and time
46 that depends on context (i.e. it is known to be optimized away when
47 context is known either by inlining or from IP-CP and clonning),
48 we use predicates. Predicates are logical formulas in
49 conjunctive-disjunctive form consisting of clauses. Clauses are bitmaps
50 specifying what conditions must be true. Conditions are simple test
51 of the form described above.
53 In order to make predicate (possibly) true, all of its clauses must
54 be (possibly) true. To make clause (possibly) true, one of conditions
55 it mentions must be (possibly) true. There are fixed bounds on
56 number of clauses and conditions and all the manipulation functions
57 are conservative in positive direction. I.e. we may lose precision
58 by thinking that predicate may be true even when it is not.
60 estimate_edge_size and estimate_edge_growth can be used to query
61 function size/time in the given context. inline_merge_summary merges
62 properties of caller and callee after inlining.
64 Finally pass_inline_parameters is exported. This is used to drive
65 computation of function parameters used by the early inliner. IPA
66 inlined performs analysis via its analyze_function method. */
70 #include "coretypes.h"
73 #include "tree-inline.h"
74 #include "langhooks.h"
77 #include "diagnostic.h"
78 #include "gimple-pretty-print.h"
80 #include "tree-pass.h"
83 #include "tree-flow.h"
85 #include "lto-streamer.h"
86 #include "data-streamer.h"
87 #include "tree-streamer.h"
88 #include "ipa-inline.h"
89 #include "alloc-pool.h"
92 #include "tree-scalar-evolution.h"
94 /* Estimate runtime of function can easilly run into huge numbers with many
95 nested loops. Be sure we can compute time * INLINE_SIZE_SCALE * 2 in an
96 integer. For anything larger we use gcov_type. */
97 #define MAX_TIME 500000
99 /* Number of bits in integer, but we really want to be stable across different
101 #define NUM_CONDITIONS 32
103 enum predicate_conditions
105 predicate_false_condition
= 0,
106 predicate_not_inlined_condition
= 1,
107 predicate_first_dynamic_condition
= 2
110 /* Special condition code we use to represent test that operand is compile time
112 #define IS_NOT_CONSTANT ERROR_MARK
113 /* Special condition code we use to represent test that operand is not changed
114 across invocation of the function. When operand IS_NOT_CONSTANT it is always
115 CHANGED, however i.e. loop invariants can be NOT_CHANGED given percentage
116 of executions even when they are not compile time constants. */
117 #define CHANGED IDENTIFIER_NODE
119 /* Holders of ipa cgraph hooks: */
120 static struct cgraph_node_hook_list
*function_insertion_hook_holder
;
121 static struct cgraph_node_hook_list
*node_removal_hook_holder
;
122 static struct cgraph_2node_hook_list
*node_duplication_hook_holder
;
123 static struct cgraph_2edge_hook_list
*edge_duplication_hook_holder
;
124 static struct cgraph_edge_hook_list
*edge_removal_hook_holder
;
125 static void inline_node_removal_hook (struct cgraph_node
*, void *);
126 static void inline_node_duplication_hook (struct cgraph_node
*,
127 struct cgraph_node
*, void *);
128 static void inline_edge_removal_hook (struct cgraph_edge
*, void *);
129 static void inline_edge_duplication_hook (struct cgraph_edge
*,
130 struct cgraph_edge
*,
133 /* VECtor holding inline summaries.
134 In GGC memory because conditions might point to constant trees. */
135 vec
<inline_summary_t
, va_gc
> *inline_summary_vec
;
136 vec
<inline_edge_summary_t
> inline_edge_summary_vec
;
138 /* Cached node/edge growths. */
139 vec
<int> node_growth_cache
;
140 vec
<edge_growth_cache_entry
> edge_growth_cache
;
142 /* Edge predicates goes here. */
143 static alloc_pool edge_predicate_pool
;
145 /* Return true predicate (tautology).
146 We represent it by empty list of clauses. */
148 static inline struct predicate
149 true_predicate (void)
157 /* Return predicate testing single condition number COND. */
159 static inline struct predicate
160 single_cond_predicate (int cond
)
163 p
.clause
[0] = 1 << cond
;
169 /* Return false predicate. First clause require false condition. */
171 static inline struct predicate
172 false_predicate (void)
174 return single_cond_predicate (predicate_false_condition
);
178 /* Return true if P is (false). */
181 true_predicate_p (struct predicate
*p
)
183 return !p
->clause
[0];
187 /* Return true if P is (false). */
190 false_predicate_p (struct predicate
*p
)
192 if (p
->clause
[0] == (1 << predicate_false_condition
))
194 gcc_checking_assert (!p
->clause
[1]
195 && p
->clause
[0] == 1 << predicate_false_condition
);
202 /* Return predicate that is set true when function is not inlined. */
203 static inline struct predicate
204 not_inlined_predicate (void)
206 return single_cond_predicate (predicate_not_inlined_condition
);
209 /* Simple description of whether a memory load or a condition refers to a load
210 from an aggregate and if so, how and where from in the aggregate.
211 Individual fields have the same meaning like fields with the same name in
214 struct agg_position_info
216 HOST_WIDE_INT offset
;
221 /* Add condition to condition list CONDS. AGGPOS describes whether the used
222 oprand is loaded from an aggregate and where in the aggregate it is. It can
223 be NULL, which means this not a load from an aggregate. */
225 static struct predicate
226 add_condition (struct inline_summary
*summary
, int operand_num
,
227 struct agg_position_info
*aggpos
,
228 enum tree_code code
, tree val
)
232 struct condition new_cond
;
233 HOST_WIDE_INT offset
;
234 bool agg_contents
, by_ref
;
238 offset
= aggpos
->offset
;
239 agg_contents
= aggpos
->agg_contents
;
240 by_ref
= aggpos
->by_ref
;
245 agg_contents
= false;
249 gcc_checking_assert (operand_num
>= 0);
250 for (i
= 0; vec_safe_iterate (summary
->conds
, i
, &c
); i
++)
252 if (c
->operand_num
== operand_num
255 && c
->agg_contents
== agg_contents
256 && (!agg_contents
|| (c
->offset
== offset
&& c
->by_ref
== by_ref
)))
257 return single_cond_predicate (i
+ predicate_first_dynamic_condition
);
259 /* Too many conditions. Give up and return constant true. */
260 if (i
== NUM_CONDITIONS
- predicate_first_dynamic_condition
)
261 return true_predicate ();
263 new_cond
.operand_num
= operand_num
;
264 new_cond
.code
= code
;
266 new_cond
.agg_contents
= agg_contents
;
267 new_cond
.by_ref
= by_ref
;
268 new_cond
.offset
= offset
;
269 vec_safe_push (summary
->conds
, new_cond
);
270 return single_cond_predicate (i
+ predicate_first_dynamic_condition
);
274 /* Add clause CLAUSE into the predicate P. */
277 add_clause (conditions conditions
, struct predicate
*p
, clause_t clause
)
281 int insert_here
= -1;
288 /* False clause makes the whole predicate false. Kill the other variants. */
289 if (clause
== (1 << predicate_false_condition
))
291 p
->clause
[0] = (1 << predicate_false_condition
);
295 if (false_predicate_p (p
))
298 /* No one should be sily enough to add false into nontrivial clauses. */
299 gcc_checking_assert (!(clause
& (1 << predicate_false_condition
)));
301 /* Look where to insert the clause. At the same time prune out
302 clauses of P that are implied by the new clause and thus
304 for (i
= 0, i2
= 0; i
<= MAX_CLAUSES
; i
++)
306 p
->clause
[i2
] = p
->clause
[i
];
311 /* If p->clause[i] implies clause, there is nothing to add. */
312 if ((p
->clause
[i
] & clause
) == p
->clause
[i
])
314 /* We had nothing to add, none of clauses should've become
316 gcc_checking_assert (i
== i2
);
320 if (p
->clause
[i
] < clause
&& insert_here
< 0)
323 /* If clause implies p->clause[i], then p->clause[i] becomes redundant.
324 Otherwise the p->clause[i] has to stay. */
325 if ((p
->clause
[i
] & clause
) != clause
)
329 /* Look for clauses that are obviously true. I.e.
330 op0 == 5 || op0 != 5. */
331 for (c1
= predicate_first_dynamic_condition
; c1
< NUM_CONDITIONS
; c1
++)
334 if (!(clause
& (1 << c1
)))
336 cc1
= &(*conditions
)[c1
- predicate_first_dynamic_condition
];
337 /* We have no way to represent !CHANGED and !IS_NOT_CONSTANT
338 and thus there is no point for looking for them. */
339 if (cc1
->code
== CHANGED
340 || cc1
->code
== IS_NOT_CONSTANT
)
342 for (c2
= c1
+ 1; c2
<= NUM_CONDITIONS
; c2
++)
343 if (clause
& (1 << c2
))
345 condition
*cc1
= &(*conditions
)[c1
- predicate_first_dynamic_condition
];
346 condition
*cc2
= &(*conditions
)[c2
- predicate_first_dynamic_condition
];
347 if (cc1
->operand_num
== cc2
->operand_num
348 && cc1
->val
== cc2
->val
349 && cc2
->code
!= IS_NOT_CONSTANT
350 && cc2
->code
!= CHANGED
351 && cc1
->code
== invert_tree_comparison
353 HONOR_NANS (TYPE_MODE (TREE_TYPE (cc1
->val
)))))
359 /* We run out of variants. Be conservative in positive direction. */
360 if (i2
== MAX_CLAUSES
)
362 /* Keep clauses in decreasing order. This makes equivalence testing easy. */
363 p
->clause
[i2
+ 1] = 0;
364 if (insert_here
>= 0)
365 for (;i2
> insert_here
; i2
--)
366 p
->clause
[i2
] = p
->clause
[i2
- 1];
369 p
->clause
[insert_here
] = clause
;
375 static struct predicate
376 and_predicates (conditions conditions
,
377 struct predicate
*p
, struct predicate
*p2
)
379 struct predicate out
= *p
;
382 /* Avoid busy work. */
383 if (false_predicate_p (p2
) || true_predicate_p (p
))
385 if (false_predicate_p (p
) || true_predicate_p (p2
))
388 /* See how far predicates match. */
389 for (i
= 0; p
->clause
[i
] && p
->clause
[i
] == p2
->clause
[i
]; i
++)
391 gcc_checking_assert (i
< MAX_CLAUSES
);
394 /* Combine the predicates rest. */
395 for (; p2
->clause
[i
]; i
++)
397 gcc_checking_assert (i
< MAX_CLAUSES
);
398 add_clause (conditions
, &out
, p2
->clause
[i
]);
404 /* Return true if predicates are obviously equal. */
407 predicates_equal_p (struct predicate
*p
, struct predicate
*p2
)
410 for (i
= 0; p
->clause
[i
]; i
++)
412 gcc_checking_assert (i
< MAX_CLAUSES
);
413 gcc_checking_assert (p
->clause
[i
] > p
->clause
[i
+ 1]);
414 gcc_checking_assert (!p2
->clause
[i
]
415 || p2
->clause
[i
] > p2
->clause
[i
+ 1]);
416 if (p
->clause
[i
] != p2
->clause
[i
])
419 return !p2
->clause
[i
];
425 static struct predicate
426 or_predicates (conditions conditions
, struct predicate
*p
, struct predicate
*p2
)
428 struct predicate out
= true_predicate ();
431 /* Avoid busy work. */
432 if (false_predicate_p (p2
) || true_predicate_p (p
))
434 if (false_predicate_p (p
) || true_predicate_p (p2
))
436 if (predicates_equal_p (p
, p2
))
439 /* OK, combine the predicates. */
440 for (i
= 0; p
->clause
[i
]; i
++)
441 for (j
= 0; p2
->clause
[j
]; j
++)
443 gcc_checking_assert (i
< MAX_CLAUSES
&& j
< MAX_CLAUSES
);
444 add_clause (conditions
, &out
, p
->clause
[i
] | p2
->clause
[j
]);
450 /* Having partial truth assignment in POSSIBLE_TRUTHS, return false
451 if predicate P is known to be false. */
454 evaluate_predicate (struct predicate
*p
, clause_t possible_truths
)
458 /* True remains true. */
459 if (true_predicate_p (p
))
462 gcc_assert (!(possible_truths
& (1 << predicate_false_condition
)));
464 /* See if we can find clause we can disprove. */
465 for (i
= 0; p
->clause
[i
]; i
++)
467 gcc_checking_assert (i
< MAX_CLAUSES
);
468 if (!(p
->clause
[i
] & possible_truths
))
474 /* Return the probability in range 0...REG_BR_PROB_BASE that the predicated
475 instruction will be recomputed per invocation of the inlined call. */
478 predicate_probability (conditions conds
,
479 struct predicate
*p
, clause_t possible_truths
,
480 vec
<inline_param_summary_t
> inline_param_summary
)
483 int combined_prob
= REG_BR_PROB_BASE
;
485 /* True remains true. */
486 if (true_predicate_p (p
))
487 return REG_BR_PROB_BASE
;
489 if (false_predicate_p (p
))
492 gcc_assert (!(possible_truths
& (1 << predicate_false_condition
)));
494 /* See if we can find clause we can disprove. */
495 for (i
= 0; p
->clause
[i
]; i
++)
497 gcc_checking_assert (i
< MAX_CLAUSES
);
498 if (!(p
->clause
[i
] & possible_truths
))
504 if (!inline_param_summary
.exists ())
505 return REG_BR_PROB_BASE
;
506 for (i2
= 0; i2
< NUM_CONDITIONS
; i2
++)
507 if ((p
->clause
[i
] & possible_truths
) & (1 << i2
))
509 if (i2
>= predicate_first_dynamic_condition
)
511 condition
*c
= &(*conds
)[i2
- predicate_first_dynamic_condition
];
512 if (c
->code
== CHANGED
514 < (int) inline_param_summary
.length ()))
516 int iprob
= inline_param_summary
[c
->operand_num
].change_prob
;
517 this_prob
= MAX (this_prob
, iprob
);
520 this_prob
= REG_BR_PROB_BASE
;
523 this_prob
= REG_BR_PROB_BASE
;
525 combined_prob
= MIN (this_prob
, combined_prob
);
530 return combined_prob
;
534 /* Dump conditional COND. */
537 dump_condition (FILE *f
, conditions conditions
, int cond
)
540 if (cond
== predicate_false_condition
)
541 fprintf (f
, "false");
542 else if (cond
== predicate_not_inlined_condition
)
543 fprintf (f
, "not inlined");
546 c
= &(*conditions
)[cond
- predicate_first_dynamic_condition
];
547 fprintf (f
, "op%i", c
->operand_num
);
549 fprintf (f
, "[%soffset: " HOST_WIDE_INT_PRINT_DEC
"]",
550 c
->by_ref
? "ref " : "", c
->offset
);
551 if (c
->code
== IS_NOT_CONSTANT
)
553 fprintf (f
, " not constant");
556 if (c
->code
== CHANGED
)
558 fprintf (f
, " changed");
561 fprintf (f
, " %s ", op_symbol_code (c
->code
));
562 print_generic_expr (f
, c
->val
, 1);
567 /* Dump clause CLAUSE. */
570 dump_clause (FILE *f
, conditions conds
, clause_t clause
)
577 for (i
= 0; i
< NUM_CONDITIONS
; i
++)
578 if (clause
& (1 << i
))
583 dump_condition (f
, conds
, i
);
589 /* Dump predicate PREDICATE. */
592 dump_predicate (FILE *f
, conditions conds
, struct predicate
*pred
)
595 if (true_predicate_p (pred
))
596 dump_clause (f
, conds
, 0);
598 for (i
= 0; pred
->clause
[i
]; i
++)
602 dump_clause (f
, conds
, pred
->clause
[i
]);
608 /* Dump inline hints. */
610 dump_inline_hints (FILE *f
, inline_hints hints
)
614 fprintf (f
, "inline hints:");
615 if (hints
& INLINE_HINT_indirect_call
)
617 hints
&= ~INLINE_HINT_indirect_call
;
618 fprintf (f
, " indirect_call");
620 if (hints
& INLINE_HINT_loop_iterations
)
622 hints
&= ~INLINE_HINT_loop_iterations
;
623 fprintf (f
, " loop_iterations");
625 if (hints
& INLINE_HINT_loop_stride
)
627 hints
&= ~INLINE_HINT_loop_stride
;
628 fprintf (f
, " loop_stride");
630 if (hints
& INLINE_HINT_same_scc
)
632 hints
&= ~INLINE_HINT_same_scc
;
633 fprintf (f
, " same_scc");
635 if (hints
& INLINE_HINT_in_scc
)
637 hints
&= ~INLINE_HINT_in_scc
;
638 fprintf (f
, " in_scc");
640 if (hints
& INLINE_HINT_cross_module
)
642 hints
&= ~INLINE_HINT_cross_module
;
643 fprintf (f
, " cross_module");
645 if (hints
& INLINE_HINT_declared_inline
)
647 hints
&= ~INLINE_HINT_declared_inline
;
648 fprintf (f
, " declared_inline");
650 if (hints
& INLINE_HINT_array_index
)
652 hints
&= ~INLINE_HINT_array_index
;
653 fprintf (f
, " array_index");
659 /* Record SIZE and TIME under condition PRED into the inline summary. */
662 account_size_time (struct inline_summary
*summary
, int size
, int time
,
663 struct predicate
*pred
)
669 if (false_predicate_p (pred
))
672 /* We need to create initial empty unconitional clause, but otherwie
673 we don't need to account empty times and sizes. */
674 if (!size
&& !time
&& summary
->entry
)
677 /* Watch overflow that might result from insane profiles. */
678 if (time
> MAX_TIME
* INLINE_TIME_SCALE
)
679 time
= MAX_TIME
* INLINE_TIME_SCALE
;
680 gcc_assert (time
>= 0);
682 for (i
= 0; vec_safe_iterate (summary
->entry
, i
, &e
); i
++)
683 if (predicates_equal_p (&e
->predicate
, pred
))
692 e
= &(*summary
->entry
)[0];
693 gcc_assert (!e
->predicate
.clause
[0]);
694 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
695 fprintf (dump_file
, "\t\tReached limit on number of entries, ignoring the predicate.");
697 if (dump_file
&& (dump_flags
& TDF_DETAILS
) && (time
|| size
))
699 fprintf (dump_file
, "\t\tAccounting size:%3.2f, time:%3.2f on %spredicate:",
700 ((double)size
) / INLINE_SIZE_SCALE
,
701 ((double)time
) / INLINE_TIME_SCALE
,
702 found
? "" : "new ");
703 dump_predicate (dump_file
, summary
->conds
, pred
);
707 struct size_time_entry new_entry
;
708 new_entry
.size
= size
;
709 new_entry
.time
= time
;
710 new_entry
.predicate
= *pred
;
711 vec_safe_push (summary
->entry
, new_entry
);
717 if (e
->time
> MAX_TIME
* INLINE_TIME_SCALE
)
718 e
->time
= MAX_TIME
* INLINE_TIME_SCALE
;
722 /* Set predicate for edge E. */
725 edge_set_predicate (struct cgraph_edge
*e
, struct predicate
*predicate
)
727 struct inline_edge_summary
*es
= inline_edge_summary (e
);
728 if (predicate
&& !true_predicate_p (predicate
))
731 es
->predicate
= (struct predicate
*)pool_alloc (edge_predicate_pool
);
732 *es
->predicate
= *predicate
;
737 pool_free (edge_predicate_pool
, es
->predicate
);
738 es
->predicate
= NULL
;
742 /* Set predicate for hint *P. */
745 set_hint_predicate (struct predicate
**p
, struct predicate new_predicate
)
747 if (false_predicate_p (&new_predicate
)
748 || true_predicate_p (&new_predicate
))
751 pool_free (edge_predicate_pool
, *p
);
757 *p
= (struct predicate
*)pool_alloc (edge_predicate_pool
);
763 /* KNOWN_VALS is partial mapping of parameters of NODE to constant values.
764 KNOWN_AGGS is a vector of aggreggate jump functions for each parameter.
765 Return clause of possible truths. When INLINE_P is true, assume that we are
768 ERROR_MARK means compile time invariant. */
771 evaluate_conditions_for_known_args (struct cgraph_node
*node
,
773 vec
<tree
> known_vals
,
774 vec
<ipa_agg_jump_function_p
> known_aggs
)
776 clause_t clause
= inline_p
? 0 : 1 << predicate_not_inlined_condition
;
777 struct inline_summary
*info
= inline_summary (node
);
781 for (i
= 0; vec_safe_iterate (info
->conds
, i
, &c
); i
++)
786 /* We allow call stmt to have fewer arguments than the callee function
787 (especially for K&R style programs). So bound check here (we assume
788 known_aggs vector, if non-NULL, has the same length as
790 gcc_checking_assert (!known_aggs
.exists ()
791 || (known_vals
.length () == known_aggs
.length ()));
792 if (c
->operand_num
>= (int) known_vals
.length ())
794 clause
|= 1 << (i
+ predicate_first_dynamic_condition
);
800 struct ipa_agg_jump_function
*agg
;
802 if (c
->code
== CHANGED
804 && (known_vals
[c
->operand_num
]
808 if (known_aggs
.exists ())
810 agg
= known_aggs
[c
->operand_num
];
811 val
= ipa_find_agg_cst_for_param (agg
, c
->offset
, c
->by_ref
);
818 val
= known_vals
[c
->operand_num
];
819 if (val
== error_mark_node
&& c
->code
!= CHANGED
)
825 clause
|= 1 << (i
+ predicate_first_dynamic_condition
);
828 if (c
->code
== IS_NOT_CONSTANT
|| c
->code
== CHANGED
)
830 res
= fold_binary_to_constant (c
->code
, boolean_type_node
, val
, c
->val
);
832 && integer_zerop (res
))
834 clause
|= 1 << (i
+ predicate_first_dynamic_condition
);
840 /* Work out what conditions might be true at invocation of E. */
843 evaluate_properties_for_edge (struct cgraph_edge
*e
, bool inline_p
,
844 clause_t
*clause_ptr
,
845 vec
<tree
> *known_vals_ptr
,
846 vec
<tree
> *known_binfos_ptr
,
847 vec
<ipa_agg_jump_function_p
> *known_aggs_ptr
)
849 struct cgraph_node
*callee
= cgraph_function_or_thunk_node (e
->callee
, NULL
);
850 struct inline_summary
*info
= inline_summary (callee
);
851 vec
<tree
> known_vals
= vec
<tree
>();
852 vec
<ipa_agg_jump_function_p
> known_aggs
853 = vec
<ipa_agg_jump_function_p
>();
856 *clause_ptr
= inline_p
? 0 : 1 << predicate_not_inlined_condition
;
858 known_vals_ptr
->create (0);
859 if (known_binfos_ptr
)
860 known_binfos_ptr
->create (0);
862 if (ipa_node_params_vector
.exists ()
863 && !e
->call_stmt_cannot_inline_p
864 && ((clause_ptr
&& info
->conds
)
865 || known_vals_ptr
|| known_binfos_ptr
))
867 struct ipa_node_params
*parms_info
;
868 struct ipa_edge_args
*args
= IPA_EDGE_REF (e
);
869 struct inline_edge_summary
*es
= inline_edge_summary (e
);
870 int i
, count
= ipa_get_cs_argument_count (args
);
872 if (e
->caller
->global
.inlined_to
)
873 parms_info
= IPA_NODE_REF (e
->caller
->global
.inlined_to
);
875 parms_info
= IPA_NODE_REF (e
->caller
);
877 if (count
&& (info
->conds
|| known_vals_ptr
))
878 known_vals
.safe_grow_cleared (count
);
879 if (count
&& (info
->conds
|| known_aggs_ptr
))
880 known_aggs
.safe_grow_cleared (count
);
881 if (count
&& known_binfos_ptr
)
882 known_binfos_ptr
->safe_grow_cleared (count
);
884 for (i
= 0; i
< count
; i
++)
886 struct ipa_jump_func
*jf
= ipa_get_ith_jump_func (args
, i
);
887 tree cst
= ipa_value_from_jfunc (parms_info
, jf
);
890 if (known_vals
.exists () && TREE_CODE (cst
) != TREE_BINFO
)
892 else if (known_binfos_ptr
!= NULL
&& TREE_CODE (cst
) == TREE_BINFO
)
893 (*known_binfos_ptr
)[i
] = cst
;
895 else if (inline_p
&& !es
->param
[i
].change_prob
)
896 known_vals
[i
] = error_mark_node
;
897 /* TODO: When IPA-CP starts propagating and merging aggregate jump
898 functions, use its knowledge of the caller too, just like the
899 scalar case above. */
900 known_aggs
[i
] = &jf
->agg
;
905 *clause_ptr
= evaluate_conditions_for_known_args (callee
, inline_p
,
906 known_vals
, known_aggs
);
909 *known_vals_ptr
= known_vals
;
911 known_vals
.release ();
914 *known_aggs_ptr
= known_aggs
;
916 known_aggs
.release ();
920 /* Allocate the inline summary vector or resize it to cover all cgraph nodes. */
923 inline_summary_alloc (void)
925 if (!node_removal_hook_holder
)
926 node_removal_hook_holder
=
927 cgraph_add_node_removal_hook (&inline_node_removal_hook
, NULL
);
928 if (!edge_removal_hook_holder
)
929 edge_removal_hook_holder
=
930 cgraph_add_edge_removal_hook (&inline_edge_removal_hook
, NULL
);
931 if (!node_duplication_hook_holder
)
932 node_duplication_hook_holder
=
933 cgraph_add_node_duplication_hook (&inline_node_duplication_hook
, NULL
);
934 if (!edge_duplication_hook_holder
)
935 edge_duplication_hook_holder
=
936 cgraph_add_edge_duplication_hook (&inline_edge_duplication_hook
, NULL
);
938 if (vec_safe_length (inline_summary_vec
) <= (unsigned) cgraph_max_uid
)
939 vec_safe_grow_cleared (inline_summary_vec
, cgraph_max_uid
+ 1);
940 if (inline_edge_summary_vec
.length () <= (unsigned) cgraph_edge_max_uid
)
941 inline_edge_summary_vec
.safe_grow_cleared (cgraph_edge_max_uid
+ 1);
942 if (!edge_predicate_pool
)
943 edge_predicate_pool
= create_alloc_pool ("edge predicates",
944 sizeof (struct predicate
),
948 /* We are called multiple time for given function; clear
949 data from previous run so they are not cumulated. */
952 reset_inline_edge_summary (struct cgraph_edge
*e
)
954 if (e
->uid
< (int)inline_edge_summary_vec
.length ())
956 struct inline_edge_summary
*es
= inline_edge_summary (e
);
958 es
->call_stmt_size
= es
->call_stmt_time
= 0;
960 pool_free (edge_predicate_pool
, es
->predicate
);
961 es
->predicate
= NULL
;
962 es
->param
.release ();
966 /* We are called multiple time for given function; clear
967 data from previous run so they are not cumulated. */
970 reset_inline_summary (struct cgraph_node
*node
)
972 struct inline_summary
*info
= inline_summary (node
);
973 struct cgraph_edge
*e
;
975 info
->self_size
= info
->self_time
= 0;
976 info
->estimated_stack_size
= 0;
977 info
->estimated_self_stack_size
= 0;
978 info
->stack_frame_offset
= 0;
983 if (info
->loop_iterations
)
985 pool_free (edge_predicate_pool
, info
->loop_iterations
);
986 info
->loop_iterations
= NULL
;
988 if (info
->loop_stride
)
990 pool_free (edge_predicate_pool
, info
->loop_stride
);
991 info
->loop_stride
= NULL
;
993 if (info
->array_index
)
995 pool_free (edge_predicate_pool
, info
->array_index
);
996 info
->array_index
= NULL
;
998 vec_free (info
->conds
);
999 vec_free (info
->entry
);
1000 for (e
= node
->callees
; e
; e
= e
->next_callee
)
1001 reset_inline_edge_summary (e
);
1002 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
1003 reset_inline_edge_summary (e
);
1006 /* Hook that is called by cgraph.c when a node is removed. */
1009 inline_node_removal_hook (struct cgraph_node
*node
, void *data ATTRIBUTE_UNUSED
)
1011 struct inline_summary
*info
;
1012 if (vec_safe_length (inline_summary_vec
) <= (unsigned)node
->uid
)
1014 info
= inline_summary (node
);
1015 reset_inline_summary (node
);
1016 memset (info
, 0, sizeof (inline_summary_t
));
1019 /* Remap predicate P of former function to be predicate of duplicated functoin.
1020 POSSIBLE_TRUTHS is clause of possible truths in the duplicated node,
1021 INFO is inline summary of the duplicated node. */
1023 static struct predicate
1024 remap_predicate_after_duplication (struct predicate
*p
,
1025 clause_t possible_truths
,
1026 struct inline_summary
*info
)
1028 struct predicate new_predicate
= true_predicate ();
1030 for (j
= 0; p
->clause
[j
]; j
++)
1031 if (!(possible_truths
& p
->clause
[j
]))
1033 new_predicate
= false_predicate ();
1037 add_clause (info
->conds
, &new_predicate
,
1038 possible_truths
& p
->clause
[j
]);
1039 return new_predicate
;
1042 /* Same as remap_predicate_after_duplication but handle hint predicate *P.
1043 Additionally care about allocating new memory slot for updated predicate
1044 and set it to NULL when it becomes true or false (and thus uninteresting).
1048 remap_hint_predicate_after_duplication (struct predicate
**p
,
1049 clause_t possible_truths
,
1050 struct inline_summary
*info
)
1052 struct predicate new_predicate
;
1057 new_predicate
= remap_predicate_after_duplication (*p
,
1060 /* We do not want to free previous predicate; it is used by node origin. */
1062 set_hint_predicate (p
, new_predicate
);
1066 /* Hook that is called by cgraph.c when a node is duplicated. */
1069 inline_node_duplication_hook (struct cgraph_node
*src
, struct cgraph_node
*dst
,
1070 ATTRIBUTE_UNUSED
void *data
)
1072 struct inline_summary
*info
;
1073 inline_summary_alloc ();
1074 info
= inline_summary (dst
);
1075 memcpy (info
, inline_summary (src
),
1076 sizeof (struct inline_summary
));
1077 /* TODO: as an optimization, we may avoid copying conditions
1078 that are known to be false or true. */
1079 info
->conds
= vec_safe_copy (info
->conds
);
1081 /* When there are any replacements in the function body, see if we can figure
1082 out that something was optimized out. */
1083 if (ipa_node_params_vector
.exists ()
1084 && dst
->clone
.tree_map
)
1086 vec
<size_time_entry
, va_gc
> *entry
= info
->entry
;
1087 /* Use SRC parm info since it may not be copied yet. */
1088 struct ipa_node_params
*parms_info
= IPA_NODE_REF (src
);
1089 vec
<tree
> known_vals
= vec
<tree
>();
1090 int count
= ipa_get_param_count (parms_info
);
1092 clause_t possible_truths
;
1093 struct predicate true_pred
= true_predicate ();
1095 int optimized_out_size
= 0;
1096 bool inlined_to_p
= false;
1097 struct cgraph_edge
*edge
;
1100 known_vals
.safe_grow_cleared (count
);
1101 for (i
= 0; i
< count
; i
++)
1103 tree t
= ipa_get_param (parms_info
, i
);
1104 struct ipa_replace_map
*r
;
1106 for (j
= 0; vec_safe_iterate (dst
->clone
.tree_map
, j
, &r
); j
++)
1108 if (r
->old_tree
== t
1112 known_vals
[i
] = r
->new_tree
;
1117 possible_truths
= evaluate_conditions_for_known_args (dst
, false,
1119 vec
<ipa_agg_jump_function_p
>());
1120 known_vals
.release ();
1122 account_size_time (info
, 0, 0, &true_pred
);
1124 /* Remap size_time vectors.
1125 Simplify the predicate by prunning out alternatives that are known
1127 TODO: as on optimization, we can also eliminate conditions known
1129 for (i
= 0; vec_safe_iterate (entry
, i
, &e
); i
++)
1131 struct predicate new_predicate
;
1132 new_predicate
= remap_predicate_after_duplication (&e
->predicate
,
1135 if (false_predicate_p (&new_predicate
))
1136 optimized_out_size
+= e
->size
;
1138 account_size_time (info
, e
->size
, e
->time
, &new_predicate
);
1141 /* Remap edge predicates with the same simplification as above.
1142 Also copy constantness arrays. */
1143 for (edge
= dst
->callees
; edge
; edge
= edge
->next_callee
)
1145 struct predicate new_predicate
;
1146 struct inline_edge_summary
*es
= inline_edge_summary (edge
);
1148 if (!edge
->inline_failed
)
1149 inlined_to_p
= true;
1152 new_predicate
= remap_predicate_after_duplication (es
->predicate
,
1155 if (false_predicate_p (&new_predicate
)
1156 && !false_predicate_p (es
->predicate
))
1158 optimized_out_size
+= es
->call_stmt_size
* INLINE_SIZE_SCALE
;
1159 edge
->frequency
= 0;
1161 edge_set_predicate (edge
, &new_predicate
);
1164 /* Remap indirect edge predicates with the same simplificaiton as above.
1165 Also copy constantness arrays. */
1166 for (edge
= dst
->indirect_calls
; edge
; edge
= edge
->next_callee
)
1168 struct predicate new_predicate
;
1169 struct inline_edge_summary
*es
= inline_edge_summary (edge
);
1171 gcc_checking_assert (edge
->inline_failed
);
1174 new_predicate
= remap_predicate_after_duplication (es
->predicate
,
1177 if (false_predicate_p (&new_predicate
)
1178 && !false_predicate_p (es
->predicate
))
1180 optimized_out_size
+= es
->call_stmt_size
* INLINE_SIZE_SCALE
;
1181 edge
->frequency
= 0;
1183 edge_set_predicate (edge
, &new_predicate
);
1185 remap_hint_predicate_after_duplication (&info
->loop_iterations
,
1188 remap_hint_predicate_after_duplication (&info
->loop_stride
,
1191 remap_hint_predicate_after_duplication (&info
->array_index
,
1195 /* If inliner or someone after inliner will ever start producing
1196 non-trivial clones, we will get trouble with lack of information
1197 about updating self sizes, because size vectors already contains
1198 sizes of the calees. */
1199 gcc_assert (!inlined_to_p
1200 || !optimized_out_size
);
1204 info
->entry
= vec_safe_copy (info
->entry
);
1205 if (info
->loop_iterations
)
1207 predicate p
= *info
->loop_iterations
;
1208 info
->loop_iterations
= NULL
;
1209 set_hint_predicate (&info
->loop_iterations
, p
);
1211 if (info
->loop_stride
)
1213 predicate p
= *info
->loop_stride
;
1214 info
->loop_stride
= NULL
;
1215 set_hint_predicate (&info
->loop_stride
, p
);
1217 if (info
->array_index
)
1219 predicate p
= *info
->array_index
;
1220 info
->array_index
= NULL
;
1221 set_hint_predicate (&info
->array_index
, p
);
1224 inline_update_overall_summary (dst
);
1228 /* Hook that is called by cgraph.c when a node is duplicated. */
1231 inline_edge_duplication_hook (struct cgraph_edge
*src
, struct cgraph_edge
*dst
,
1232 ATTRIBUTE_UNUSED
void *data
)
1234 struct inline_edge_summary
*info
;
1235 struct inline_edge_summary
*srcinfo
;
1236 inline_summary_alloc ();
1237 info
= inline_edge_summary (dst
);
1238 srcinfo
= inline_edge_summary (src
);
1239 memcpy (info
, srcinfo
,
1240 sizeof (struct inline_edge_summary
));
1241 info
->predicate
= NULL
;
1242 edge_set_predicate (dst
, srcinfo
->predicate
);
1243 info
->param
= srcinfo
->param
.copy ();
1247 /* Keep edge cache consistent across edge removal. */
1250 inline_edge_removal_hook (struct cgraph_edge
*edge
, void *data ATTRIBUTE_UNUSED
)
1252 if (edge_growth_cache
.exists ())
1253 reset_edge_growth_cache (edge
);
1254 reset_inline_edge_summary (edge
);
1258 /* Initialize growth caches. */
1261 initialize_growth_caches (void)
1263 if (cgraph_edge_max_uid
)
1264 edge_growth_cache
.safe_grow_cleared (cgraph_edge_max_uid
);
1266 node_growth_cache
.safe_grow_cleared (cgraph_max_uid
);
1270 /* Free growth caches. */
1273 free_growth_caches (void)
1275 edge_growth_cache
.release ();
1276 node_growth_cache
.release ();
1280 /* Dump edge summaries associated to NODE and recursively to all clones.
1281 Indent by INDENT. */
1284 dump_inline_edge_summary (FILE * f
, int indent
, struct cgraph_node
*node
,
1285 struct inline_summary
*info
)
1287 struct cgraph_edge
*edge
;
1288 for (edge
= node
->callees
; edge
; edge
= edge
->next_callee
)
1290 struct inline_edge_summary
*es
= inline_edge_summary (edge
);
1291 struct cgraph_node
*callee
= cgraph_function_or_thunk_node (edge
->callee
, NULL
);
1294 fprintf (f
, "%*s%s/%i %s\n%*s loop depth:%2i freq:%4i size:%2i time: %2i callee size:%2i stack:%2i",
1295 indent
, "", cgraph_node_name (callee
),
1297 !edge
->inline_failed
? "inlined"
1298 : cgraph_inline_failed_string (edge
->inline_failed
),
1304 (int)inline_summary (callee
)->size
/ INLINE_SIZE_SCALE
,
1305 (int)inline_summary (callee
)->estimated_stack_size
);
1309 fprintf (f
, " predicate: ");
1310 dump_predicate (f
, info
->conds
, es
->predicate
);
1314 if (es
->param
.exists ())
1315 for (i
= 0; i
< (int)es
->param
.length (); i
++)
1317 int prob
= es
->param
[i
].change_prob
;
1320 fprintf (f
, "%*s op%i is compile time invariant\n",
1322 else if (prob
!= REG_BR_PROB_BASE
)
1323 fprintf (f
, "%*s op%i change %f%% of time\n", indent
+ 2, "", i
,
1324 prob
* 100.0 / REG_BR_PROB_BASE
);
1326 if (!edge
->inline_failed
)
1328 fprintf (f
, "%*sStack frame offset %i, callee self size %i,"
1329 " callee size %i\n",
1331 (int)inline_summary (callee
)->stack_frame_offset
,
1332 (int)inline_summary (callee
)->estimated_self_stack_size
,
1333 (int)inline_summary (callee
)->estimated_stack_size
);
1334 dump_inline_edge_summary (f
, indent
+2, callee
, info
);
1337 for (edge
= node
->indirect_calls
; edge
; edge
= edge
->next_callee
)
1339 struct inline_edge_summary
*es
= inline_edge_summary (edge
);
1340 fprintf (f
, "%*sindirect call loop depth:%2i freq:%4i size:%2i"
1346 es
->call_stmt_time
);
1349 fprintf (f
, "predicate: ");
1350 dump_predicate (f
, info
->conds
, es
->predicate
);
1359 dump_inline_summary (FILE * f
, struct cgraph_node
*node
)
1363 struct inline_summary
*s
= inline_summary (node
);
1366 fprintf (f
, "Inline summary for %s/%i", cgraph_node_name (node
),
1368 if (DECL_DISREGARD_INLINE_LIMITS (node
->symbol
.decl
))
1369 fprintf (f
, " always_inline");
1371 fprintf (f
, " inlinable");
1372 fprintf (f
, "\n self time: %i\n",
1374 fprintf (f
, " global time: %i\n", s
->time
);
1375 fprintf (f
, " self size: %i\n",
1377 fprintf (f
, " global size: %i\n", s
->size
);
1378 fprintf (f
, " self stack: %i\n",
1379 (int) s
->estimated_self_stack_size
);
1380 fprintf (f
, " global stack: %i\n",
1381 (int) s
->estimated_stack_size
);
1383 fprintf (f
, " estimated growth:%i\n",
1386 fprintf (f
, " In SCC: %i\n",
1388 for (i
= 0; vec_safe_iterate (s
->entry
, i
, &e
); i
++)
1390 fprintf (f
, " size:%f, time:%f, predicate:",
1391 (double) e
->size
/ INLINE_SIZE_SCALE
,
1392 (double) e
->time
/ INLINE_TIME_SCALE
);
1393 dump_predicate (f
, s
->conds
, &e
->predicate
);
1395 if (s
->loop_iterations
)
1397 fprintf (f
, " loop iterations:");
1398 dump_predicate (f
, s
->conds
, s
->loop_iterations
);
1402 fprintf (f
, " loop stride:");
1403 dump_predicate (f
, s
->conds
, s
->loop_stride
);
1407 fprintf (f
, " array index:");
1408 dump_predicate (f
, s
->conds
, s
->array_index
);
1410 fprintf (f
, " calls:\n");
1411 dump_inline_edge_summary (f
, 4, node
, s
);
1417 debug_inline_summary (struct cgraph_node
*node
)
1419 dump_inline_summary (stderr
, node
);
1423 dump_inline_summaries (FILE *f
)
1425 struct cgraph_node
*node
;
1427 FOR_EACH_DEFINED_FUNCTION (node
)
1428 if (!node
->global
.inlined_to
)
1429 dump_inline_summary (f
, node
);
1432 /* Give initial reasons why inlining would fail on EDGE. This gets either
1433 nullified or usually overwritten by more precise reasons later. */
1436 initialize_inline_failed (struct cgraph_edge
*e
)
1438 struct cgraph_node
*callee
= e
->callee
;
1440 if (e
->indirect_unknown_callee
)
1441 e
->inline_failed
= CIF_INDIRECT_UNKNOWN_CALL
;
1442 else if (!callee
->analyzed
)
1443 e
->inline_failed
= CIF_BODY_NOT_AVAILABLE
;
1444 else if (callee
->local
.redefined_extern_inline
)
1445 e
->inline_failed
= CIF_REDEFINED_EXTERN_INLINE
;
1446 else if (e
->call_stmt_cannot_inline_p
)
1447 e
->inline_failed
= CIF_MISMATCHED_ARGUMENTS
;
1449 e
->inline_failed
= CIF_FUNCTION_NOT_CONSIDERED
;
1452 /* Callback of walk_aliased_vdefs. Flags that it has been invoked to the
1453 boolean variable pointed to by DATA. */
1456 mark_modified (ao_ref
*ao ATTRIBUTE_UNUSED
, tree vdef ATTRIBUTE_UNUSED
,
1459 bool *b
= (bool *) data
;
1464 /* If OP refers to value of function parameter, return the corresponding
1468 unmodified_parm_1 (gimple stmt
, tree op
)
1470 /* SSA_NAME referring to parm default def? */
1471 if (TREE_CODE (op
) == SSA_NAME
1472 && SSA_NAME_IS_DEFAULT_DEF (op
)
1473 && TREE_CODE (SSA_NAME_VAR (op
)) == PARM_DECL
)
1474 return SSA_NAME_VAR (op
);
1475 /* Non-SSA parm reference? */
1476 if (TREE_CODE (op
) == PARM_DECL
)
1478 bool modified
= false;
1481 ao_ref_init (&refd
, op
);
1482 walk_aliased_vdefs (&refd
, gimple_vuse (stmt
), mark_modified
, &modified
,
1490 /* If OP refers to value of function parameter, return the corresponding
1491 parameter. Also traverse chains of SSA register assignments. */
1494 unmodified_parm (gimple stmt
, tree op
)
1496 tree res
= unmodified_parm_1 (stmt
, op
);
1500 if (TREE_CODE (op
) == SSA_NAME
1501 && !SSA_NAME_IS_DEFAULT_DEF (op
)
1502 && gimple_assign_single_p (SSA_NAME_DEF_STMT (op
)))
1503 return unmodified_parm (SSA_NAME_DEF_STMT (op
),
1504 gimple_assign_rhs1 (SSA_NAME_DEF_STMT (op
)));
1508 /* If OP refers to a value of a function parameter or value loaded from an
1509 aggregate passed to a parameter (either by value or reference), return TRUE
1510 and store the number of the parameter to *INDEX_P and information whether
1511 and how it has been loaded from an aggregate into *AGGPOS. INFO describes
1512 the function parameters, STMT is the statement in which OP is used or
1516 unmodified_parm_or_parm_agg_item (struct ipa_node_params
*info
,
1517 gimple stmt
, tree op
, int *index_p
,
1518 struct agg_position_info
*aggpos
)
1520 tree res
= unmodified_parm_1 (stmt
, op
);
1522 gcc_checking_assert (aggpos
);
1525 *index_p
= ipa_get_param_decl_index (info
, res
);
1528 aggpos
->agg_contents
= false;
1529 aggpos
->by_ref
= false;
1533 if (TREE_CODE (op
) == SSA_NAME
)
1535 if (SSA_NAME_IS_DEFAULT_DEF (op
)
1536 || !gimple_assign_single_p (SSA_NAME_DEF_STMT (op
)))
1538 stmt
= SSA_NAME_DEF_STMT (op
);
1539 op
= gimple_assign_rhs1 (stmt
);
1540 if (!REFERENCE_CLASS_P (op
))
1541 return unmodified_parm_or_parm_agg_item (info
, stmt
, op
, index_p
,
1545 aggpos
->agg_contents
= true;
1546 return ipa_load_from_parm_agg (info
, stmt
, op
, index_p
, &aggpos
->offset
,
1550 /* See if statement might disappear after inlining.
1551 0 - means not eliminated
1552 1 - half of statements goes away
1553 2 - for sure it is eliminated.
1554 We are not terribly sophisticated, basically looking for simple abstraction
1555 penalty wrappers. */
1558 eliminated_by_inlining_prob (gimple stmt
)
1560 enum gimple_code code
= gimple_code (stmt
);
1561 enum tree_code rhs_code
;
1571 if (gimple_num_ops (stmt
) != 2)
1574 rhs_code
= gimple_assign_rhs_code (stmt
);
1576 /* Casts of parameters, loads from parameters passed by reference
1577 and stores to return value or parameters are often free after
1578 inlining dua to SRA and further combining.
1579 Assume that half of statements goes away. */
1580 if (rhs_code
== CONVERT_EXPR
1581 || rhs_code
== NOP_EXPR
1582 || rhs_code
== VIEW_CONVERT_EXPR
1583 || rhs_code
== ADDR_EXPR
1584 || gimple_assign_rhs_class (stmt
) == GIMPLE_SINGLE_RHS
)
1586 tree rhs
= gimple_assign_rhs1 (stmt
);
1587 tree lhs
= gimple_assign_lhs (stmt
);
1588 tree inner_rhs
= get_base_address (rhs
);
1589 tree inner_lhs
= get_base_address (lhs
);
1590 bool rhs_free
= false;
1591 bool lhs_free
= false;
1598 /* Reads of parameter are expected to be free. */
1599 if (unmodified_parm (stmt
, inner_rhs
))
1601 /* Match expressions of form &this->field. Those will most likely
1602 combine with something upstream after inlining. */
1603 else if (TREE_CODE (inner_rhs
) == ADDR_EXPR
)
1605 tree op
= get_base_address (TREE_OPERAND (inner_rhs
, 0));
1606 if (TREE_CODE (op
) == PARM_DECL
)
1608 else if (TREE_CODE (op
) == MEM_REF
1609 && unmodified_parm (stmt
, TREE_OPERAND (op
, 0)))
1613 /* When parameter is not SSA register because its address is taken
1614 and it is just copied into one, the statement will be completely
1615 free after inlining (we will copy propagate backward). */
1616 if (rhs_free
&& is_gimple_reg (lhs
))
1619 /* Reads of parameters passed by reference
1620 expected to be free (i.e. optimized out after inlining). */
1621 if (TREE_CODE(inner_rhs
) == MEM_REF
1622 && unmodified_parm (stmt
, TREE_OPERAND (inner_rhs
, 0)))
1625 /* Copying parameter passed by reference into gimple register is
1626 probably also going to copy propagate, but we can't be quite
1628 if (rhs_free
&& is_gimple_reg (lhs
))
1631 /* Writes to parameters, parameters passed by value and return value
1632 (either dirrectly or passed via invisible reference) are free.
1634 TODO: We ought to handle testcase like
1635 struct a {int a,b;};
1637 retrurnsturct (void)
1643 This translate into:
1658 For that we either need to copy ipa-split logic detecting writes
1660 if (TREE_CODE (inner_lhs
) == PARM_DECL
1661 || TREE_CODE (inner_lhs
) == RESULT_DECL
1662 || (TREE_CODE(inner_lhs
) == MEM_REF
1663 && (unmodified_parm (stmt
, TREE_OPERAND (inner_lhs
, 0))
1664 || (TREE_CODE (TREE_OPERAND (inner_lhs
, 0)) == SSA_NAME
1665 && SSA_NAME_VAR (TREE_OPERAND (inner_lhs
, 0))
1666 && TREE_CODE (SSA_NAME_VAR (TREE_OPERAND
1667 (inner_lhs
, 0))) == RESULT_DECL
))))
1670 && (is_gimple_reg (rhs
) || is_gimple_min_invariant (rhs
)))
1672 if (lhs_free
&& rhs_free
)
1682 /* If BB ends by a conditional we can turn into predicates, attach corresponding
1683 predicates to the CFG edges. */
1686 set_cond_stmt_execution_predicate (struct ipa_node_params
*info
,
1687 struct inline_summary
*summary
,
1693 struct agg_position_info aggpos
;
1694 enum tree_code code
, inverted_code
;
1700 last
= last_stmt (bb
);
1702 || gimple_code (last
) != GIMPLE_COND
)
1704 if (!is_gimple_ip_invariant (gimple_cond_rhs (last
)))
1706 op
= gimple_cond_lhs (last
);
1707 /* TODO: handle conditionals like
1710 if (unmodified_parm_or_parm_agg_item (info
, last
, op
, &index
, &aggpos
))
1712 code
= gimple_cond_code (last
);
1714 = invert_tree_comparison (code
,
1715 HONOR_NANS (TYPE_MODE (TREE_TYPE (op
))));
1717 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
1719 struct predicate p
= add_condition (summary
, index
, &aggpos
,
1720 e
->flags
& EDGE_TRUE_VALUE
1721 ? code
: inverted_code
,
1722 gimple_cond_rhs (last
));
1723 e
->aux
= pool_alloc (edge_predicate_pool
);
1724 *(struct predicate
*)e
->aux
= p
;
1728 if (TREE_CODE (op
) != SSA_NAME
)
1731 if (builtin_constant_p (op))
1735 Here we can predicate nonconstant_code. We can't
1736 really handle constant_code since we have no predicate
1737 for this and also the constant code is not known to be
1738 optimized away when inliner doen't see operand is constant.
1739 Other optimizers might think otherwise. */
1740 if (gimple_cond_code (last
) != NE_EXPR
1741 || !integer_zerop (gimple_cond_rhs (last
)))
1743 set_stmt
= SSA_NAME_DEF_STMT (op
);
1744 if (!gimple_call_builtin_p (set_stmt
, BUILT_IN_CONSTANT_P
)
1745 || gimple_call_num_args (set_stmt
) != 1)
1747 op2
= gimple_call_arg (set_stmt
, 0);
1748 if (!unmodified_parm_or_parm_agg_item (info
, set_stmt
, op2
, &index
, &aggpos
))
1750 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
1751 if (e
->flags
& EDGE_FALSE_VALUE
)
1753 struct predicate p
= add_condition (summary
, index
, &aggpos
,
1754 IS_NOT_CONSTANT
, NULL_TREE
);
1755 e
->aux
= pool_alloc (edge_predicate_pool
);
1756 *(struct predicate
*)e
->aux
= p
;
1761 /* If BB ends by a switch we can turn into predicates, attach corresponding
1762 predicates to the CFG edges. */
1765 set_switch_stmt_execution_predicate (struct ipa_node_params
*info
,
1766 struct inline_summary
*summary
,
1772 struct agg_position_info aggpos
;
1778 last
= last_stmt (bb
);
1780 || gimple_code (last
) != GIMPLE_SWITCH
)
1782 op
= gimple_switch_index (last
);
1783 if (!unmodified_parm_or_parm_agg_item (info
, last
, op
, &index
, &aggpos
))
1786 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
1788 e
->aux
= pool_alloc (edge_predicate_pool
);
1789 *(struct predicate
*)e
->aux
= false_predicate ();
1791 n
= gimple_switch_num_labels(last
);
1792 for (case_idx
= 0; case_idx
< n
; ++case_idx
)
1794 tree cl
= gimple_switch_label (last
, case_idx
);
1798 e
= find_edge (bb
, label_to_block (CASE_LABEL (cl
)));
1799 min
= CASE_LOW (cl
);
1800 max
= CASE_HIGH (cl
);
1802 /* For default we might want to construct predicate that none
1803 of cases is met, but it is bit hard to do not having negations
1804 of conditionals handy. */
1806 p
= true_predicate ();
1808 p
= add_condition (summary
, index
, &aggpos
, EQ_EXPR
, min
);
1811 struct predicate p1
, p2
;
1812 p1
= add_condition (summary
, index
, &aggpos
, GE_EXPR
, min
);
1813 p2
= add_condition (summary
, index
, &aggpos
, LE_EXPR
, max
);
1814 p
= and_predicates (summary
->conds
, &p1
, &p2
);
1816 *(struct predicate
*)e
->aux
1817 = or_predicates (summary
->conds
, &p
, (struct predicate
*)e
->aux
);
1822 /* For each BB in NODE attach to its AUX pointer predicate under
1823 which it is executable. */
1826 compute_bb_predicates (struct cgraph_node
*node
,
1827 struct ipa_node_params
*parms_info
,
1828 struct inline_summary
*summary
)
1830 struct function
*my_function
= DECL_STRUCT_FUNCTION (node
->symbol
.decl
);
1834 FOR_EACH_BB_FN (bb
, my_function
)
1836 set_cond_stmt_execution_predicate (parms_info
, summary
, bb
);
1837 set_switch_stmt_execution_predicate (parms_info
, summary
, bb
);
1840 /* Entry block is always executable. */
1841 ENTRY_BLOCK_PTR_FOR_FUNCTION (my_function
)->aux
1842 = pool_alloc (edge_predicate_pool
);
1843 *(struct predicate
*)ENTRY_BLOCK_PTR_FOR_FUNCTION (my_function
)->aux
1844 = true_predicate ();
1846 /* A simple dataflow propagation of predicates forward in the CFG.
1847 TODO: work in reverse postorder. */
1851 FOR_EACH_BB_FN (bb
, my_function
)
1853 struct predicate p
= false_predicate ();
1856 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
1860 struct predicate this_bb_predicate
1861 = *(struct predicate
*)e
->src
->aux
;
1864 = and_predicates (summary
->conds
, &this_bb_predicate
,
1865 (struct predicate
*)e
->aux
);
1866 p
= or_predicates (summary
->conds
, &p
, &this_bb_predicate
);
1867 if (true_predicate_p (&p
))
1871 if (false_predicate_p (&p
))
1872 gcc_assert (!bb
->aux
);
1878 bb
->aux
= pool_alloc (edge_predicate_pool
);
1879 *((struct predicate
*)bb
->aux
) = p
;
1881 else if (!predicates_equal_p (&p
, (struct predicate
*)bb
->aux
))
1884 *((struct predicate
*)bb
->aux
) = p
;
1892 /* We keep info about constantness of SSA names. */
1894 typedef struct predicate predicate_t
;
1895 /* Return predicate specifying when the STMT might have result that is not
1896 a compile time constant. */
1898 static struct predicate
1899 will_be_nonconstant_expr_predicate (struct ipa_node_params
*info
,
1900 struct inline_summary
*summary
,
1902 vec
<predicate_t
> nonconstant_names
)
1907 while (UNARY_CLASS_P (expr
))
1908 expr
= TREE_OPERAND (expr
, 0);
1910 parm
= unmodified_parm (NULL
, expr
);
1912 && (index
= ipa_get_param_decl_index (info
, parm
)) >= 0)
1913 return add_condition (summary
, index
, NULL
, CHANGED
, NULL_TREE
);
1914 if (is_gimple_min_invariant (expr
))
1915 return false_predicate ();
1916 if (TREE_CODE (expr
) == SSA_NAME
)
1917 return nonconstant_names
[SSA_NAME_VERSION (expr
)];
1918 if (BINARY_CLASS_P (expr
)
1919 || COMPARISON_CLASS_P (expr
))
1921 struct predicate p1
= will_be_nonconstant_expr_predicate
1922 (info
, summary
, TREE_OPERAND (expr
, 0),
1924 struct predicate p2
;
1925 if (true_predicate_p (&p1
))
1927 p2
= will_be_nonconstant_expr_predicate (info
, summary
,
1928 TREE_OPERAND (expr
, 1),
1930 return or_predicates (summary
->conds
, &p1
, &p2
);
1932 else if (TREE_CODE (expr
) == COND_EXPR
)
1934 struct predicate p1
= will_be_nonconstant_expr_predicate
1935 (info
, summary
, TREE_OPERAND (expr
, 0),
1937 struct predicate p2
;
1938 if (true_predicate_p (&p1
))
1940 p2
= will_be_nonconstant_expr_predicate (info
, summary
,
1941 TREE_OPERAND (expr
, 1),
1943 if (true_predicate_p (&p2
))
1945 p1
= or_predicates (summary
->conds
, &p1
, &p2
);
1946 p2
= will_be_nonconstant_expr_predicate (info
, summary
,
1947 TREE_OPERAND (expr
, 2),
1949 return or_predicates (summary
->conds
, &p1
, &p2
);
1956 return false_predicate ();
1960 /* Return predicate specifying when the STMT might have result that is not
1961 a compile time constant. */
1963 static struct predicate
1964 will_be_nonconstant_predicate (struct ipa_node_params
*info
,
1965 struct inline_summary
*summary
,
1967 vec
<predicate_t
> nonconstant_names
)
1969 struct predicate p
= true_predicate ();
1972 struct predicate op_non_const
;
1975 struct agg_position_info aggpos
;
1977 /* What statments might be optimized away
1978 when their arguments are constant
1979 TODO: also trivial builtins.
1980 builtin_constant_p is already handled later. */
1981 if (gimple_code (stmt
) != GIMPLE_ASSIGN
1982 && gimple_code (stmt
) != GIMPLE_COND
1983 && gimple_code (stmt
) != GIMPLE_SWITCH
)
1986 /* Stores will stay anyway. */
1987 if (gimple_store_p (stmt
))
1990 is_load
= gimple_assign_load_p (stmt
);
1992 /* Loads can be optimized when the value is known. */
1996 gcc_assert (gimple_assign_single_p (stmt
));
1997 op
= gimple_assign_rhs1 (stmt
);
1998 if (!unmodified_parm_or_parm_agg_item (info
, stmt
, op
, &base_index
,
2005 /* See if we understand all operands before we start
2006 adding conditionals. */
2007 FOR_EACH_SSA_TREE_OPERAND (use
, stmt
, iter
, SSA_OP_USE
)
2009 tree parm
= unmodified_parm (stmt
, use
);
2010 /* For arguments we can build a condition. */
2011 if (parm
&& ipa_get_param_decl_index (info
, parm
) >= 0)
2013 if (TREE_CODE (use
) != SSA_NAME
)
2015 /* If we know when operand is constant,
2016 we still can say something useful. */
2017 if (!true_predicate_p (&nonconstant_names
[SSA_NAME_VERSION (use
)]))
2023 op_non_const
= add_condition (summary
, base_index
, &aggpos
, CHANGED
, NULL
);
2025 op_non_const
= false_predicate ();
2026 FOR_EACH_SSA_TREE_OPERAND (use
, stmt
, iter
, SSA_OP_USE
)
2028 tree parm
= unmodified_parm (stmt
, use
);
2032 && (index
= ipa_get_param_decl_index (info
, parm
)) >= 0)
2034 if (index
!= base_index
)
2035 p
= add_condition (summary
, index
, NULL
, CHANGED
, NULL_TREE
);
2040 p
= nonconstant_names
[SSA_NAME_VERSION (use
)];
2041 op_non_const
= or_predicates (summary
->conds
, &p
, &op_non_const
);
2043 if (gimple_code (stmt
) == GIMPLE_ASSIGN
2044 && TREE_CODE (gimple_assign_lhs (stmt
)) == SSA_NAME
)
2045 nonconstant_names
[SSA_NAME_VERSION (gimple_assign_lhs (stmt
))]
2047 return op_non_const
;
2050 struct record_modified_bb_info
2056 /* Callback of walk_aliased_vdefs. Records basic blocks where the value may be
2057 set except for info->stmt. */
2060 record_modified (ao_ref
*ao ATTRIBUTE_UNUSED
, tree vdef
,
2063 struct record_modified_bb_info
*info
= (struct record_modified_bb_info
*) data
;
2064 if (SSA_NAME_DEF_STMT (vdef
) == info
->stmt
)
2066 bitmap_set_bit (info
->bb_set
,
2067 SSA_NAME_IS_DEFAULT_DEF (vdef
)
2068 ? ENTRY_BLOCK_PTR
->index
: gimple_bb (SSA_NAME_DEF_STMT (vdef
))->index
);
2072 /* Return probability (based on REG_BR_PROB_BASE) that I-th parameter of STMT
2073 will change since last invocation of STMT.
2075 Value 0 is reserved for compile time invariants.
2076 For common parameters it is REG_BR_PROB_BASE. For loop invariants it
2077 ought to be REG_BR_PROB_BASE / estimated_iters. */
2080 param_change_prob (gimple stmt
, int i
)
2082 tree op
= gimple_call_arg (stmt
, i
);
2083 basic_block bb
= gimple_bb (stmt
);
2086 if (is_gimple_min_invariant (op
))
2088 /* We would have to do non-trivial analysis to really work out what
2089 is the probability of value to change (i.e. when init statement
2090 is in a sibling loop of the call).
2092 We do an conservative estimate: when call is executed N times more often
2093 than the statement defining value, we take the frequency 1/N. */
2094 if (TREE_CODE (op
) == SSA_NAME
)
2099 return REG_BR_PROB_BASE
;
2101 if (SSA_NAME_IS_DEFAULT_DEF (op
))
2102 init_freq
= ENTRY_BLOCK_PTR
->frequency
;
2104 init_freq
= gimple_bb (SSA_NAME_DEF_STMT (op
))->frequency
;
2108 if (init_freq
< bb
->frequency
)
2109 return MAX ((init_freq
* REG_BR_PROB_BASE
+
2110 bb
->frequency
/ 2) / bb
->frequency
, 1);
2112 return REG_BR_PROB_BASE
;
2115 base
= get_base_address (op
);
2120 struct record_modified_bb_info info
;
2124 if (const_value_known_p (base
))
2127 return REG_BR_PROB_BASE
;
2128 ao_ref_init (&refd
, op
);
2130 info
.bb_set
= BITMAP_ALLOC (NULL
);
2131 walk_aliased_vdefs (&refd
, gimple_vuse (stmt
), record_modified
, &info
,
2133 if (bitmap_bit_p (info
.bb_set
, bb
->index
))
2135 BITMAP_FREE (info
.bb_set
);
2136 return REG_BR_PROB_BASE
;
2139 /* Assume that every memory is initialized at entry.
2140 TODO: Can we easilly determine if value is always defined
2141 and thus we may skip entry block? */
2142 if (ENTRY_BLOCK_PTR
->frequency
)
2143 max
= ENTRY_BLOCK_PTR
->frequency
;
2147 EXECUTE_IF_SET_IN_BITMAP (info
.bb_set
, 0, index
, bi
)
2148 max
= MIN (max
, BASIC_BLOCK (index
)->frequency
);
2150 BITMAP_FREE (info
.bb_set
);
2151 if (max
< bb
->frequency
)
2152 return MAX ((max
* REG_BR_PROB_BASE
+
2153 bb
->frequency
/ 2) / bb
->frequency
, 1);
2155 return REG_BR_PROB_BASE
;
2157 return REG_BR_PROB_BASE
;
2160 /* Find whether a basic block BB is the final block of a (half) diamond CFG
2161 sub-graph and if the predicate the condition depends on is known. If so,
2162 return true and store the pointer the predicate in *P. */
2165 phi_result_unknown_predicate (struct ipa_node_params
*info
,
2166 struct inline_summary
*summary
, basic_block bb
,
2167 struct predicate
*p
,
2168 vec
<predicate_t
> nonconstant_names
)
2172 basic_block first_bb
= NULL
;
2175 if (single_pred_p (bb
))
2177 *p
= false_predicate ();
2181 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
2183 if (single_succ_p (e
->src
))
2185 if (!single_pred_p (e
->src
))
2188 first_bb
= single_pred (e
->src
);
2189 else if (single_pred (e
->src
) != first_bb
)
2196 else if (e
->src
!= first_bb
)
2204 stmt
= last_stmt (first_bb
);
2206 || gimple_code (stmt
) != GIMPLE_COND
2207 || !is_gimple_ip_invariant (gimple_cond_rhs (stmt
)))
2210 *p
= will_be_nonconstant_expr_predicate (info
, summary
,
2211 gimple_cond_lhs (stmt
),
2213 if (true_predicate_p (p
))
2219 /* Given a PHI statement in a function described by inline properties SUMMARY
2220 and *P being the predicate describing whether the selected PHI argument is
2221 known, store a predicate for the result of the PHI statement into
2222 NONCONSTANT_NAMES, if possible. */
2225 predicate_for_phi_result (struct inline_summary
*summary
, gimple phi
,
2226 struct predicate
*p
,
2227 vec
<predicate_t
> nonconstant_names
)
2231 for (i
= 0; i
< gimple_phi_num_args (phi
); i
++)
2233 tree arg
= gimple_phi_arg (phi
, i
)->def
;
2234 if (!is_gimple_min_invariant (arg
))
2236 gcc_assert (TREE_CODE (arg
) == SSA_NAME
);
2237 *p
= or_predicates (summary
->conds
, p
,
2238 &nonconstant_names
[SSA_NAME_VERSION (arg
)]);
2239 if (true_predicate_p (p
))
2244 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
2246 fprintf (dump_file
, "\t\tphi predicate: ");
2247 dump_predicate (dump_file
, summary
->conds
, p
);
2249 nonconstant_names
[SSA_NAME_VERSION (gimple_phi_result (phi
))] = *p
;
2252 /* Return predicate specifying when array index in access OP becomes non-constant. */
2254 static struct predicate
2255 array_index_predicate (struct inline_summary
*info
,
2256 vec
<predicate_t
> nonconstant_names
, tree op
)
2258 struct predicate p
= false_predicate ();
2259 while (handled_component_p (op
))
2261 if (TREE_CODE (op
) == ARRAY_REF
2262 || TREE_CODE (op
) == ARRAY_RANGE_REF
)
2264 if (TREE_CODE (TREE_OPERAND (op
, 1)) == SSA_NAME
)
2265 p
= or_predicates (info
->conds
, &p
,
2267 SSA_NAME_VERSION (TREE_OPERAND (op
, 1))]);
2269 op
= TREE_OPERAND (op
, 0);
2274 /* Compute function body size parameters for NODE.
2275 When EARLY is true, we compute only simple summaries without
2276 non-trivial predicates to drive the early inliner. */
2279 estimate_function_body_sizes (struct cgraph_node
*node
, bool early
)
2282 /* Estimate static overhead for function prologue/epilogue and alignment. */
2284 /* Benefits are scaled by probability of elimination that is in range
2287 gimple_stmt_iterator bsi
;
2288 struct function
*my_function
= DECL_STRUCT_FUNCTION (node
->symbol
.decl
);
2290 struct inline_summary
*info
= inline_summary (node
);
2291 struct predicate bb_predicate
;
2292 struct ipa_node_params
*parms_info
= NULL
;
2293 vec
<predicate_t
> nonconstant_names
= vec
<predicate_t
>();
2296 predicate array_index
= true_predicate ();
2301 if (optimize
&& !early
)
2303 calculate_dominance_info (CDI_DOMINATORS
);
2304 loop_optimizer_init (LOOPS_NORMAL
| LOOPS_HAVE_RECORDED_EXITS
);
2306 if (ipa_node_params_vector
.exists ())
2308 parms_info
= IPA_NODE_REF (node
);
2309 nonconstant_names
.safe_grow_cleared(SSANAMES (my_function
)->length());
2314 fprintf (dump_file
, "\nAnalyzing function body size: %s\n",
2315 cgraph_node_name (node
));
2317 /* When we run into maximal number of entries, we assign everything to the
2318 constant truth case. Be sure to have it in list. */
2319 bb_predicate
= true_predicate ();
2320 account_size_time (info
, 0, 0, &bb_predicate
);
2322 bb_predicate
= not_inlined_predicate ();
2323 account_size_time (info
, 2 * INLINE_SIZE_SCALE
, 0, &bb_predicate
);
2325 gcc_assert (my_function
&& my_function
->cfg
);
2327 compute_bb_predicates (node
, parms_info
, info
);
2328 gcc_assert (cfun
== my_function
);
2329 order
= XNEWVEC (int, n_basic_blocks
);
2330 nblocks
= pre_and_rev_post_order_compute (NULL
, order
, false);
2331 for (n
= 0; n
< nblocks
; n
++)
2333 bb
= BASIC_BLOCK (order
[n
]);
2334 freq
= compute_call_stmt_bb_frequency (node
->symbol
.decl
, bb
);
2336 /* TODO: Obviously predicates can be propagated down across CFG. */
2340 bb_predicate
= *(struct predicate
*)bb
->aux
;
2342 bb_predicate
= false_predicate ();
2345 bb_predicate
= true_predicate ();
2347 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
2349 fprintf (dump_file
, "\n BB %i predicate:", bb
->index
);
2350 dump_predicate (dump_file
, info
->conds
, &bb_predicate
);
2353 if (parms_info
&& nonconstant_names
.exists ())
2355 struct predicate phi_predicate
;
2356 bool first_phi
= true;
2358 for (bsi
= gsi_start_phis (bb
); !gsi_end_p (bsi
); gsi_next (&bsi
))
2361 && !phi_result_unknown_predicate (parms_info
, info
, bb
,
2366 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
2368 fprintf (dump_file
, " ");
2369 print_gimple_stmt (dump_file
, gsi_stmt (bsi
), 0, 0);
2371 predicate_for_phi_result (info
, gsi_stmt (bsi
), &phi_predicate
,
2376 for (bsi
= gsi_start_bb (bb
); !gsi_end_p (bsi
); gsi_next (&bsi
))
2378 gimple stmt
= gsi_stmt (bsi
);
2379 int this_size
= estimate_num_insns (stmt
, &eni_size_weights
);
2380 int this_time
= estimate_num_insns (stmt
, &eni_time_weights
);
2382 struct predicate will_be_nonconstant
;
2384 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
2386 fprintf (dump_file
, " ");
2387 print_gimple_stmt (dump_file
, stmt
, 0, 0);
2388 fprintf (dump_file
, "\t\tfreq:%3.2f size:%3i time:%3i\n",
2389 ((double)freq
)/CGRAPH_FREQ_BASE
, this_size
, this_time
);
2392 if (gimple_assign_load_p (stmt
) && nonconstant_names
.exists ())
2394 struct predicate this_array_index
;
2395 this_array_index
= array_index_predicate (info
, nonconstant_names
,
2396 gimple_assign_rhs1 (stmt
));
2397 if (!false_predicate_p (&this_array_index
))
2398 array_index
= and_predicates (info
->conds
, &array_index
, &this_array_index
);
2400 if (gimple_store_p (stmt
) && nonconstant_names
.exists ())
2402 struct predicate this_array_index
;
2403 this_array_index
= array_index_predicate (info
, nonconstant_names
,
2404 gimple_get_lhs (stmt
));
2405 if (!false_predicate_p (&this_array_index
))
2406 array_index
= and_predicates (info
->conds
, &array_index
, &this_array_index
);
2410 if (is_gimple_call (stmt
))
2412 struct cgraph_edge
*edge
= cgraph_edge (node
, stmt
);
2413 struct inline_edge_summary
*es
= inline_edge_summary (edge
);
2415 /* Special case: results of BUILT_IN_CONSTANT_P will be always
2416 resolved as constant. We however don't want to optimize
2417 out the cgraph edges. */
2418 if (nonconstant_names
.exists ()
2419 && gimple_call_builtin_p (stmt
, BUILT_IN_CONSTANT_P
)
2420 && gimple_call_lhs (stmt
)
2421 && TREE_CODE (gimple_call_lhs (stmt
)) == SSA_NAME
)
2423 struct predicate false_p
= false_predicate ();
2424 nonconstant_names
[SSA_NAME_VERSION (gimple_call_lhs (stmt
))]
2427 if (ipa_node_params_vector
.exists ())
2429 int count
= gimple_call_num_args (stmt
);
2433 es
->param
.safe_grow_cleared (count
);
2434 for (i
= 0; i
< count
; i
++)
2436 int prob
= param_change_prob (stmt
, i
);
2437 gcc_assert (prob
>= 0 && prob
<= REG_BR_PROB_BASE
);
2438 es
->param
[i
].change_prob
= prob
;
2442 es
->call_stmt_size
= this_size
;
2443 es
->call_stmt_time
= this_time
;
2444 es
->loop_depth
= bb_loop_depth (bb
);
2445 edge_set_predicate (edge
, &bb_predicate
);
2448 /* TODO: When conditional jump or swithc is known to be constant, but
2449 we did not translate it into the predicates, we really can account
2450 just maximum of the possible paths. */
2453 = will_be_nonconstant_predicate (parms_info
, info
,
2454 stmt
, nonconstant_names
);
2455 if (this_time
|| this_size
)
2461 prob
= eliminated_by_inlining_prob (stmt
);
2462 if (prob
== 1 && dump_file
&& (dump_flags
& TDF_DETAILS
))
2463 fprintf (dump_file
, "\t\t50%% will be eliminated by inlining\n");
2464 if (prob
== 2 && dump_file
&& (dump_flags
& TDF_DETAILS
))
2465 fprintf (dump_file
, "\t\tWill be eliminated by inlining\n");
2468 p
= and_predicates (info
->conds
, &bb_predicate
,
2469 &will_be_nonconstant
);
2471 p
= true_predicate ();
2473 if (!false_predicate_p (&p
))
2477 if (time
> MAX_TIME
* INLINE_TIME_SCALE
)
2478 time
= MAX_TIME
* INLINE_TIME_SCALE
;
2481 /* We account everything but the calls. Calls have their own
2482 size/time info attached to cgraph edges. This is necessary
2483 in order to make the cost disappear after inlining. */
2484 if (!is_gimple_call (stmt
))
2488 struct predicate ip
= not_inlined_predicate ();
2489 ip
= and_predicates (info
->conds
, &ip
, &p
);
2490 account_size_time (info
, this_size
* prob
,
2491 this_time
* prob
, &ip
);
2494 account_size_time (info
, this_size
* (2 - prob
),
2495 this_time
* (2 - prob
), &p
);
2498 gcc_assert (time
>= 0);
2499 gcc_assert (size
>= 0);
2503 set_hint_predicate (&inline_summary (node
)->array_index
, array_index
);
2504 time
= (time
+ CGRAPH_FREQ_BASE
/ 2) / CGRAPH_FREQ_BASE
;
2505 if (time
> MAX_TIME
)
2509 if (!early
&& nonconstant_names
.exists ())
2513 predicate loop_iterations
= true_predicate ();
2514 predicate loop_stride
= true_predicate ();
2516 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
2517 flow_loops_dump (dump_file
, NULL
, 0);
2519 FOR_EACH_LOOP (li
, loop
, 0)
2524 struct tree_niter_desc niter_desc
;
2525 basic_block
*body
= get_loop_body (loop
);
2526 bb_predicate
= *(struct predicate
*)loop
->header
->aux
;
2528 exits
= get_loop_exit_edges (loop
);
2529 FOR_EACH_VEC_ELT (exits
, j
, ex
)
2530 if (number_of_iterations_exit (loop
, ex
, &niter_desc
, false)
2531 && !is_gimple_min_invariant (niter_desc
.niter
))
2533 predicate will_be_nonconstant
2534 = will_be_nonconstant_expr_predicate (parms_info
, info
,
2535 niter_desc
.niter
, nonconstant_names
);
2536 if (!true_predicate_p (&will_be_nonconstant
))
2537 will_be_nonconstant
= and_predicates (info
->conds
,
2539 &will_be_nonconstant
);
2540 if (!true_predicate_p (&will_be_nonconstant
)
2541 && !false_predicate_p (&will_be_nonconstant
))
2542 /* This is slightly inprecise. We may want to represent each loop with
2543 independent predicate. */
2544 loop_iterations
= and_predicates (info
->conds
, &loop_iterations
, &will_be_nonconstant
);
2548 for (i
= 0; i
< loop
->num_nodes
; i
++)
2550 gimple_stmt_iterator gsi
;
2551 bb_predicate
= *(struct predicate
*)body
[i
]->aux
;
2552 for (gsi
= gsi_start_bb (body
[i
]); !gsi_end_p (gsi
); gsi_next (&gsi
))
2554 gimple stmt
= gsi_stmt (gsi
);
2559 FOR_EACH_SSA_TREE_OPERAND (use
, stmt
, iter
, SSA_OP_USE
)
2561 predicate will_be_nonconstant
;
2563 if (!simple_iv (loop
, loop_containing_stmt (stmt
), use
, &iv
, true)
2564 || is_gimple_min_invariant (iv
.step
))
2567 = will_be_nonconstant_expr_predicate (parms_info
, info
,
2568 iv
.step
, nonconstant_names
);
2569 if (!true_predicate_p (&will_be_nonconstant
))
2570 will_be_nonconstant
= and_predicates (info
->conds
,
2572 &will_be_nonconstant
);
2573 if (!true_predicate_p (&will_be_nonconstant
)
2574 && !false_predicate_p (&will_be_nonconstant
))
2575 /* This is slightly inprecise. We may want to represent each loop with
2576 independent predicate. */
2577 loop_stride
= and_predicates (info
->conds
, &loop_stride
, &will_be_nonconstant
);
2583 set_hint_predicate (&inline_summary (node
)->loop_iterations
, loop_iterations
);
2584 set_hint_predicate (&inline_summary (node
)->loop_stride
, loop_stride
);
2587 FOR_ALL_BB_FN (bb
, my_function
)
2593 pool_free (edge_predicate_pool
, bb
->aux
);
2595 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
2598 pool_free (edge_predicate_pool
, e
->aux
);
2602 inline_summary (node
)->self_time
= time
;
2603 inline_summary (node
)->self_size
= size
;
2604 nonconstant_names
.release ();
2605 if (optimize
&& !early
)
2607 loop_optimizer_finalize ();
2608 free_dominance_info (CDI_DOMINATORS
);
2612 fprintf (dump_file
, "\n");
2613 dump_inline_summary (dump_file
, node
);
2618 /* Compute parameters of functions used by inliner.
2619 EARLY is true when we compute parameters for the early inliner */
2622 compute_inline_parameters (struct cgraph_node
*node
, bool early
)
2624 HOST_WIDE_INT self_stack_size
;
2625 struct cgraph_edge
*e
;
2626 struct inline_summary
*info
;
2628 gcc_assert (!node
->global
.inlined_to
);
2630 inline_summary_alloc ();
2632 info
= inline_summary (node
);
2633 reset_inline_summary (node
);
2635 /* FIXME: Thunks are inlinable, but tree-inline don't know how to do that.
2636 Once this happen, we will need to more curefully predict call
2638 if (node
->thunk
.thunk_p
)
2640 struct inline_edge_summary
*es
= inline_edge_summary (node
->callees
);
2641 struct predicate t
= true_predicate ();
2643 info
->inlinable
= 0;
2644 node
->callees
->call_stmt_cannot_inline_p
= true;
2645 node
->local
.can_change_signature
= false;
2646 es
->call_stmt_time
= 1;
2647 es
->call_stmt_size
= 1;
2648 account_size_time (info
, 0, 0, &t
);
2652 /* Even is_gimple_min_invariant rely on current_function_decl. */
2653 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
2655 /* Estimate the stack size for the function if we're optimizing. */
2656 self_stack_size
= optimize
? estimated_stack_frame_size (node
) : 0;
2657 info
->estimated_self_stack_size
= self_stack_size
;
2658 info
->estimated_stack_size
= self_stack_size
;
2659 info
->stack_frame_offset
= 0;
2661 /* Can this function be inlined at all? */
2662 info
->inlinable
= tree_inlinable_function_p (node
->symbol
.decl
);
2664 /* Type attributes can use parameter indices to describe them. */
2665 if (TYPE_ATTRIBUTES (TREE_TYPE (node
->symbol
.decl
)))
2666 node
->local
.can_change_signature
= false;
2669 /* Otherwise, inlinable functions always can change signature. */
2670 if (info
->inlinable
)
2671 node
->local
.can_change_signature
= true;
2674 /* Functions calling builtin_apply can not change signature. */
2675 for (e
= node
->callees
; e
; e
= e
->next_callee
)
2677 tree
cdecl = e
->callee
->symbol
.decl
;
2678 if (DECL_BUILT_IN (cdecl)
2679 && DECL_BUILT_IN_CLASS (cdecl) == BUILT_IN_NORMAL
2680 && (DECL_FUNCTION_CODE (cdecl) == BUILT_IN_APPLY_ARGS
2681 || DECL_FUNCTION_CODE (cdecl) == BUILT_IN_VA_START
))
2684 node
->local
.can_change_signature
= !e
;
2687 estimate_function_body_sizes (node
, early
);
2689 /* Inlining characteristics are maintained by the cgraph_mark_inline. */
2690 info
->time
= info
->self_time
;
2691 info
->size
= info
->self_size
;
2692 info
->stack_frame_offset
= 0;
2693 info
->estimated_stack_size
= info
->estimated_self_stack_size
;
2694 #ifdef ENABLE_CHECKING
2695 inline_update_overall_summary (node
);
2696 gcc_assert (info
->time
== info
->self_time
2697 && info
->size
== info
->self_size
);
2704 /* Compute parameters of functions used by inliner using
2705 current_function_decl. */
2708 compute_inline_parameters_for_current (void)
2710 compute_inline_parameters (cgraph_get_node (current_function_decl
), true);
2714 struct gimple_opt_pass pass_inline_parameters
=
2718 "inline_param", /* name */
2719 OPTGROUP_INLINE
, /* optinfo_flags */
2721 compute_inline_parameters_for_current
,/* execute */
2724 0, /* static_pass_number */
2725 TV_INLINE_PARAMETERS
, /* tv_id */
2726 0, /* properties_required */
2727 0, /* properties_provided */
2728 0, /* properties_destroyed */
2729 0, /* todo_flags_start */
2730 0 /* todo_flags_finish */
2735 /* Estimate benefit devirtualizing indirect edge IE, provided KNOWN_VALS and
2739 estimate_edge_devirt_benefit (struct cgraph_edge
*ie
,
2740 int *size
, int *time
,
2741 vec
<tree
> known_vals
,
2742 vec
<tree
> known_binfos
,
2743 vec
<ipa_agg_jump_function_p
> known_aggs
)
2746 struct cgraph_node
*callee
;
2747 struct inline_summary
*isummary
;
2749 if (!known_vals
.exists () && !known_binfos
.exists ())
2751 if (!flag_indirect_inlining
)
2754 target
= ipa_get_indirect_edge_target (ie
, known_vals
, known_binfos
,
2759 /* Account for difference in cost between indirect and direct calls. */
2760 *size
-= (eni_size_weights
.indirect_call_cost
- eni_size_weights
.call_cost
);
2761 *time
-= (eni_time_weights
.indirect_call_cost
- eni_time_weights
.call_cost
);
2762 gcc_checking_assert (*time
>= 0);
2763 gcc_checking_assert (*size
>= 0);
2765 callee
= cgraph_get_node (target
);
2766 if (!callee
|| !callee
->analyzed
)
2768 isummary
= inline_summary (callee
);
2769 return isummary
->inlinable
;
2772 /* Increase SIZE and TIME for size and time needed to handle edge E. */
2775 estimate_edge_size_and_time (struct cgraph_edge
*e
, int *size
, int *time
,
2777 vec
<tree
> known_vals
,
2778 vec
<tree
> known_binfos
,
2779 vec
<ipa_agg_jump_function_p
> known_aggs
,
2780 inline_hints
*hints
)
2783 struct inline_edge_summary
*es
= inline_edge_summary (e
);
2784 int call_size
= es
->call_stmt_size
;
2785 int call_time
= es
->call_stmt_time
;
2787 && estimate_edge_devirt_benefit (e
, &call_size
, &call_time
,
2788 known_vals
, known_binfos
, known_aggs
)
2790 && cgraph_maybe_hot_edge_p (e
))
2791 *hints
|= INLINE_HINT_indirect_call
;
2792 *size
+= call_size
* INLINE_SIZE_SCALE
;
2793 *time
+= call_time
* prob
/ REG_BR_PROB_BASE
2794 * e
->frequency
* (INLINE_TIME_SCALE
/ CGRAPH_FREQ_BASE
);
2795 if (*time
> MAX_TIME
* INLINE_TIME_SCALE
)
2796 *time
= MAX_TIME
* INLINE_TIME_SCALE
;
2801 /* Increase SIZE and TIME for size and time needed to handle all calls in NODE.
2802 POSSIBLE_TRUTHS, KNOWN_VALS and KNOWN_BINFOS describe context of the call
2806 estimate_calls_size_and_time (struct cgraph_node
*node
, int *size
, int *time
,
2807 inline_hints
*hints
,
2808 clause_t possible_truths
,
2809 vec
<tree
> known_vals
,
2810 vec
<tree
> known_binfos
,
2811 vec
<ipa_agg_jump_function_p
> known_aggs
)
2813 struct cgraph_edge
*e
;
2814 for (e
= node
->callees
; e
; e
= e
->next_callee
)
2816 struct inline_edge_summary
*es
= inline_edge_summary (e
);
2817 if (!es
->predicate
|| evaluate_predicate (es
->predicate
, possible_truths
))
2819 if (e
->inline_failed
)
2821 /* Predicates of calls shall not use NOT_CHANGED codes,
2822 sowe do not need to compute probabilities. */
2823 estimate_edge_size_and_time (e
, size
, time
, REG_BR_PROB_BASE
,
2824 known_vals
, known_binfos
, known_aggs
,
2828 estimate_calls_size_and_time (e
->callee
, size
, time
, hints
,
2830 known_vals
, known_binfos
, known_aggs
);
2833 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
2835 struct inline_edge_summary
*es
= inline_edge_summary (e
);
2836 if (!es
->predicate
|| evaluate_predicate (es
->predicate
, possible_truths
))
2837 estimate_edge_size_and_time (e
, size
, time
, REG_BR_PROB_BASE
,
2838 known_vals
, known_binfos
, known_aggs
,
2844 /* Estimate size and time needed to execute NODE assuming
2845 POSSIBLE_TRUTHS clause, and KNOWN_VALS and KNOWN_BINFOS information
2846 about NODE's arguments. */
2849 estimate_node_size_and_time (struct cgraph_node
*node
,
2850 clause_t possible_truths
,
2851 vec
<tree
> known_vals
,
2852 vec
<tree
> known_binfos
,
2853 vec
<ipa_agg_jump_function_p
> known_aggs
,
2854 int *ret_size
, int *ret_time
,
2855 inline_hints
*ret_hints
,
2856 vec
<inline_param_summary_t
>
2857 inline_param_summary
)
2859 struct inline_summary
*info
= inline_summary (node
);
2863 inline_hints hints
= 0;
2867 && (dump_flags
& TDF_DETAILS
))
2870 fprintf (dump_file
, " Estimating body: %s/%i\n"
2871 " Known to be false: ",
2872 cgraph_node_name (node
),
2875 for (i
= predicate_not_inlined_condition
;
2876 i
< (predicate_first_dynamic_condition
2877 + (int)vec_safe_length (info
->conds
)); i
++)
2878 if (!(possible_truths
& (1 << i
)))
2881 fprintf (dump_file
, ", ");
2883 dump_condition (dump_file
, info
->conds
, i
);
2887 for (i
= 0; vec_safe_iterate (info
->entry
, i
, &e
); i
++)
2888 if (evaluate_predicate (&e
->predicate
, possible_truths
))
2891 gcc_checking_assert (e
->time
>= 0);
2892 gcc_checking_assert (time
>= 0);
2893 if (!inline_param_summary
.exists ())
2897 int prob
= predicate_probability (info
->conds
,
2900 inline_param_summary
);
2901 gcc_checking_assert (prob
>= 0);
2902 gcc_checking_assert (prob
<= REG_BR_PROB_BASE
);
2903 time
+= ((gcov_type
)e
->time
* prob
) / REG_BR_PROB_BASE
;
2905 if (time
> MAX_TIME
* INLINE_TIME_SCALE
)
2906 time
= MAX_TIME
* INLINE_TIME_SCALE
;
2907 gcc_checking_assert (time
>= 0);
2910 gcc_checking_assert (size
>= 0);
2911 gcc_checking_assert (time
>= 0);
2913 if (info
->loop_iterations
2914 && !evaluate_predicate (info
->loop_iterations
, possible_truths
))
2915 hints
|=INLINE_HINT_loop_iterations
;
2916 if (info
->loop_stride
2917 && !evaluate_predicate (info
->loop_stride
, possible_truths
))
2918 hints
|=INLINE_HINT_loop_stride
;
2919 if (info
->array_index
2920 && !evaluate_predicate (info
->array_index
, possible_truths
))
2921 hints
|=INLINE_HINT_array_index
;
2923 hints
|= INLINE_HINT_in_scc
;
2924 if (DECL_DECLARED_INLINE_P (node
->symbol
.decl
))
2925 hints
|= INLINE_HINT_declared_inline
;
2927 estimate_calls_size_and_time (node
, &size
, &time
, &hints
, possible_truths
,
2928 known_vals
, known_binfos
, known_aggs
);
2929 gcc_checking_assert (size
>= 0);
2930 gcc_checking_assert (time
>= 0);
2931 time
= RDIV (time
, INLINE_TIME_SCALE
);
2932 size
= RDIV (size
, INLINE_SIZE_SCALE
);
2935 && (dump_flags
& TDF_DETAILS
))
2936 fprintf (dump_file
, "\n size:%i time:%i\n", (int)size
, (int)time
);
2947 /* Estimate size and time needed to execute callee of EDGE assuming that
2948 parameters known to be constant at caller of EDGE are propagated.
2949 KNOWN_VALS and KNOWN_BINFOS are vectors of assumed known constant values
2950 and types for parameters. */
2953 estimate_ipcp_clone_size_and_time (struct cgraph_node
*node
,
2954 vec
<tree
> known_vals
,
2955 vec
<tree
> known_binfos
,
2956 vec
<ipa_agg_jump_function_p
> known_aggs
,
2957 int *ret_size
, int *ret_time
,
2958 inline_hints
*hints
)
2962 clause
= evaluate_conditions_for_known_args (node
, false, known_vals
,
2964 estimate_node_size_and_time (node
, clause
, known_vals
, known_binfos
,
2965 known_aggs
, ret_size
, ret_time
, hints
,
2966 vec
<inline_param_summary_t
>());
2969 /* Translate all conditions from callee representation into caller
2970 representation and symbolically evaluate predicate P into new predicate.
2972 INFO is inline_summary of function we are adding predicate into, CALLEE_INFO
2973 is summary of function predicate P is from. OPERAND_MAP is array giving
2974 callee formal IDs the caller formal IDs. POSSSIBLE_TRUTHS is clausule of all
2975 callee conditions that may be true in caller context. TOPLEV_PREDICATE is
2976 predicate under which callee is executed. OFFSET_MAP is an array of of
2977 offsets that need to be added to conditions, negative offset means that
2978 conditions relying on values passed by reference have to be discarded
2979 because they might not be preserved (and should be considered offset zero
2980 for other purposes). */
2982 static struct predicate
2983 remap_predicate (struct inline_summary
*info
,
2984 struct inline_summary
*callee_info
,
2985 struct predicate
*p
,
2986 vec
<int> operand_map
,
2987 vec
<int> offset_map
,
2988 clause_t possible_truths
,
2989 struct predicate
*toplev_predicate
)
2992 struct predicate out
= true_predicate ();
2994 /* True predicate is easy. */
2995 if (true_predicate_p (p
))
2996 return *toplev_predicate
;
2997 for (i
= 0; p
->clause
[i
]; i
++)
2999 clause_t clause
= p
->clause
[i
];
3001 struct predicate clause_predicate
= false_predicate ();
3003 gcc_assert (i
< MAX_CLAUSES
);
3005 for (cond
= 0; cond
< NUM_CONDITIONS
; cond
++)
3006 /* Do we have condition we can't disprove? */
3007 if (clause
& possible_truths
& (1 << cond
))
3009 struct predicate cond_predicate
;
3010 /* Work out if the condition can translate to predicate in the
3011 inlined function. */
3012 if (cond
>= predicate_first_dynamic_condition
)
3014 struct condition
*c
;
3016 c
= &(*callee_info
->conds
)[cond
3017 - predicate_first_dynamic_condition
];
3018 /* See if we can remap condition operand to caller's operand.
3019 Otherwise give up. */
3020 if (!operand_map
.exists ()
3021 || (int)operand_map
.length () <= c
->operand_num
3022 || operand_map
[c
->operand_num
] == -1
3023 /* TODO: For non-aggregate conditions, adding an offset is
3024 basically an arithmetic jump function processing which
3025 we should support in future. */
3026 || ((!c
->agg_contents
|| !c
->by_ref
)
3027 && offset_map
[c
->operand_num
] > 0)
3028 || (c
->agg_contents
&& c
->by_ref
3029 && offset_map
[c
->operand_num
] < 0))
3030 cond_predicate
= true_predicate ();
3033 struct agg_position_info ap
;
3034 HOST_WIDE_INT offset_delta
= offset_map
[c
->operand_num
];
3035 if (offset_delta
< 0)
3037 gcc_checking_assert (!c
->agg_contents
|| !c
->by_ref
);
3040 gcc_assert (!c
->agg_contents
3042 || offset_delta
== 0);
3043 ap
.offset
= c
->offset
+ offset_delta
;
3044 ap
.agg_contents
= c
->agg_contents
;
3045 ap
.by_ref
= c
->by_ref
;
3046 cond_predicate
= add_condition (info
,
3047 operand_map
[c
->operand_num
],
3048 &ap
, c
->code
, c
->val
);
3051 /* Fixed conditions remains same, construct single
3052 condition predicate. */
3055 cond_predicate
.clause
[0] = 1 << cond
;
3056 cond_predicate
.clause
[1] = 0;
3058 clause_predicate
= or_predicates (info
->conds
, &clause_predicate
,
3061 out
= and_predicates (info
->conds
, &out
, &clause_predicate
);
3063 return and_predicates (info
->conds
, &out
, toplev_predicate
);
3067 /* Update summary information of inline clones after inlining.
3068 Compute peak stack usage. */
3071 inline_update_callee_summaries (struct cgraph_node
*node
,
3074 struct cgraph_edge
*e
;
3075 struct inline_summary
*callee_info
= inline_summary (node
);
3076 struct inline_summary
*caller_info
= inline_summary (node
->callers
->caller
);
3079 callee_info
->stack_frame_offset
3080 = caller_info
->stack_frame_offset
3081 + caller_info
->estimated_self_stack_size
;
3082 peak
= callee_info
->stack_frame_offset
3083 + callee_info
->estimated_self_stack_size
;
3084 if (inline_summary (node
->global
.inlined_to
)->estimated_stack_size
3086 inline_summary (node
->global
.inlined_to
)->estimated_stack_size
= peak
;
3087 cgraph_propagate_frequency (node
);
3088 for (e
= node
->callees
; e
; e
= e
->next_callee
)
3090 if (!e
->inline_failed
)
3091 inline_update_callee_summaries (e
->callee
, depth
);
3092 inline_edge_summary (e
)->loop_depth
+= depth
;
3094 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
3095 inline_edge_summary (e
)->loop_depth
+= depth
;
3098 /* Update change_prob of EDGE after INLINED_EDGE has been inlined.
3099 When functoin A is inlined in B and A calls C with parameter that
3100 changes with probability PROB1 and C is known to be passthroug
3101 of argument if B that change with probability PROB2, the probability
3102 of change is now PROB1*PROB2. */
3105 remap_edge_change_prob (struct cgraph_edge
*inlined_edge
,
3106 struct cgraph_edge
*edge
)
3108 if (ipa_node_params_vector
.exists ())
3111 struct ipa_edge_args
*args
= IPA_EDGE_REF (edge
);
3112 struct inline_edge_summary
*es
= inline_edge_summary (edge
);
3113 struct inline_edge_summary
*inlined_es
3114 = inline_edge_summary (inlined_edge
);
3116 for (i
= 0; i
< ipa_get_cs_argument_count (args
); i
++)
3118 struct ipa_jump_func
*jfunc
= ipa_get_ith_jump_func (args
, i
);
3119 if (jfunc
->type
== IPA_JF_PASS_THROUGH
3120 && (ipa_get_jf_pass_through_formal_id (jfunc
)
3121 < (int) inlined_es
->param
.length ()))
3123 int jf_formal_id
= ipa_get_jf_pass_through_formal_id (jfunc
);
3124 int prob1
= es
->param
[i
].change_prob
;
3125 int prob2
= inlined_es
->param
[jf_formal_id
].change_prob
;
3126 int prob
= ((prob1
* prob2
+ REG_BR_PROB_BASE
/ 2)
3127 / REG_BR_PROB_BASE
);
3129 if (prob1
&& prob2
&& !prob
)
3132 es
->param
[i
].change_prob
= prob
;
3138 /* Update edge summaries of NODE after INLINED_EDGE has been inlined.
3140 Remap predicates of callees of NODE. Rest of arguments match
3143 Also update change probabilities. */
3146 remap_edge_summaries (struct cgraph_edge
*inlined_edge
,
3147 struct cgraph_node
*node
,
3148 struct inline_summary
*info
,
3149 struct inline_summary
*callee_info
,
3150 vec
<int> operand_map
,
3151 vec
<int> offset_map
,
3152 clause_t possible_truths
,
3153 struct predicate
*toplev_predicate
)
3155 struct cgraph_edge
*e
;
3156 for (e
= node
->callees
; e
; e
= e
->next_callee
)
3158 struct inline_edge_summary
*es
= inline_edge_summary (e
);
3161 if (e
->inline_failed
)
3163 remap_edge_change_prob (inlined_edge
, e
);
3167 p
= remap_predicate (info
, callee_info
,
3168 es
->predicate
, operand_map
, offset_map
,
3171 edge_set_predicate (e
, &p
);
3172 /* TODO: We should remove the edge for code that will be
3173 optimized out, but we need to keep verifiers and tree-inline
3174 happy. Make it cold for now. */
3175 if (false_predicate_p (&p
))
3182 edge_set_predicate (e
, toplev_predicate
);
3185 remap_edge_summaries (inlined_edge
, e
->callee
, info
, callee_info
,
3186 operand_map
, offset_map
, possible_truths
,
3189 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
3191 struct inline_edge_summary
*es
= inline_edge_summary (e
);
3194 remap_edge_change_prob (inlined_edge
, e
);
3197 p
= remap_predicate (info
, callee_info
,
3198 es
->predicate
, operand_map
, offset_map
,
3199 possible_truths
, toplev_predicate
);
3200 edge_set_predicate (e
, &p
);
3201 /* TODO: We should remove the edge for code that will be optimized
3202 out, but we need to keep verifiers and tree-inline happy.
3203 Make it cold for now. */
3204 if (false_predicate_p (&p
))
3211 edge_set_predicate (e
, toplev_predicate
);
3215 /* Same as remap_predicate, but set result into hint *HINT. */
3218 remap_hint_predicate (struct inline_summary
*info
,
3219 struct inline_summary
*callee_info
,
3220 struct predicate
**hint
,
3221 vec
<int> operand_map
,
3222 vec
<int> offset_map
,
3223 clause_t possible_truths
,
3224 struct predicate
*toplev_predicate
)
3230 p
= remap_predicate (info
, callee_info
,
3232 operand_map
, offset_map
,
3235 if (!false_predicate_p (&p
)
3236 && !true_predicate_p (&p
))
3239 set_hint_predicate (hint
, p
);
3241 **hint
= and_predicates (info
->conds
,
3247 /* We inlined EDGE. Update summary of the function we inlined into. */
3250 inline_merge_summary (struct cgraph_edge
*edge
)
3252 struct inline_summary
*callee_info
= inline_summary (edge
->callee
);
3253 struct cgraph_node
*to
= (edge
->caller
->global
.inlined_to
3254 ? edge
->caller
->global
.inlined_to
: edge
->caller
);
3255 struct inline_summary
*info
= inline_summary (to
);
3256 clause_t clause
= 0; /* not_inline is known to be false. */
3258 vec
<int> operand_map
= vec
<int>();
3259 vec
<int> offset_map
= vec
<int>();
3261 struct predicate toplev_predicate
;
3262 struct predicate true_p
= true_predicate ();
3263 struct inline_edge_summary
*es
= inline_edge_summary (edge
);
3266 toplev_predicate
= *es
->predicate
;
3268 toplev_predicate
= true_predicate ();
3270 if (ipa_node_params_vector
.exists () && callee_info
->conds
)
3272 struct ipa_edge_args
*args
= IPA_EDGE_REF (edge
);
3273 int count
= ipa_get_cs_argument_count (args
);
3276 evaluate_properties_for_edge (edge
, true, &clause
, NULL
, NULL
, NULL
);
3279 operand_map
.safe_grow_cleared (count
);
3280 offset_map
.safe_grow_cleared (count
);
3282 for (i
= 0; i
< count
; i
++)
3284 struct ipa_jump_func
*jfunc
= ipa_get_ith_jump_func (args
, i
);
3287 /* TODO: handle non-NOPs when merging. */
3288 if (jfunc
->type
== IPA_JF_PASS_THROUGH
)
3290 if (ipa_get_jf_pass_through_operation (jfunc
) == NOP_EXPR
)
3291 map
= ipa_get_jf_pass_through_formal_id (jfunc
);
3292 if (!ipa_get_jf_pass_through_agg_preserved (jfunc
))
3295 else if (jfunc
->type
== IPA_JF_ANCESTOR
)
3297 HOST_WIDE_INT offset
= ipa_get_jf_ancestor_offset (jfunc
);
3298 if (offset
>= 0 && offset
< INT_MAX
)
3300 map
= ipa_get_jf_ancestor_formal_id (jfunc
);
3301 if (!ipa_get_jf_ancestor_agg_preserved (jfunc
))
3303 offset_map
[i
] = offset
;
3306 operand_map
[i
] = map
;
3307 gcc_assert (map
< ipa_get_param_count (IPA_NODE_REF (to
)));
3310 for (i
= 0; vec_safe_iterate (callee_info
->entry
, i
, &e
); i
++)
3312 struct predicate p
= remap_predicate (info
, callee_info
,
3313 &e
->predicate
, operand_map
,
3316 if (!false_predicate_p (&p
))
3318 gcov_type add_time
= ((gcov_type
)e
->time
* edge
->frequency
3319 + CGRAPH_FREQ_BASE
/ 2) / CGRAPH_FREQ_BASE
;
3320 int prob
= predicate_probability (callee_info
->conds
,
3323 add_time
= ((gcov_type
)add_time
* prob
) / REG_BR_PROB_BASE
;
3324 if (add_time
> MAX_TIME
* INLINE_TIME_SCALE
)
3325 add_time
= MAX_TIME
* INLINE_TIME_SCALE
;
3326 if (prob
!= REG_BR_PROB_BASE
3327 && dump_file
&& (dump_flags
& TDF_DETAILS
))
3329 fprintf (dump_file
, "\t\tScaling time by probability:%f\n",
3330 (double)prob
/ REG_BR_PROB_BASE
);
3332 account_size_time (info
, e
->size
, add_time
, &p
);
3335 remap_edge_summaries (edge
, edge
->callee
, info
, callee_info
, operand_map
,
3336 offset_map
, clause
, &toplev_predicate
);
3337 remap_hint_predicate (info
, callee_info
,
3338 &callee_info
->loop_iterations
,
3339 operand_map
, offset_map
,
3340 clause
, &toplev_predicate
);
3341 remap_hint_predicate (info
, callee_info
,
3342 &callee_info
->loop_stride
,
3343 operand_map
, offset_map
,
3344 clause
, &toplev_predicate
);
3345 remap_hint_predicate (info
, callee_info
,
3346 &callee_info
->array_index
,
3347 operand_map
, offset_map
,
3348 clause
, &toplev_predicate
);
3350 inline_update_callee_summaries (edge
->callee
,
3351 inline_edge_summary (edge
)->loop_depth
);
3353 /* We do not maintain predicates of inlined edges, free it. */
3354 edge_set_predicate (edge
, &true_p
);
3355 /* Similarly remove param summaries. */
3356 es
->param
.release ();
3357 operand_map
.release ();
3358 offset_map
.release ();
3361 /* For performance reasons inline_merge_summary is not updating overall size
3362 and time. Recompute it. */
3365 inline_update_overall_summary (struct cgraph_node
*node
)
3367 struct inline_summary
*info
= inline_summary (node
);
3373 for (i
= 0; vec_safe_iterate (info
->entry
, i
, &e
); i
++)
3375 info
->size
+= e
->size
, info
->time
+= e
->time
;
3376 if (info
->time
> MAX_TIME
* INLINE_TIME_SCALE
)
3377 info
->time
= MAX_TIME
* INLINE_TIME_SCALE
;
3379 estimate_calls_size_and_time (node
, &info
->size
, &info
->time
, NULL
,
3380 ~(clause_t
)(1 << predicate_false_condition
),
3383 vec
<ipa_agg_jump_function_p
>());
3384 info
->time
= (info
->time
+ INLINE_TIME_SCALE
/ 2) / INLINE_TIME_SCALE
;
3385 info
->size
= (info
->size
+ INLINE_SIZE_SCALE
/ 2) / INLINE_SIZE_SCALE
;
3388 /* Return hints derrived from EDGE. */
3390 simple_edge_hints (struct cgraph_edge
*edge
)
3393 struct cgraph_node
*to
= (edge
->caller
->global
.inlined_to
3394 ? edge
->caller
->global
.inlined_to
3396 if (inline_summary (to
)->scc_no
3397 && inline_summary (to
)->scc_no
== inline_summary (edge
->callee
)->scc_no
3398 && !cgraph_edge_recursive_p (edge
))
3399 hints
|= INLINE_HINT_same_scc
;
3401 if (to
->symbol
.lto_file_data
&& edge
->callee
->symbol
.lto_file_data
3402 && to
->symbol
.lto_file_data
!= edge
->callee
->symbol
.lto_file_data
)
3403 hints
|= INLINE_HINT_cross_module
;
3408 /* Estimate the time cost for the caller when inlining EDGE.
3409 Only to be called via estimate_edge_time, that handles the
3412 When caching, also update the cache entry. Compute both time and
3413 size, since we always need both metrics eventually. */
3416 do_estimate_edge_time (struct cgraph_edge
*edge
)
3421 struct cgraph_node
*callee
;
3423 vec
<tree
> known_vals
;
3424 vec
<tree
> known_binfos
;
3425 vec
<ipa_agg_jump_function_p
> known_aggs
;
3426 struct inline_edge_summary
*es
= inline_edge_summary (edge
);
3428 callee
= cgraph_function_or_thunk_node (edge
->callee
, NULL
);
3430 gcc_checking_assert (edge
->inline_failed
);
3431 evaluate_properties_for_edge (edge
, true,
3432 &clause
, &known_vals
, &known_binfos
,
3434 estimate_node_size_and_time (callee
, clause
, known_vals
, known_binfos
,
3435 known_aggs
, &size
, &time
, &hints
, es
->param
);
3436 known_vals
.release ();
3437 known_binfos
.release ();
3438 known_aggs
.release ();
3439 gcc_checking_assert (size
>= 0);
3440 gcc_checking_assert (time
>= 0);
3442 /* When caching, update the cache entry. */
3443 if (edge_growth_cache
.exists ())
3445 if ((int)edge_growth_cache
.length () <= edge
->uid
)
3446 edge_growth_cache
.safe_grow_cleared (cgraph_edge_max_uid
);
3447 edge_growth_cache
[edge
->uid
].time
= time
+ (time
>= 0);
3449 edge_growth_cache
[edge
->uid
].size
= size
+ (size
>= 0);
3450 hints
|= simple_edge_hints (edge
);
3451 edge_growth_cache
[edge
->uid
].hints
= hints
+ 1;
3457 /* Return estimated callee growth after inlining EDGE.
3458 Only to be called via estimate_edge_size. */
3461 do_estimate_edge_size (struct cgraph_edge
*edge
)
3464 struct cgraph_node
*callee
;
3466 vec
<tree
> known_vals
;
3467 vec
<tree
> known_binfos
;
3468 vec
<ipa_agg_jump_function_p
> known_aggs
;
3470 /* When we do caching, use do_estimate_edge_time to populate the entry. */
3472 if (edge_growth_cache
.exists ())
3474 do_estimate_edge_time (edge
);
3475 size
= edge_growth_cache
[edge
->uid
].size
;
3476 gcc_checking_assert (size
);
3477 return size
- (size
> 0);
3480 callee
= cgraph_function_or_thunk_node (edge
->callee
, NULL
);
3482 /* Early inliner runs without caching, go ahead and do the dirty work. */
3483 gcc_checking_assert (edge
->inline_failed
);
3484 evaluate_properties_for_edge (edge
, true,
3485 &clause
, &known_vals
, &known_binfos
,
3487 estimate_node_size_and_time (callee
, clause
, known_vals
, known_binfos
,
3488 known_aggs
, &size
, NULL
, NULL
,
3489 vec
<inline_param_summary_t
>());
3490 known_vals
.release ();
3491 known_binfos
.release ();
3492 known_aggs
.release ();
3497 /* Estimate the growth of the caller when inlining EDGE.
3498 Only to be called via estimate_edge_size. */
3501 do_estimate_edge_hints (struct cgraph_edge
*edge
)
3504 struct cgraph_node
*callee
;
3506 vec
<tree
> known_vals
;
3507 vec
<tree
> known_binfos
;
3508 vec
<ipa_agg_jump_function_p
> known_aggs
;
3510 /* When we do caching, use do_estimate_edge_time to populate the entry. */
3512 if (edge_growth_cache
.exists ())
3514 do_estimate_edge_time (edge
);
3515 hints
= edge_growth_cache
[edge
->uid
].hints
;
3516 gcc_checking_assert (hints
);
3520 callee
= cgraph_function_or_thunk_node (edge
->callee
, NULL
);
3522 /* Early inliner runs without caching, go ahead and do the dirty work. */
3523 gcc_checking_assert (edge
->inline_failed
);
3524 evaluate_properties_for_edge (edge
, true,
3525 &clause
, &known_vals
, &known_binfos
,
3527 estimate_node_size_and_time (callee
, clause
, known_vals
, known_binfos
,
3528 known_aggs
, NULL
, NULL
, &hints
,
3529 vec
<inline_param_summary_t
>());
3530 known_vals
.release ();
3531 known_binfos
.release ();
3532 known_aggs
.release ();
3533 hints
|= simple_edge_hints (edge
);
3538 /* Estimate self time of the function NODE after inlining EDGE. */
3541 estimate_time_after_inlining (struct cgraph_node
*node
,
3542 struct cgraph_edge
*edge
)
3544 struct inline_edge_summary
*es
= inline_edge_summary (edge
);
3545 if (!es
->predicate
|| !false_predicate_p (es
->predicate
))
3547 gcov_type time
= inline_summary (node
)->time
+ estimate_edge_time (edge
);
3550 if (time
> MAX_TIME
)
3554 return inline_summary (node
)->time
;
3558 /* Estimate the size of NODE after inlining EDGE which should be an
3559 edge to either NODE or a call inlined into NODE. */
3562 estimate_size_after_inlining (struct cgraph_node
*node
,
3563 struct cgraph_edge
*edge
)
3565 struct inline_edge_summary
*es
= inline_edge_summary (edge
);
3566 if (!es
->predicate
|| !false_predicate_p (es
->predicate
))
3568 int size
= inline_summary (node
)->size
+ estimate_edge_growth (edge
);
3569 gcc_assert (size
>= 0);
3572 return inline_summary (node
)->size
;
3578 bool self_recursive
;
3583 /* Worker for do_estimate_growth. Collect growth for all callers. */
3586 do_estimate_growth_1 (struct cgraph_node
*node
, void *data
)
3588 struct cgraph_edge
*e
;
3589 struct growth_data
*d
= (struct growth_data
*) data
;
3591 for (e
= node
->callers
; e
; e
= e
->next_caller
)
3593 gcc_checking_assert (e
->inline_failed
);
3595 if (e
->caller
== node
3596 || (e
->caller
->global
.inlined_to
3597 && e
->caller
->global
.inlined_to
== node
))
3598 d
->self_recursive
= true;
3599 d
->growth
+= estimate_edge_growth (e
);
3605 /* Estimate the growth caused by inlining NODE into all callees. */
3608 do_estimate_growth (struct cgraph_node
*node
)
3610 struct growth_data d
= {0, false};
3611 struct inline_summary
*info
= inline_summary (node
);
3613 cgraph_for_node_and_aliases (node
, do_estimate_growth_1
, &d
, true);
3615 /* For self recursive functions the growth estimation really should be
3616 infinity. We don't want to return very large values because the growth
3617 plays various roles in badness computation fractions. Be sure to not
3618 return zero or negative growths. */
3619 if (d
.self_recursive
)
3620 d
.growth
= d
.growth
< info
->size
? info
->size
: d
.growth
;
3621 else if (DECL_EXTERNAL (node
->symbol
.decl
))
3625 if (cgraph_will_be_removed_from_program_if_no_direct_calls (node
))
3626 d
.growth
-= info
->size
;
3627 /* COMDAT functions are very often not shared across multiple units
3628 since they come from various template instantiations.
3629 Take this into account. */
3630 else if (DECL_COMDAT (node
->symbol
.decl
)
3631 && cgraph_can_remove_if_no_direct_calls_p (node
))
3632 d
.growth
-= (info
->size
3633 * (100 - PARAM_VALUE (PARAM_COMDAT_SHARING_PROBABILITY
))
3637 if (node_growth_cache
.exists ())
3639 if ((int)node_growth_cache
.length () <= node
->uid
)
3640 node_growth_cache
.safe_grow_cleared (cgraph_max_uid
);
3641 node_growth_cache
[node
->uid
] = d
.growth
+ (d
.growth
>= 0);
3647 /* This function performs intraprocedural analysis in NODE that is required to
3648 inline indirect calls. */
3651 inline_indirect_intraprocedural_analysis (struct cgraph_node
*node
)
3653 ipa_analyze_node (node
);
3654 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
3656 ipa_print_node_params (dump_file
, node
);
3657 ipa_print_node_jump_functions (dump_file
, node
);
3662 /* Note function body size. */
3665 inline_analyze_function (struct cgraph_node
*node
)
3667 push_cfun (DECL_STRUCT_FUNCTION (node
->symbol
.decl
));
3670 fprintf (dump_file
, "\nAnalyzing function: %s/%u\n",
3671 cgraph_node_name (node
), node
->uid
);
3672 if (optimize
&& !node
->thunk
.thunk_p
)
3673 inline_indirect_intraprocedural_analysis (node
);
3674 compute_inline_parameters (node
, false);
3680 /* Called when new function is inserted to callgraph late. */
3683 add_new_function (struct cgraph_node
*node
, void *data ATTRIBUTE_UNUSED
)
3685 inline_analyze_function (node
);
3689 /* Note function body size. */
3692 inline_generate_summary (void)
3694 struct cgraph_node
*node
;
3696 function_insertion_hook_holder
=
3697 cgraph_add_function_insertion_hook (&add_new_function
, NULL
);
3699 ipa_register_cgraph_hooks ();
3700 inline_free_summary ();
3702 FOR_EACH_DEFINED_FUNCTION (node
)
3704 inline_analyze_function (node
);
3708 /* Read predicate from IB. */
3710 static struct predicate
3711 read_predicate (struct lto_input_block
*ib
)
3713 struct predicate out
;
3719 gcc_assert (k
<= MAX_CLAUSES
);
3720 clause
= out
.clause
[k
++] = streamer_read_uhwi (ib
);
3724 /* Zero-initialize the remaining clauses in OUT. */
3725 while (k
<= MAX_CLAUSES
)
3726 out
.clause
[k
++] = 0;
3732 /* Write inline summary for edge E to OB. */
3735 read_inline_edge_summary (struct lto_input_block
*ib
, struct cgraph_edge
*e
)
3737 struct inline_edge_summary
*es
= inline_edge_summary (e
);
3741 es
->call_stmt_size
= streamer_read_uhwi (ib
);
3742 es
->call_stmt_time
= streamer_read_uhwi (ib
);
3743 es
->loop_depth
= streamer_read_uhwi (ib
);
3744 p
= read_predicate (ib
);
3745 edge_set_predicate (e
, &p
);
3746 length
= streamer_read_uhwi (ib
);
3749 es
->param
.safe_grow_cleared (length
);
3750 for (i
= 0; i
< length
; i
++)
3751 es
->param
[i
].change_prob
3752 = streamer_read_uhwi (ib
);
3757 /* Stream in inline summaries from the section. */
3760 inline_read_section (struct lto_file_decl_data
*file_data
, const char *data
,
3763 const struct lto_function_header
*header
=
3764 (const struct lto_function_header
*) data
;
3765 const int cfg_offset
= sizeof (struct lto_function_header
);
3766 const int main_offset
= cfg_offset
+ header
->cfg_size
;
3767 const int string_offset
= main_offset
+ header
->main_size
;
3768 struct data_in
*data_in
;
3769 struct lto_input_block ib
;
3770 unsigned int i
, count2
, j
;
3771 unsigned int f_count
;
3773 LTO_INIT_INPUT_BLOCK (ib
, (const char *) data
+ main_offset
, 0,
3777 lto_data_in_create (file_data
, (const char *) data
+ string_offset
,
3778 header
->string_size
,
3779 vec
<ld_plugin_symbol_resolution_t
>());
3780 f_count
= streamer_read_uhwi (&ib
);
3781 for (i
= 0; i
< f_count
; i
++)
3784 struct cgraph_node
*node
;
3785 struct inline_summary
*info
;
3786 lto_symtab_encoder_t encoder
;
3787 struct bitpack_d bp
;
3788 struct cgraph_edge
*e
;
3791 index
= streamer_read_uhwi (&ib
);
3792 encoder
= file_data
->symtab_node_encoder
;
3793 node
= cgraph (lto_symtab_encoder_deref (encoder
, index
));
3794 info
= inline_summary (node
);
3796 info
->estimated_stack_size
3797 = info
->estimated_self_stack_size
= streamer_read_uhwi (&ib
);
3798 info
->size
= info
->self_size
= streamer_read_uhwi (&ib
);
3799 info
->time
= info
->self_time
= streamer_read_uhwi (&ib
);
3801 bp
= streamer_read_bitpack (&ib
);
3802 info
->inlinable
= bp_unpack_value (&bp
, 1);
3804 count2
= streamer_read_uhwi (&ib
);
3805 gcc_assert (!info
->conds
);
3806 for (j
= 0; j
< count2
; j
++)
3809 c
.operand_num
= streamer_read_uhwi (&ib
);
3810 c
.code
= (enum tree_code
) streamer_read_uhwi (&ib
);
3811 c
.val
= stream_read_tree (&ib
, data_in
);
3812 bp
= streamer_read_bitpack (&ib
);
3813 c
.agg_contents
= bp_unpack_value (&bp
, 1);
3814 c
.by_ref
= bp_unpack_value (&bp
, 1);
3816 c
.offset
= streamer_read_uhwi (&ib
);
3817 vec_safe_push (info
->conds
, c
);
3819 count2
= streamer_read_uhwi (&ib
);
3820 gcc_assert (!info
->entry
);
3821 for (j
= 0; j
< count2
; j
++)
3823 struct size_time_entry e
;
3825 e
.size
= streamer_read_uhwi (&ib
);
3826 e
.time
= streamer_read_uhwi (&ib
);
3827 e
.predicate
= read_predicate (&ib
);
3829 vec_safe_push (info
->entry
, e
);
3832 p
= read_predicate (&ib
);
3833 set_hint_predicate (&info
->loop_iterations
, p
);
3834 p
= read_predicate (&ib
);
3835 set_hint_predicate (&info
->loop_stride
, p
);
3836 p
= read_predicate (&ib
);
3837 set_hint_predicate (&info
->array_index
, p
);
3838 for (e
= node
->callees
; e
; e
= e
->next_callee
)
3839 read_inline_edge_summary (&ib
, e
);
3840 for (e
= node
->indirect_calls
; e
; e
= e
->next_callee
)
3841 read_inline_edge_summary (&ib
, e
);
3844 lto_free_section_data (file_data
, LTO_section_inline_summary
, NULL
, data
,
3846 lto_data_in_delete (data_in
);
3850 /* Read inline summary. Jump functions are shared among ipa-cp
3851 and inliner, so when ipa-cp is active, we don't need to write them
3855 inline_read_summary (void)
3857 struct lto_file_decl_data
**file_data_vec
= lto_get_file_decl_data ();
3858 struct lto_file_decl_data
*file_data
;
3861 inline_summary_alloc ();
3863 while ((file_data
= file_data_vec
[j
++]))
3866 const char *data
= lto_get_section_data (file_data
,
3867 LTO_section_inline_summary
,
3870 inline_read_section (file_data
, data
, len
);
3872 /* Fatal error here. We do not want to support compiling ltrans units
3873 with different version of compiler or different flags than the WPA
3874 unit, so this should never happen. */
3875 fatal_error ("ipa inline summary is missing in input file");
3879 ipa_register_cgraph_hooks ();
3881 ipa_prop_read_jump_functions ();
3883 function_insertion_hook_holder
=
3884 cgraph_add_function_insertion_hook (&add_new_function
, NULL
);
3888 /* Write predicate P to OB. */
3891 write_predicate (struct output_block
*ob
, struct predicate
*p
)
3895 for (j
= 0; p
->clause
[j
]; j
++)
3897 gcc_assert (j
< MAX_CLAUSES
);
3898 streamer_write_uhwi (ob
, p
->clause
[j
]);
3900 streamer_write_uhwi (ob
, 0);
3904 /* Write inline summary for edge E to OB. */
3907 write_inline_edge_summary (struct output_block
*ob
, struct cgraph_edge
*e
)
3909 struct inline_edge_summary
*es
= inline_edge_summary (e
);
3912 streamer_write_uhwi (ob
, es
->call_stmt_size
);
3913 streamer_write_uhwi (ob
, es
->call_stmt_time
);
3914 streamer_write_uhwi (ob
, es
->loop_depth
);
3915 write_predicate (ob
, es
->predicate
);
3916 streamer_write_uhwi (ob
, es
->param
.length ());
3917 for (i
= 0; i
< (int)es
->param
.length (); i
++)
3918 streamer_write_uhwi (ob
, es
->param
[i
].change_prob
);
3922 /* Write inline summary for node in SET.
3923 Jump functions are shared among ipa-cp and inliner, so when ipa-cp is
3924 active, we don't need to write them twice. */
3927 inline_write_summary (void)
3929 struct cgraph_node
*node
;
3930 struct output_block
*ob
= create_output_block (LTO_section_inline_summary
);
3931 lto_symtab_encoder_t encoder
= ob
->decl_state
->symtab_node_encoder
;
3932 unsigned int count
= 0;
3935 for (i
= 0; i
< lto_symtab_encoder_size (encoder
); i
++)
3937 symtab_node snode
= lto_symtab_encoder_deref (encoder
, i
);
3938 cgraph_node
*cnode
= dyn_cast
<cgraph_node
> (snode
);
3939 if (cnode
&& cnode
->analyzed
)
3942 streamer_write_uhwi (ob
, count
);
3944 for (i
= 0; i
< lto_symtab_encoder_size (encoder
); i
++)
3946 symtab_node snode
= lto_symtab_encoder_deref (encoder
, i
);
3947 cgraph_node
*cnode
= dyn_cast
<cgraph_node
> (snode
);
3948 if (cnode
&& (node
= cnode
)->analyzed
)
3950 struct inline_summary
*info
= inline_summary (node
);
3951 struct bitpack_d bp
;
3952 struct cgraph_edge
*edge
;
3955 struct condition
*c
;
3957 streamer_write_uhwi (ob
, lto_symtab_encoder_encode (encoder
, (symtab_node
)node
));
3958 streamer_write_hwi (ob
, info
->estimated_self_stack_size
);
3959 streamer_write_hwi (ob
, info
->self_size
);
3960 streamer_write_hwi (ob
, info
->self_time
);
3961 bp
= bitpack_create (ob
->main_stream
);
3962 bp_pack_value (&bp
, info
->inlinable
, 1);
3963 streamer_write_bitpack (&bp
);
3964 streamer_write_uhwi (ob
, vec_safe_length (info
->conds
));
3965 for (i
= 0; vec_safe_iterate (info
->conds
, i
, &c
); i
++)
3967 streamer_write_uhwi (ob
, c
->operand_num
);
3968 streamer_write_uhwi (ob
, c
->code
);
3969 stream_write_tree (ob
, c
->val
, true);
3970 bp
= bitpack_create (ob
->main_stream
);
3971 bp_pack_value (&bp
, c
->agg_contents
, 1);
3972 bp_pack_value (&bp
, c
->by_ref
, 1);
3973 streamer_write_bitpack (&bp
);
3974 if (c
->agg_contents
)
3975 streamer_write_uhwi (ob
, c
->offset
);
3977 streamer_write_uhwi (ob
, vec_safe_length (info
->entry
));
3978 for (i
= 0; vec_safe_iterate (info
->entry
, i
, &e
); i
++)
3980 streamer_write_uhwi (ob
, e
->size
);
3981 streamer_write_uhwi (ob
, e
->time
);
3982 write_predicate (ob
, &e
->predicate
);
3984 write_predicate (ob
, info
->loop_iterations
);
3985 write_predicate (ob
, info
->loop_stride
);
3986 write_predicate (ob
, info
->array_index
);
3987 for (edge
= node
->callees
; edge
; edge
= edge
->next_callee
)
3988 write_inline_edge_summary (ob
, edge
);
3989 for (edge
= node
->indirect_calls
; edge
; edge
= edge
->next_callee
)
3990 write_inline_edge_summary (ob
, edge
);
3993 streamer_write_char_stream (ob
->main_stream
, 0);
3994 produce_asm (ob
, NULL
);
3995 destroy_output_block (ob
);
3997 if (optimize
&& !flag_ipa_cp
)
3998 ipa_prop_write_jump_functions ();
4002 /* Release inline summary. */
4005 inline_free_summary (void)
4007 struct cgraph_node
*node
;
4008 if (!inline_edge_summary_vec
.exists ())
4010 FOR_EACH_DEFINED_FUNCTION (node
)
4011 reset_inline_summary (node
);
4012 if (function_insertion_hook_holder
)
4013 cgraph_remove_function_insertion_hook (function_insertion_hook_holder
);
4014 function_insertion_hook_holder
= NULL
;
4015 if (node_removal_hook_holder
)
4016 cgraph_remove_node_removal_hook (node_removal_hook_holder
);
4017 node_removal_hook_holder
= NULL
;
4018 if (edge_removal_hook_holder
)
4019 cgraph_remove_edge_removal_hook (edge_removal_hook_holder
);
4020 edge_removal_hook_holder
= NULL
;
4021 if (node_duplication_hook_holder
)
4022 cgraph_remove_node_duplication_hook (node_duplication_hook_holder
);
4023 node_duplication_hook_holder
= NULL
;
4024 if (edge_duplication_hook_holder
)
4025 cgraph_remove_edge_duplication_hook (edge_duplication_hook_holder
);
4026 edge_duplication_hook_holder
= NULL
;
4027 vec_free (inline_summary_vec
);
4028 inline_edge_summary_vec
.release ();
4029 if (edge_predicate_pool
)
4030 free_alloc_pool (edge_predicate_pool
);
4031 edge_predicate_pool
= 0;