* config/xtensa/predicates.md (call expander): Update for
[official-gcc.git] / gcc / ipa-inline-analysis.c
blob9e66a4c5a5c91399405c2b20dbd5525616050348
1 /* Inlining decision heuristics.
2 Copyright (C) 2003-2014 Free Software Foundation, Inc.
3 Contributed by Jan Hubicka
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 /* Analysis used by the inliner and other passes limiting code size growth.
23 We estimate for each function
24 - function body size
25 - average function execution time
26 - inlining size benefit (that is how much of function body size
27 and its call sequence is expected to disappear by inlining)
28 - inlining time benefit
29 - function frame size
30 For each call
31 - call statement size and time
33 inlinie_summary datastructures store above information locally (i.e.
34 parameters of the function itself) and globally (i.e. parameters of
35 the function created by applying all the inline decisions already
36 present in the callgraph).
38 We provide accestor to the inline_summary datastructure and
39 basic logic updating the parameters when inlining is performed.
41 The summaries are context sensitive. Context means
42 1) partial assignment of known constant values of operands
43 2) whether function is inlined into the call or not.
44 It is easy to add more variants. To represent function size and time
45 that depends on context (i.e. it is known to be optimized away when
46 context is known either by inlining or from IP-CP and clonning),
47 we use predicates. Predicates are logical formulas in
48 conjunctive-disjunctive form consisting of clauses. Clauses are bitmaps
49 specifying what conditions must be true. Conditions are simple test
50 of the form described above.
52 In order to make predicate (possibly) true, all of its clauses must
53 be (possibly) true. To make clause (possibly) true, one of conditions
54 it mentions must be (possibly) true. There are fixed bounds on
55 number of clauses and conditions and all the manipulation functions
56 are conservative in positive direction. I.e. we may lose precision
57 by thinking that predicate may be true even when it is not.
59 estimate_edge_size and estimate_edge_growth can be used to query
60 function size/time in the given context. inline_merge_summary merges
61 properties of caller and callee after inlining.
63 Finally pass_inline_parameters is exported. This is used to drive
64 computation of function parameters used by the early inliner. IPA
65 inlined performs analysis via its analyze_function method. */
67 #include "config.h"
68 #include "system.h"
69 #include "coretypes.h"
70 #include "tm.h"
71 #include "tree.h"
72 #include "stor-layout.h"
73 #include "stringpool.h"
74 #include "print-tree.h"
75 #include "tree-inline.h"
76 #include "langhooks.h"
77 #include "flags.h"
78 #include "diagnostic.h"
79 #include "gimple-pretty-print.h"
80 #include "params.h"
81 #include "tree-pass.h"
82 #include "coverage.h"
83 #include "basic-block.h"
84 #include "tree-ssa-alias.h"
85 #include "internal-fn.h"
86 #include "gimple-expr.h"
87 #include "is-a.h"
88 #include "gimple.h"
89 #include "gimple-iterator.h"
90 #include "gimple-ssa.h"
91 #include "tree-cfg.h"
92 #include "tree-phinodes.h"
93 #include "ssa-iterators.h"
94 #include "tree-ssanames.h"
95 #include "tree-ssa-loop-niter.h"
96 #include "tree-ssa-loop.h"
97 #include "ipa-prop.h"
98 #include "lto-streamer.h"
99 #include "data-streamer.h"
100 #include "tree-streamer.h"
101 #include "ipa-inline.h"
102 #include "alloc-pool.h"
103 #include "cfgloop.h"
104 #include "tree-scalar-evolution.h"
105 #include "ipa-utils.h"
106 #include "cilk.h"
107 #include "cfgexpand.h"
109 /* Estimate runtime of function can easilly run into huge numbers with many
110 nested loops. Be sure we can compute time * INLINE_SIZE_SCALE * 2 in an
111 integer. For anything larger we use gcov_type. */
112 #define MAX_TIME 500000
114 /* Number of bits in integer, but we really want to be stable across different
115 hosts. */
116 #define NUM_CONDITIONS 32
118 enum predicate_conditions
120 predicate_false_condition = 0,
121 predicate_not_inlined_condition = 1,
122 predicate_first_dynamic_condition = 2
125 /* Special condition code we use to represent test that operand is compile time
126 constant. */
127 #define IS_NOT_CONSTANT ERROR_MARK
128 /* Special condition code we use to represent test that operand is not changed
129 across invocation of the function. When operand IS_NOT_CONSTANT it is always
130 CHANGED, however i.e. loop invariants can be NOT_CHANGED given percentage
131 of executions even when they are not compile time constants. */
132 #define CHANGED IDENTIFIER_NODE
134 /* Holders of ipa cgraph hooks: */
135 static struct cgraph_node_hook_list *function_insertion_hook_holder;
136 static struct cgraph_node_hook_list *node_removal_hook_holder;
137 static struct cgraph_2node_hook_list *node_duplication_hook_holder;
138 static struct cgraph_2edge_hook_list *edge_duplication_hook_holder;
139 static struct cgraph_edge_hook_list *edge_removal_hook_holder;
140 static void inline_node_removal_hook (struct cgraph_node *, void *);
141 static void inline_node_duplication_hook (struct cgraph_node *,
142 struct cgraph_node *, void *);
143 static void inline_edge_removal_hook (struct cgraph_edge *, void *);
144 static void inline_edge_duplication_hook (struct cgraph_edge *,
145 struct cgraph_edge *, void *);
147 /* VECtor holding inline summaries.
148 In GGC memory because conditions might point to constant trees. */
149 vec<inline_summary_t, va_gc> *inline_summary_vec;
150 vec<inline_edge_summary_t> inline_edge_summary_vec;
152 /* Cached node/edge growths. */
153 vec<int> node_growth_cache;
154 vec<edge_growth_cache_entry> edge_growth_cache;
156 /* Edge predicates goes here. */
157 static alloc_pool edge_predicate_pool;
159 /* Return true predicate (tautology).
160 We represent it by empty list of clauses. */
162 static inline struct predicate
163 true_predicate (void)
165 struct predicate p;
166 p.clause[0] = 0;
167 return p;
171 /* Return predicate testing single condition number COND. */
173 static inline struct predicate
174 single_cond_predicate (int cond)
176 struct predicate p;
177 p.clause[0] = 1 << cond;
178 p.clause[1] = 0;
179 return p;
183 /* Return false predicate. First clause require false condition. */
185 static inline struct predicate
186 false_predicate (void)
188 return single_cond_predicate (predicate_false_condition);
192 /* Return true if P is (true). */
194 static inline bool
195 true_predicate_p (struct predicate *p)
197 return !p->clause[0];
201 /* Return true if P is (false). */
203 static inline bool
204 false_predicate_p (struct predicate *p)
206 if (p->clause[0] == (1 << predicate_false_condition))
208 gcc_checking_assert (!p->clause[1]
209 && p->clause[0] == 1 << predicate_false_condition);
210 return true;
212 return false;
216 /* Return predicate that is set true when function is not inlined. */
218 static inline struct predicate
219 not_inlined_predicate (void)
221 return single_cond_predicate (predicate_not_inlined_condition);
224 /* Simple description of whether a memory load or a condition refers to a load
225 from an aggregate and if so, how and where from in the aggregate.
226 Individual fields have the same meaning like fields with the same name in
227 struct condition. */
229 struct agg_position_info
231 HOST_WIDE_INT offset;
232 bool agg_contents;
233 bool by_ref;
236 /* Add condition to condition list CONDS. AGGPOS describes whether the used
237 oprand is loaded from an aggregate and where in the aggregate it is. It can
238 be NULL, which means this not a load from an aggregate. */
240 static struct predicate
241 add_condition (struct inline_summary *summary, int operand_num,
242 struct agg_position_info *aggpos,
243 enum tree_code code, tree val)
245 int i;
246 struct condition *c;
247 struct condition new_cond;
248 HOST_WIDE_INT offset;
249 bool agg_contents, by_ref;
251 if (aggpos)
253 offset = aggpos->offset;
254 agg_contents = aggpos->agg_contents;
255 by_ref = aggpos->by_ref;
257 else
259 offset = 0;
260 agg_contents = false;
261 by_ref = false;
264 gcc_checking_assert (operand_num >= 0);
265 for (i = 0; vec_safe_iterate (summary->conds, i, &c); i++)
267 if (c->operand_num == operand_num
268 && c->code == code
269 && c->val == val
270 && c->agg_contents == agg_contents
271 && (!agg_contents || (c->offset == offset && c->by_ref == by_ref)))
272 return single_cond_predicate (i + predicate_first_dynamic_condition);
274 /* Too many conditions. Give up and return constant true. */
275 if (i == NUM_CONDITIONS - predicate_first_dynamic_condition)
276 return true_predicate ();
278 new_cond.operand_num = operand_num;
279 new_cond.code = code;
280 new_cond.val = val;
281 new_cond.agg_contents = agg_contents;
282 new_cond.by_ref = by_ref;
283 new_cond.offset = offset;
284 vec_safe_push (summary->conds, new_cond);
285 return single_cond_predicate (i + predicate_first_dynamic_condition);
289 /* Add clause CLAUSE into the predicate P. */
291 static inline void
292 add_clause (conditions conditions, struct predicate *p, clause_t clause)
294 int i;
295 int i2;
296 int insert_here = -1;
297 int c1, c2;
299 /* True clause. */
300 if (!clause)
301 return;
303 /* False clause makes the whole predicate false. Kill the other variants. */
304 if (clause == (1 << predicate_false_condition))
306 p->clause[0] = (1 << predicate_false_condition);
307 p->clause[1] = 0;
308 return;
310 if (false_predicate_p (p))
311 return;
313 /* No one should be silly enough to add false into nontrivial clauses. */
314 gcc_checking_assert (!(clause & (1 << predicate_false_condition)));
316 /* Look where to insert the clause. At the same time prune out
317 clauses of P that are implied by the new clause and thus
318 redundant. */
319 for (i = 0, i2 = 0; i <= MAX_CLAUSES; i++)
321 p->clause[i2] = p->clause[i];
323 if (!p->clause[i])
324 break;
326 /* If p->clause[i] implies clause, there is nothing to add. */
327 if ((p->clause[i] & clause) == p->clause[i])
329 /* We had nothing to add, none of clauses should've become
330 redundant. */
331 gcc_checking_assert (i == i2);
332 return;
335 if (p->clause[i] < clause && insert_here < 0)
336 insert_here = i2;
338 /* If clause implies p->clause[i], then p->clause[i] becomes redundant.
339 Otherwise the p->clause[i] has to stay. */
340 if ((p->clause[i] & clause) != clause)
341 i2++;
344 /* Look for clauses that are obviously true. I.e.
345 op0 == 5 || op0 != 5. */
346 for (c1 = predicate_first_dynamic_condition; c1 < NUM_CONDITIONS; c1++)
348 condition *cc1;
349 if (!(clause & (1 << c1)))
350 continue;
351 cc1 = &(*conditions)[c1 - predicate_first_dynamic_condition];
352 /* We have no way to represent !CHANGED and !IS_NOT_CONSTANT
353 and thus there is no point for looking for them. */
354 if (cc1->code == CHANGED || cc1->code == IS_NOT_CONSTANT)
355 continue;
356 for (c2 = c1 + 1; c2 < NUM_CONDITIONS; c2++)
357 if (clause & (1 << c2))
359 condition *cc1 =
360 &(*conditions)[c1 - predicate_first_dynamic_condition];
361 condition *cc2 =
362 &(*conditions)[c2 - predicate_first_dynamic_condition];
363 if (cc1->operand_num == cc2->operand_num
364 && cc1->val == cc2->val
365 && cc2->code != IS_NOT_CONSTANT
366 && cc2->code != CHANGED
367 && cc1->code == invert_tree_comparison
368 (cc2->code,
369 HONOR_NANS (TYPE_MODE (TREE_TYPE (cc1->val)))))
370 return;
375 /* We run out of variants. Be conservative in positive direction. */
376 if (i2 == MAX_CLAUSES)
377 return;
378 /* Keep clauses in decreasing order. This makes equivalence testing easy. */
379 p->clause[i2 + 1] = 0;
380 if (insert_here >= 0)
381 for (; i2 > insert_here; i2--)
382 p->clause[i2] = p->clause[i2 - 1];
383 else
384 insert_here = i2;
385 p->clause[insert_here] = clause;
389 /* Return P & P2. */
391 static struct predicate
392 and_predicates (conditions conditions,
393 struct predicate *p, struct predicate *p2)
395 struct predicate out = *p;
396 int i;
398 /* Avoid busy work. */
399 if (false_predicate_p (p2) || true_predicate_p (p))
400 return *p2;
401 if (false_predicate_p (p) || true_predicate_p (p2))
402 return *p;
404 /* See how far predicates match. */
405 for (i = 0; p->clause[i] && p->clause[i] == p2->clause[i]; i++)
407 gcc_checking_assert (i < MAX_CLAUSES);
410 /* Combine the predicates rest. */
411 for (; p2->clause[i]; i++)
413 gcc_checking_assert (i < MAX_CLAUSES);
414 add_clause (conditions, &out, p2->clause[i]);
416 return out;
420 /* Return true if predicates are obviously equal. */
422 static inline bool
423 predicates_equal_p (struct predicate *p, struct predicate *p2)
425 int i;
426 for (i = 0; p->clause[i]; i++)
428 gcc_checking_assert (i < MAX_CLAUSES);
429 gcc_checking_assert (p->clause[i] > p->clause[i + 1]);
430 gcc_checking_assert (!p2->clause[i]
431 || p2->clause[i] > p2->clause[i + 1]);
432 if (p->clause[i] != p2->clause[i])
433 return false;
435 return !p2->clause[i];
439 /* Return P | P2. */
441 static struct predicate
442 or_predicates (conditions conditions,
443 struct predicate *p, struct predicate *p2)
445 struct predicate out = true_predicate ();
446 int i, j;
448 /* Avoid busy work. */
449 if (false_predicate_p (p2) || true_predicate_p (p))
450 return *p;
451 if (false_predicate_p (p) || true_predicate_p (p2))
452 return *p2;
453 if (predicates_equal_p (p, p2))
454 return *p;
456 /* OK, combine the predicates. */
457 for (i = 0; p->clause[i]; i++)
458 for (j = 0; p2->clause[j]; j++)
460 gcc_checking_assert (i < MAX_CLAUSES && j < MAX_CLAUSES);
461 add_clause (conditions, &out, p->clause[i] | p2->clause[j]);
463 return out;
467 /* Having partial truth assignment in POSSIBLE_TRUTHS, return false
468 if predicate P is known to be false. */
470 static bool
471 evaluate_predicate (struct predicate *p, clause_t possible_truths)
473 int i;
475 /* True remains true. */
476 if (true_predicate_p (p))
477 return true;
479 gcc_assert (!(possible_truths & (1 << predicate_false_condition)));
481 /* See if we can find clause we can disprove. */
482 for (i = 0; p->clause[i]; i++)
484 gcc_checking_assert (i < MAX_CLAUSES);
485 if (!(p->clause[i] & possible_truths))
486 return false;
488 return true;
491 /* Return the probability in range 0...REG_BR_PROB_BASE that the predicated
492 instruction will be recomputed per invocation of the inlined call. */
494 static int
495 predicate_probability (conditions conds,
496 struct predicate *p, clause_t possible_truths,
497 vec<inline_param_summary> inline_param_summary)
499 int i;
500 int combined_prob = REG_BR_PROB_BASE;
502 /* True remains true. */
503 if (true_predicate_p (p))
504 return REG_BR_PROB_BASE;
506 if (false_predicate_p (p))
507 return 0;
509 gcc_assert (!(possible_truths & (1 << predicate_false_condition)));
511 /* See if we can find clause we can disprove. */
512 for (i = 0; p->clause[i]; i++)
514 gcc_checking_assert (i < MAX_CLAUSES);
515 if (!(p->clause[i] & possible_truths))
516 return 0;
517 else
519 int this_prob = 0;
520 int i2;
521 if (!inline_param_summary.exists ())
522 return REG_BR_PROB_BASE;
523 for (i2 = 0; i2 < NUM_CONDITIONS; i2++)
524 if ((p->clause[i] & possible_truths) & (1 << i2))
526 if (i2 >= predicate_first_dynamic_condition)
528 condition *c =
529 &(*conds)[i2 - predicate_first_dynamic_condition];
530 if (c->code == CHANGED
531 && (c->operand_num <
532 (int) inline_param_summary.length ()))
534 int iprob =
535 inline_param_summary[c->operand_num].change_prob;
536 this_prob = MAX (this_prob, iprob);
538 else
539 this_prob = REG_BR_PROB_BASE;
541 else
542 this_prob = REG_BR_PROB_BASE;
544 combined_prob = MIN (this_prob, combined_prob);
545 if (!combined_prob)
546 return 0;
549 return combined_prob;
553 /* Dump conditional COND. */
555 static void
556 dump_condition (FILE *f, conditions conditions, int cond)
558 condition *c;
559 if (cond == predicate_false_condition)
560 fprintf (f, "false");
561 else if (cond == predicate_not_inlined_condition)
562 fprintf (f, "not inlined");
563 else
565 c = &(*conditions)[cond - predicate_first_dynamic_condition];
566 fprintf (f, "op%i", c->operand_num);
567 if (c->agg_contents)
568 fprintf (f, "[%soffset: " HOST_WIDE_INT_PRINT_DEC "]",
569 c->by_ref ? "ref " : "", c->offset);
570 if (c->code == IS_NOT_CONSTANT)
572 fprintf (f, " not constant");
573 return;
575 if (c->code == CHANGED)
577 fprintf (f, " changed");
578 return;
580 fprintf (f, " %s ", op_symbol_code (c->code));
581 print_generic_expr (f, c->val, 1);
586 /* Dump clause CLAUSE. */
588 static void
589 dump_clause (FILE *f, conditions conds, clause_t clause)
591 int i;
592 bool found = false;
593 fprintf (f, "(");
594 if (!clause)
595 fprintf (f, "true");
596 for (i = 0; i < NUM_CONDITIONS; i++)
597 if (clause & (1 << i))
599 if (found)
600 fprintf (f, " || ");
601 found = true;
602 dump_condition (f, conds, i);
604 fprintf (f, ")");
608 /* Dump predicate PREDICATE. */
610 static void
611 dump_predicate (FILE *f, conditions conds, struct predicate *pred)
613 int i;
614 if (true_predicate_p (pred))
615 dump_clause (f, conds, 0);
616 else
617 for (i = 0; pred->clause[i]; i++)
619 if (i)
620 fprintf (f, " && ");
621 dump_clause (f, conds, pred->clause[i]);
623 fprintf (f, "\n");
627 /* Dump inline hints. */
628 void
629 dump_inline_hints (FILE *f, inline_hints hints)
631 if (!hints)
632 return;
633 fprintf (f, "inline hints:");
634 if (hints & INLINE_HINT_indirect_call)
636 hints &= ~INLINE_HINT_indirect_call;
637 fprintf (f, " indirect_call");
639 if (hints & INLINE_HINT_loop_iterations)
641 hints &= ~INLINE_HINT_loop_iterations;
642 fprintf (f, " loop_iterations");
644 if (hints & INLINE_HINT_loop_stride)
646 hints &= ~INLINE_HINT_loop_stride;
647 fprintf (f, " loop_stride");
649 if (hints & INLINE_HINT_same_scc)
651 hints &= ~INLINE_HINT_same_scc;
652 fprintf (f, " same_scc");
654 if (hints & INLINE_HINT_in_scc)
656 hints &= ~INLINE_HINT_in_scc;
657 fprintf (f, " in_scc");
659 if (hints & INLINE_HINT_cross_module)
661 hints &= ~INLINE_HINT_cross_module;
662 fprintf (f, " cross_module");
664 if (hints & INLINE_HINT_declared_inline)
666 hints &= ~INLINE_HINT_declared_inline;
667 fprintf (f, " declared_inline");
669 if (hints & INLINE_HINT_array_index)
671 hints &= ~INLINE_HINT_array_index;
672 fprintf (f, " array_index");
674 if (hints & INLINE_HINT_known_hot)
676 hints &= ~INLINE_HINT_known_hot;
677 fprintf (f, " known_hot");
679 gcc_assert (!hints);
683 /* Record SIZE and TIME under condition PRED into the inline summary. */
685 static void
686 account_size_time (struct inline_summary *summary, int size, int time,
687 struct predicate *pred)
689 size_time_entry *e;
690 bool found = false;
691 int i;
693 if (false_predicate_p (pred))
694 return;
696 /* We need to create initial empty unconitional clause, but otherwie
697 we don't need to account empty times and sizes. */
698 if (!size && !time && summary->entry)
699 return;
701 /* Watch overflow that might result from insane profiles. */
702 if (time > MAX_TIME * INLINE_TIME_SCALE)
703 time = MAX_TIME * INLINE_TIME_SCALE;
704 gcc_assert (time >= 0);
706 for (i = 0; vec_safe_iterate (summary->entry, i, &e); i++)
707 if (predicates_equal_p (&e->predicate, pred))
709 found = true;
710 break;
712 if (i == 256)
714 i = 0;
715 found = true;
716 e = &(*summary->entry)[0];
717 gcc_assert (!e->predicate.clause[0]);
718 if (dump_file && (dump_flags & TDF_DETAILS))
719 fprintf (dump_file,
720 "\t\tReached limit on number of entries, "
721 "ignoring the predicate.");
723 if (dump_file && (dump_flags & TDF_DETAILS) && (time || size))
725 fprintf (dump_file,
726 "\t\tAccounting size:%3.2f, time:%3.2f on %spredicate:",
727 ((double) size) / INLINE_SIZE_SCALE,
728 ((double) time) / INLINE_TIME_SCALE, found ? "" : "new ");
729 dump_predicate (dump_file, summary->conds, pred);
731 if (!found)
733 struct size_time_entry new_entry;
734 new_entry.size = size;
735 new_entry.time = time;
736 new_entry.predicate = *pred;
737 vec_safe_push (summary->entry, new_entry);
739 else
741 e->size += size;
742 e->time += time;
743 if (e->time > MAX_TIME * INLINE_TIME_SCALE)
744 e->time = MAX_TIME * INLINE_TIME_SCALE;
748 /* Set predicate for edge E. */
750 static void
751 edge_set_predicate (struct cgraph_edge *e, struct predicate *predicate)
753 struct inline_edge_summary *es = inline_edge_summary (e);
755 /* If the edge is determined to be never executed, redirect it
756 to BUILTIN_UNREACHABLE to save inliner from inlining into it. */
757 if (predicate && false_predicate_p (predicate) && e->callee)
759 struct cgraph_node *callee = !e->inline_failed ? e->callee : NULL;
761 cgraph_redirect_edge_callee (e,
762 cgraph_get_create_node
763 (builtin_decl_implicit (BUILT_IN_UNREACHABLE)));
764 e->inline_failed = CIF_UNREACHABLE;
765 if (callee)
766 cgraph_remove_node_and_inline_clones (callee, NULL);
768 if (predicate && !true_predicate_p (predicate))
770 if (!es->predicate)
771 es->predicate = (struct predicate *) pool_alloc (edge_predicate_pool);
772 *es->predicate = *predicate;
774 else
776 if (es->predicate)
777 pool_free (edge_predicate_pool, es->predicate);
778 es->predicate = NULL;
782 /* Set predicate for hint *P. */
784 static void
785 set_hint_predicate (struct predicate **p, struct predicate new_predicate)
787 if (false_predicate_p (&new_predicate) || true_predicate_p (&new_predicate))
789 if (*p)
790 pool_free (edge_predicate_pool, *p);
791 *p = NULL;
793 else
795 if (!*p)
796 *p = (struct predicate *) pool_alloc (edge_predicate_pool);
797 **p = new_predicate;
802 /* KNOWN_VALS is partial mapping of parameters of NODE to constant values.
803 KNOWN_AGGS is a vector of aggreggate jump functions for each parameter.
804 Return clause of possible truths. When INLINE_P is true, assume that we are
805 inlining.
807 ERROR_MARK means compile time invariant. */
809 static clause_t
810 evaluate_conditions_for_known_args (struct cgraph_node *node,
811 bool inline_p,
812 vec<tree> known_vals,
813 vec<ipa_agg_jump_function_p>
814 known_aggs)
816 clause_t clause = inline_p ? 0 : 1 << predicate_not_inlined_condition;
817 struct inline_summary *info = inline_summary (node);
818 int i;
819 struct condition *c;
821 for (i = 0; vec_safe_iterate (info->conds, i, &c); i++)
823 tree val;
824 tree res;
826 /* We allow call stmt to have fewer arguments than the callee function
827 (especially for K&R style programs). So bound check here (we assume
828 known_aggs vector, if non-NULL, has the same length as
829 known_vals). */
830 gcc_checking_assert (!known_aggs.exists ()
831 || (known_vals.length () == known_aggs.length ()));
832 if (c->operand_num >= (int) known_vals.length ())
834 clause |= 1 << (i + predicate_first_dynamic_condition);
835 continue;
838 if (c->agg_contents)
840 struct ipa_agg_jump_function *agg;
842 if (c->code == CHANGED
843 && !c->by_ref
844 && (known_vals[c->operand_num] == error_mark_node))
845 continue;
847 if (known_aggs.exists ())
849 agg = known_aggs[c->operand_num];
850 val = ipa_find_agg_cst_for_param (agg, c->offset, c->by_ref);
852 else
853 val = NULL_TREE;
855 else
857 val = known_vals[c->operand_num];
858 if (val == error_mark_node && c->code != CHANGED)
859 val = NULL_TREE;
862 if (!val)
864 clause |= 1 << (i + predicate_first_dynamic_condition);
865 continue;
867 if (c->code == IS_NOT_CONSTANT || c->code == CHANGED)
868 continue;
869 res = fold_binary_to_constant (c->code, boolean_type_node, val, c->val);
870 if (res && integer_zerop (res))
871 continue;
872 clause |= 1 << (i + predicate_first_dynamic_condition);
874 return clause;
878 /* Work out what conditions might be true at invocation of E. */
880 static void
881 evaluate_properties_for_edge (struct cgraph_edge *e, bool inline_p,
882 clause_t *clause_ptr,
883 vec<tree> *known_vals_ptr,
884 vec<tree> *known_binfos_ptr,
885 vec<ipa_agg_jump_function_p> *known_aggs_ptr)
887 struct cgraph_node *callee =
888 cgraph_function_or_thunk_node (e->callee, NULL);
889 struct inline_summary *info = inline_summary (callee);
890 vec<tree> known_vals = vNULL;
891 vec<ipa_agg_jump_function_p> known_aggs = vNULL;
893 if (clause_ptr)
894 *clause_ptr = inline_p ? 0 : 1 << predicate_not_inlined_condition;
895 if (known_vals_ptr)
896 known_vals_ptr->create (0);
897 if (known_binfos_ptr)
898 known_binfos_ptr->create (0);
900 if (ipa_node_params_vector.exists ()
901 && !e->call_stmt_cannot_inline_p
902 && ((clause_ptr && info->conds) || known_vals_ptr || known_binfos_ptr))
904 struct ipa_node_params *parms_info;
905 struct ipa_edge_args *args = IPA_EDGE_REF (e);
906 struct inline_edge_summary *es = inline_edge_summary (e);
907 int i, count = ipa_get_cs_argument_count (args);
909 if (e->caller->global.inlined_to)
910 parms_info = IPA_NODE_REF (e->caller->global.inlined_to);
911 else
912 parms_info = IPA_NODE_REF (e->caller);
914 if (count && (info->conds || known_vals_ptr))
915 known_vals.safe_grow_cleared (count);
916 if (count && (info->conds || known_aggs_ptr))
917 known_aggs.safe_grow_cleared (count);
918 if (count && known_binfos_ptr)
919 known_binfos_ptr->safe_grow_cleared (count);
921 for (i = 0; i < count; i++)
923 struct ipa_jump_func *jf = ipa_get_ith_jump_func (args, i);
924 tree cst = ipa_value_from_jfunc (parms_info, jf);
925 if (cst)
927 if (known_vals.exists () && TREE_CODE (cst) != TREE_BINFO)
928 known_vals[i] = cst;
929 else if (known_binfos_ptr != NULL
930 && TREE_CODE (cst) == TREE_BINFO)
931 (*known_binfos_ptr)[i] = cst;
933 else if (inline_p && !es->param[i].change_prob)
934 known_vals[i] = error_mark_node;
935 /* TODO: When IPA-CP starts propagating and merging aggregate jump
936 functions, use its knowledge of the caller too, just like the
937 scalar case above. */
938 known_aggs[i] = &jf->agg;
942 if (clause_ptr)
943 *clause_ptr = evaluate_conditions_for_known_args (callee, inline_p,
944 known_vals, known_aggs);
946 if (known_vals_ptr)
947 *known_vals_ptr = known_vals;
948 else
949 known_vals.release ();
951 if (known_aggs_ptr)
952 *known_aggs_ptr = known_aggs;
953 else
954 known_aggs.release ();
958 /* Allocate the inline summary vector or resize it to cover all cgraph nodes. */
960 static void
961 inline_summary_alloc (void)
963 if (!node_removal_hook_holder)
964 node_removal_hook_holder =
965 cgraph_add_node_removal_hook (&inline_node_removal_hook, NULL);
966 if (!edge_removal_hook_holder)
967 edge_removal_hook_holder =
968 cgraph_add_edge_removal_hook (&inline_edge_removal_hook, NULL);
969 if (!node_duplication_hook_holder)
970 node_duplication_hook_holder =
971 cgraph_add_node_duplication_hook (&inline_node_duplication_hook, NULL);
972 if (!edge_duplication_hook_holder)
973 edge_duplication_hook_holder =
974 cgraph_add_edge_duplication_hook (&inline_edge_duplication_hook, NULL);
976 if (vec_safe_length (inline_summary_vec) <= (unsigned) cgraph_max_uid)
977 vec_safe_grow_cleared (inline_summary_vec, cgraph_max_uid + 1);
978 if (inline_edge_summary_vec.length () <= (unsigned) cgraph_edge_max_uid)
979 inline_edge_summary_vec.safe_grow_cleared (cgraph_edge_max_uid + 1);
980 if (!edge_predicate_pool)
981 edge_predicate_pool = create_alloc_pool ("edge predicates",
982 sizeof (struct predicate), 10);
985 /* We are called multiple time for given function; clear
986 data from previous run so they are not cumulated. */
988 static void
989 reset_inline_edge_summary (struct cgraph_edge *e)
991 if (e->uid < (int) inline_edge_summary_vec.length ())
993 struct inline_edge_summary *es = inline_edge_summary (e);
995 es->call_stmt_size = es->call_stmt_time = 0;
996 if (es->predicate)
997 pool_free (edge_predicate_pool, es->predicate);
998 es->predicate = NULL;
999 es->param.release ();
1003 /* We are called multiple time for given function; clear
1004 data from previous run so they are not cumulated. */
1006 static void
1007 reset_inline_summary (struct cgraph_node *node)
1009 struct inline_summary *info = inline_summary (node);
1010 struct cgraph_edge *e;
1012 info->self_size = info->self_time = 0;
1013 info->estimated_stack_size = 0;
1014 info->estimated_self_stack_size = 0;
1015 info->stack_frame_offset = 0;
1016 info->size = 0;
1017 info->time = 0;
1018 info->growth = 0;
1019 info->scc_no = 0;
1020 if (info->loop_iterations)
1022 pool_free (edge_predicate_pool, info->loop_iterations);
1023 info->loop_iterations = NULL;
1025 if (info->loop_stride)
1027 pool_free (edge_predicate_pool, info->loop_stride);
1028 info->loop_stride = NULL;
1030 if (info->array_index)
1032 pool_free (edge_predicate_pool, info->array_index);
1033 info->array_index = NULL;
1035 vec_free (info->conds);
1036 vec_free (info->entry);
1037 for (e = node->callees; e; e = e->next_callee)
1038 reset_inline_edge_summary (e);
1039 for (e = node->indirect_calls; e; e = e->next_callee)
1040 reset_inline_edge_summary (e);
1043 /* Hook that is called by cgraph.c when a node is removed. */
1045 static void
1046 inline_node_removal_hook (struct cgraph_node *node,
1047 void *data ATTRIBUTE_UNUSED)
1049 struct inline_summary *info;
1050 if (vec_safe_length (inline_summary_vec) <= (unsigned) node->uid)
1051 return;
1052 info = inline_summary (node);
1053 reset_inline_summary (node);
1054 memset (info, 0, sizeof (inline_summary_t));
1057 /* Remap predicate P of former function to be predicate of duplicated function.
1058 POSSIBLE_TRUTHS is clause of possible truths in the duplicated node,
1059 INFO is inline summary of the duplicated node. */
1061 static struct predicate
1062 remap_predicate_after_duplication (struct predicate *p,
1063 clause_t possible_truths,
1064 struct inline_summary *info)
1066 struct predicate new_predicate = true_predicate ();
1067 int j;
1068 for (j = 0; p->clause[j]; j++)
1069 if (!(possible_truths & p->clause[j]))
1071 new_predicate = false_predicate ();
1072 break;
1074 else
1075 add_clause (info->conds, &new_predicate,
1076 possible_truths & p->clause[j]);
1077 return new_predicate;
1080 /* Same as remap_predicate_after_duplication but handle hint predicate *P.
1081 Additionally care about allocating new memory slot for updated predicate
1082 and set it to NULL when it becomes true or false (and thus uninteresting).
1085 static void
1086 remap_hint_predicate_after_duplication (struct predicate **p,
1087 clause_t possible_truths,
1088 struct inline_summary *info)
1090 struct predicate new_predicate;
1092 if (!*p)
1093 return;
1095 new_predicate = remap_predicate_after_duplication (*p,
1096 possible_truths, info);
1097 /* We do not want to free previous predicate; it is used by node origin. */
1098 *p = NULL;
1099 set_hint_predicate (p, new_predicate);
1103 /* Hook that is called by cgraph.c when a node is duplicated. */
1105 static void
1106 inline_node_duplication_hook (struct cgraph_node *src,
1107 struct cgraph_node *dst,
1108 ATTRIBUTE_UNUSED void *data)
1110 struct inline_summary *info;
1111 inline_summary_alloc ();
1112 info = inline_summary (dst);
1113 memcpy (info, inline_summary (src), sizeof (struct inline_summary));
1114 /* TODO: as an optimization, we may avoid copying conditions
1115 that are known to be false or true. */
1116 info->conds = vec_safe_copy (info->conds);
1118 /* When there are any replacements in the function body, see if we can figure
1119 out that something was optimized out. */
1120 if (ipa_node_params_vector.exists () && dst->clone.tree_map)
1122 vec<size_time_entry, va_gc> *entry = info->entry;
1123 /* Use SRC parm info since it may not be copied yet. */
1124 struct ipa_node_params *parms_info = IPA_NODE_REF (src);
1125 vec<tree> known_vals = vNULL;
1126 int count = ipa_get_param_count (parms_info);
1127 int i, j;
1128 clause_t possible_truths;
1129 struct predicate true_pred = true_predicate ();
1130 size_time_entry *e;
1131 int optimized_out_size = 0;
1132 bool inlined_to_p = false;
1133 struct cgraph_edge *edge;
1135 info->entry = 0;
1136 known_vals.safe_grow_cleared (count);
1137 for (i = 0; i < count; i++)
1139 struct ipa_replace_map *r;
1141 for (j = 0; vec_safe_iterate (dst->clone.tree_map, j, &r); j++)
1143 if (((!r->old_tree && r->parm_num == i)
1144 || (r->old_tree && r->old_tree == ipa_get_param (parms_info, i)))
1145 && r->replace_p && !r->ref_p)
1147 known_vals[i] = r->new_tree;
1148 break;
1152 possible_truths = evaluate_conditions_for_known_args (dst, false,
1153 known_vals,
1154 vNULL);
1155 known_vals.release ();
1157 account_size_time (info, 0, 0, &true_pred);
1159 /* Remap size_time vectors.
1160 Simplify the predicate by prunning out alternatives that are known
1161 to be false.
1162 TODO: as on optimization, we can also eliminate conditions known
1163 to be true. */
1164 for (i = 0; vec_safe_iterate (entry, i, &e); i++)
1166 struct predicate new_predicate;
1167 new_predicate = remap_predicate_after_duplication (&e->predicate,
1168 possible_truths,
1169 info);
1170 if (false_predicate_p (&new_predicate))
1171 optimized_out_size += e->size;
1172 else
1173 account_size_time (info, e->size, e->time, &new_predicate);
1176 /* Remap edge predicates with the same simplification as above.
1177 Also copy constantness arrays. */
1178 for (edge = dst->callees; edge; edge = edge->next_callee)
1180 struct predicate new_predicate;
1181 struct inline_edge_summary *es = inline_edge_summary (edge);
1183 if (!edge->inline_failed)
1184 inlined_to_p = true;
1185 if (!es->predicate)
1186 continue;
1187 new_predicate = remap_predicate_after_duplication (es->predicate,
1188 possible_truths,
1189 info);
1190 if (false_predicate_p (&new_predicate)
1191 && !false_predicate_p (es->predicate))
1193 optimized_out_size += es->call_stmt_size * INLINE_SIZE_SCALE;
1194 edge->frequency = 0;
1196 edge_set_predicate (edge, &new_predicate);
1199 /* Remap indirect edge predicates with the same simplificaiton as above.
1200 Also copy constantness arrays. */
1201 for (edge = dst->indirect_calls; edge; edge = edge->next_callee)
1203 struct predicate new_predicate;
1204 struct inline_edge_summary *es = inline_edge_summary (edge);
1206 gcc_checking_assert (edge->inline_failed);
1207 if (!es->predicate)
1208 continue;
1209 new_predicate = remap_predicate_after_duplication (es->predicate,
1210 possible_truths,
1211 info);
1212 if (false_predicate_p (&new_predicate)
1213 && !false_predicate_p (es->predicate))
1215 optimized_out_size += es->call_stmt_size * INLINE_SIZE_SCALE;
1216 edge->frequency = 0;
1218 edge_set_predicate (edge, &new_predicate);
1220 remap_hint_predicate_after_duplication (&info->loop_iterations,
1221 possible_truths, info);
1222 remap_hint_predicate_after_duplication (&info->loop_stride,
1223 possible_truths, info);
1224 remap_hint_predicate_after_duplication (&info->array_index,
1225 possible_truths, info);
1227 /* If inliner or someone after inliner will ever start producing
1228 non-trivial clones, we will get trouble with lack of information
1229 about updating self sizes, because size vectors already contains
1230 sizes of the calees. */
1231 gcc_assert (!inlined_to_p || !optimized_out_size);
1233 else
1235 info->entry = vec_safe_copy (info->entry);
1236 if (info->loop_iterations)
1238 predicate p = *info->loop_iterations;
1239 info->loop_iterations = NULL;
1240 set_hint_predicate (&info->loop_iterations, p);
1242 if (info->loop_stride)
1244 predicate p = *info->loop_stride;
1245 info->loop_stride = NULL;
1246 set_hint_predicate (&info->loop_stride, p);
1248 if (info->array_index)
1250 predicate p = *info->array_index;
1251 info->array_index = NULL;
1252 set_hint_predicate (&info->array_index, p);
1255 inline_update_overall_summary (dst);
1259 /* Hook that is called by cgraph.c when a node is duplicated. */
1261 static void
1262 inline_edge_duplication_hook (struct cgraph_edge *src,
1263 struct cgraph_edge *dst,
1264 ATTRIBUTE_UNUSED void *data)
1266 struct inline_edge_summary *info;
1267 struct inline_edge_summary *srcinfo;
1268 inline_summary_alloc ();
1269 info = inline_edge_summary (dst);
1270 srcinfo = inline_edge_summary (src);
1271 memcpy (info, srcinfo, sizeof (struct inline_edge_summary));
1272 info->predicate = NULL;
1273 edge_set_predicate (dst, srcinfo->predicate);
1274 info->param = srcinfo->param.copy ();
1278 /* Keep edge cache consistent across edge removal. */
1280 static void
1281 inline_edge_removal_hook (struct cgraph_edge *edge,
1282 void *data ATTRIBUTE_UNUSED)
1284 if (edge_growth_cache.exists ())
1285 reset_edge_growth_cache (edge);
1286 reset_inline_edge_summary (edge);
1290 /* Initialize growth caches. */
1292 void
1293 initialize_growth_caches (void)
1295 if (cgraph_edge_max_uid)
1296 edge_growth_cache.safe_grow_cleared (cgraph_edge_max_uid);
1297 if (cgraph_max_uid)
1298 node_growth_cache.safe_grow_cleared (cgraph_max_uid);
1302 /* Free growth caches. */
1304 void
1305 free_growth_caches (void)
1307 edge_growth_cache.release ();
1308 node_growth_cache.release ();
1312 /* Dump edge summaries associated to NODE and recursively to all clones.
1313 Indent by INDENT. */
1315 static void
1316 dump_inline_edge_summary (FILE *f, int indent, struct cgraph_node *node,
1317 struct inline_summary *info)
1319 struct cgraph_edge *edge;
1320 for (edge = node->callees; edge; edge = edge->next_callee)
1322 struct inline_edge_summary *es = inline_edge_summary (edge);
1323 struct cgraph_node *callee =
1324 cgraph_function_or_thunk_node (edge->callee, NULL);
1325 int i;
1327 fprintf (f,
1328 "%*s%s/%i %s\n%*s loop depth:%2i freq:%4i size:%2i"
1329 " time: %2i callee size:%2i stack:%2i",
1330 indent, "", callee->name (), callee->order,
1331 !edge->inline_failed
1332 ? "inlined" : cgraph_inline_failed_string (edge-> inline_failed),
1333 indent, "", es->loop_depth, edge->frequency,
1334 es->call_stmt_size, es->call_stmt_time,
1335 (int) inline_summary (callee)->size / INLINE_SIZE_SCALE,
1336 (int) inline_summary (callee)->estimated_stack_size);
1338 if (es->predicate)
1340 fprintf (f, " predicate: ");
1341 dump_predicate (f, info->conds, es->predicate);
1343 else
1344 fprintf (f, "\n");
1345 if (es->param.exists ())
1346 for (i = 0; i < (int) es->param.length (); i++)
1348 int prob = es->param[i].change_prob;
1350 if (!prob)
1351 fprintf (f, "%*s op%i is compile time invariant\n",
1352 indent + 2, "", i);
1353 else if (prob != REG_BR_PROB_BASE)
1354 fprintf (f, "%*s op%i change %f%% of time\n", indent + 2, "", i,
1355 prob * 100.0 / REG_BR_PROB_BASE);
1357 if (!edge->inline_failed)
1359 fprintf (f, "%*sStack frame offset %i, callee self size %i,"
1360 " callee size %i\n",
1361 indent + 2, "",
1362 (int) inline_summary (callee)->stack_frame_offset,
1363 (int) inline_summary (callee)->estimated_self_stack_size,
1364 (int) inline_summary (callee)->estimated_stack_size);
1365 dump_inline_edge_summary (f, indent + 2, callee, info);
1368 for (edge = node->indirect_calls; edge; edge = edge->next_callee)
1370 struct inline_edge_summary *es = inline_edge_summary (edge);
1371 fprintf (f, "%*sindirect call loop depth:%2i freq:%4i size:%2i"
1372 " time: %2i",
1373 indent, "",
1374 es->loop_depth,
1375 edge->frequency, es->call_stmt_size, es->call_stmt_time);
1376 if (es->predicate)
1378 fprintf (f, "predicate: ");
1379 dump_predicate (f, info->conds, es->predicate);
1381 else
1382 fprintf (f, "\n");
1387 void
1388 dump_inline_summary (FILE *f, struct cgraph_node *node)
1390 if (node->definition)
1392 struct inline_summary *s = inline_summary (node);
1393 size_time_entry *e;
1394 int i;
1395 fprintf (f, "Inline summary for %s/%i", node->name (),
1396 node->order);
1397 if (DECL_DISREGARD_INLINE_LIMITS (node->decl))
1398 fprintf (f, " always_inline");
1399 if (s->inlinable)
1400 fprintf (f, " inlinable");
1401 fprintf (f, "\n self time: %i\n", s->self_time);
1402 fprintf (f, " global time: %i\n", s->time);
1403 fprintf (f, " self size: %i\n", s->self_size);
1404 fprintf (f, " global size: %i\n", s->size);
1405 fprintf (f, " min size: %i\n", s->min_size);
1406 fprintf (f, " self stack: %i\n",
1407 (int) s->estimated_self_stack_size);
1408 fprintf (f, " global stack: %i\n", (int) s->estimated_stack_size);
1409 if (s->growth)
1410 fprintf (f, " estimated growth:%i\n", (int) s->growth);
1411 if (s->scc_no)
1412 fprintf (f, " In SCC: %i\n", (int) s->scc_no);
1413 for (i = 0; vec_safe_iterate (s->entry, i, &e); i++)
1415 fprintf (f, " size:%f, time:%f, predicate:",
1416 (double) e->size / INLINE_SIZE_SCALE,
1417 (double) e->time / INLINE_TIME_SCALE);
1418 dump_predicate (f, s->conds, &e->predicate);
1420 if (s->loop_iterations)
1422 fprintf (f, " loop iterations:");
1423 dump_predicate (f, s->conds, s->loop_iterations);
1425 if (s->loop_stride)
1427 fprintf (f, " loop stride:");
1428 dump_predicate (f, s->conds, s->loop_stride);
1430 if (s->array_index)
1432 fprintf (f, " array index:");
1433 dump_predicate (f, s->conds, s->array_index);
1435 fprintf (f, " calls:\n");
1436 dump_inline_edge_summary (f, 4, node, s);
1437 fprintf (f, "\n");
1441 DEBUG_FUNCTION void
1442 debug_inline_summary (struct cgraph_node *node)
1444 dump_inline_summary (stderr, node);
1447 void
1448 dump_inline_summaries (FILE *f)
1450 struct cgraph_node *node;
1452 FOR_EACH_DEFINED_FUNCTION (node)
1453 if (!node->global.inlined_to)
1454 dump_inline_summary (f, node);
1457 /* Give initial reasons why inlining would fail on EDGE. This gets either
1458 nullified or usually overwritten by more precise reasons later. */
1460 void
1461 initialize_inline_failed (struct cgraph_edge *e)
1463 struct cgraph_node *callee = e->callee;
1465 if (e->indirect_unknown_callee)
1466 e->inline_failed = CIF_INDIRECT_UNKNOWN_CALL;
1467 else if (!callee->definition)
1468 e->inline_failed = CIF_BODY_NOT_AVAILABLE;
1469 else if (callee->local.redefined_extern_inline)
1470 e->inline_failed = CIF_REDEFINED_EXTERN_INLINE;
1471 else if (e->call_stmt_cannot_inline_p)
1472 e->inline_failed = CIF_MISMATCHED_ARGUMENTS;
1473 else if (cfun && fn_contains_cilk_spawn_p (cfun))
1474 /* We can't inline if the function is spawing a function. */
1475 e->inline_failed = CIF_FUNCTION_NOT_INLINABLE;
1476 else
1477 e->inline_failed = CIF_FUNCTION_NOT_CONSIDERED;
1480 /* Callback of walk_aliased_vdefs. Flags that it has been invoked to the
1481 boolean variable pointed to by DATA. */
1483 static bool
1484 mark_modified (ao_ref *ao ATTRIBUTE_UNUSED, tree vdef ATTRIBUTE_UNUSED,
1485 void *data)
1487 bool *b = (bool *) data;
1488 *b = true;
1489 return true;
1492 /* If OP refers to value of function parameter, return the corresponding
1493 parameter. */
1495 static tree
1496 unmodified_parm_1 (gimple stmt, tree op)
1498 /* SSA_NAME referring to parm default def? */
1499 if (TREE_CODE (op) == SSA_NAME
1500 && SSA_NAME_IS_DEFAULT_DEF (op)
1501 && TREE_CODE (SSA_NAME_VAR (op)) == PARM_DECL)
1502 return SSA_NAME_VAR (op);
1503 /* Non-SSA parm reference? */
1504 if (TREE_CODE (op) == PARM_DECL)
1506 bool modified = false;
1508 ao_ref refd;
1509 ao_ref_init (&refd, op);
1510 walk_aliased_vdefs (&refd, gimple_vuse (stmt), mark_modified, &modified,
1511 NULL);
1512 if (!modified)
1513 return op;
1515 return NULL_TREE;
1518 /* If OP refers to value of function parameter, return the corresponding
1519 parameter. Also traverse chains of SSA register assignments. */
1521 static tree
1522 unmodified_parm (gimple stmt, tree op)
1524 tree res = unmodified_parm_1 (stmt, op);
1525 if (res)
1526 return res;
1528 if (TREE_CODE (op) == SSA_NAME
1529 && !SSA_NAME_IS_DEFAULT_DEF (op)
1530 && gimple_assign_single_p (SSA_NAME_DEF_STMT (op)))
1531 return unmodified_parm (SSA_NAME_DEF_STMT (op),
1532 gimple_assign_rhs1 (SSA_NAME_DEF_STMT (op)));
1533 return NULL_TREE;
1536 /* If OP refers to a value of a function parameter or value loaded from an
1537 aggregate passed to a parameter (either by value or reference), return TRUE
1538 and store the number of the parameter to *INDEX_P and information whether
1539 and how it has been loaded from an aggregate into *AGGPOS. INFO describes
1540 the function parameters, STMT is the statement in which OP is used or
1541 loaded. */
1543 static bool
1544 unmodified_parm_or_parm_agg_item (struct ipa_node_params *info,
1545 gimple stmt, tree op, int *index_p,
1546 struct agg_position_info *aggpos)
1548 tree res = unmodified_parm_1 (stmt, op);
1550 gcc_checking_assert (aggpos);
1551 if (res)
1553 *index_p = ipa_get_param_decl_index (info, res);
1554 if (*index_p < 0)
1555 return false;
1556 aggpos->agg_contents = false;
1557 aggpos->by_ref = false;
1558 return true;
1561 if (TREE_CODE (op) == SSA_NAME)
1563 if (SSA_NAME_IS_DEFAULT_DEF (op)
1564 || !gimple_assign_single_p (SSA_NAME_DEF_STMT (op)))
1565 return false;
1566 stmt = SSA_NAME_DEF_STMT (op);
1567 op = gimple_assign_rhs1 (stmt);
1568 if (!REFERENCE_CLASS_P (op))
1569 return unmodified_parm_or_parm_agg_item (info, stmt, op, index_p,
1570 aggpos);
1573 aggpos->agg_contents = true;
1574 return ipa_load_from_parm_agg (info, stmt, op, index_p, &aggpos->offset,
1575 &aggpos->by_ref);
1578 /* See if statement might disappear after inlining.
1579 0 - means not eliminated
1580 1 - half of statements goes away
1581 2 - for sure it is eliminated.
1582 We are not terribly sophisticated, basically looking for simple abstraction
1583 penalty wrappers. */
1585 static int
1586 eliminated_by_inlining_prob (gimple stmt)
1588 enum gimple_code code = gimple_code (stmt);
1589 enum tree_code rhs_code;
1591 if (!optimize)
1592 return 0;
1594 switch (code)
1596 case GIMPLE_RETURN:
1597 return 2;
1598 case GIMPLE_ASSIGN:
1599 if (gimple_num_ops (stmt) != 2)
1600 return 0;
1602 rhs_code = gimple_assign_rhs_code (stmt);
1604 /* Casts of parameters, loads from parameters passed by reference
1605 and stores to return value or parameters are often free after
1606 inlining dua to SRA and further combining.
1607 Assume that half of statements goes away. */
1608 if (rhs_code == CONVERT_EXPR
1609 || rhs_code == NOP_EXPR
1610 || rhs_code == VIEW_CONVERT_EXPR
1611 || rhs_code == ADDR_EXPR
1612 || gimple_assign_rhs_class (stmt) == GIMPLE_SINGLE_RHS)
1614 tree rhs = gimple_assign_rhs1 (stmt);
1615 tree lhs = gimple_assign_lhs (stmt);
1616 tree inner_rhs = get_base_address (rhs);
1617 tree inner_lhs = get_base_address (lhs);
1618 bool rhs_free = false;
1619 bool lhs_free = false;
1621 if (!inner_rhs)
1622 inner_rhs = rhs;
1623 if (!inner_lhs)
1624 inner_lhs = lhs;
1626 /* Reads of parameter are expected to be free. */
1627 if (unmodified_parm (stmt, inner_rhs))
1628 rhs_free = true;
1629 /* Match expressions of form &this->field. Those will most likely
1630 combine with something upstream after inlining. */
1631 else if (TREE_CODE (inner_rhs) == ADDR_EXPR)
1633 tree op = get_base_address (TREE_OPERAND (inner_rhs, 0));
1634 if (TREE_CODE (op) == PARM_DECL)
1635 rhs_free = true;
1636 else if (TREE_CODE (op) == MEM_REF
1637 && unmodified_parm (stmt, TREE_OPERAND (op, 0)))
1638 rhs_free = true;
1641 /* When parameter is not SSA register because its address is taken
1642 and it is just copied into one, the statement will be completely
1643 free after inlining (we will copy propagate backward). */
1644 if (rhs_free && is_gimple_reg (lhs))
1645 return 2;
1647 /* Reads of parameters passed by reference
1648 expected to be free (i.e. optimized out after inlining). */
1649 if (TREE_CODE (inner_rhs) == MEM_REF
1650 && unmodified_parm (stmt, TREE_OPERAND (inner_rhs, 0)))
1651 rhs_free = true;
1653 /* Copying parameter passed by reference into gimple register is
1654 probably also going to copy propagate, but we can't be quite
1655 sure. */
1656 if (rhs_free && is_gimple_reg (lhs))
1657 lhs_free = true;
1659 /* Writes to parameters, parameters passed by value and return value
1660 (either dirrectly or passed via invisible reference) are free.
1662 TODO: We ought to handle testcase like
1663 struct a {int a,b;};
1664 struct a
1665 retrurnsturct (void)
1667 struct a a ={1,2};
1668 return a;
1671 This translate into:
1673 retrurnsturct ()
1675 int a$b;
1676 int a$a;
1677 struct a a;
1678 struct a D.2739;
1680 <bb 2>:
1681 D.2739.a = 1;
1682 D.2739.b = 2;
1683 return D.2739;
1686 For that we either need to copy ipa-split logic detecting writes
1687 to return value. */
1688 if (TREE_CODE (inner_lhs) == PARM_DECL
1689 || TREE_CODE (inner_lhs) == RESULT_DECL
1690 || (TREE_CODE (inner_lhs) == MEM_REF
1691 && (unmodified_parm (stmt, TREE_OPERAND (inner_lhs, 0))
1692 || (TREE_CODE (TREE_OPERAND (inner_lhs, 0)) == SSA_NAME
1693 && SSA_NAME_VAR (TREE_OPERAND (inner_lhs, 0))
1694 && TREE_CODE (SSA_NAME_VAR (TREE_OPERAND
1695 (inner_lhs,
1696 0))) == RESULT_DECL))))
1697 lhs_free = true;
1698 if (lhs_free
1699 && (is_gimple_reg (rhs) || is_gimple_min_invariant (rhs)))
1700 rhs_free = true;
1701 if (lhs_free && rhs_free)
1702 return 1;
1704 return 0;
1705 default:
1706 return 0;
1711 /* If BB ends by a conditional we can turn into predicates, attach corresponding
1712 predicates to the CFG edges. */
1714 static void
1715 set_cond_stmt_execution_predicate (struct ipa_node_params *info,
1716 struct inline_summary *summary,
1717 basic_block bb)
1719 gimple last;
1720 tree op;
1721 int index;
1722 struct agg_position_info aggpos;
1723 enum tree_code code, inverted_code;
1724 edge e;
1725 edge_iterator ei;
1726 gimple set_stmt;
1727 tree op2;
1729 last = last_stmt (bb);
1730 if (!last || gimple_code (last) != GIMPLE_COND)
1731 return;
1732 if (!is_gimple_ip_invariant (gimple_cond_rhs (last)))
1733 return;
1734 op = gimple_cond_lhs (last);
1735 /* TODO: handle conditionals like
1736 var = op0 < 4;
1737 if (var != 0). */
1738 if (unmodified_parm_or_parm_agg_item (info, last, op, &index, &aggpos))
1740 code = gimple_cond_code (last);
1741 inverted_code
1742 = invert_tree_comparison (code,
1743 HONOR_NANS (TYPE_MODE (TREE_TYPE (op))));
1745 FOR_EACH_EDGE (e, ei, bb->succs)
1747 enum tree_code this_code = (e->flags & EDGE_TRUE_VALUE
1748 ? code : inverted_code);
1749 /* invert_tree_comparison will return ERROR_MARK on FP
1750 comparsions that are not EQ/NE instead of returning proper
1751 unordered one. Be sure it is not confused with NON_CONSTANT. */
1752 if (this_code != ERROR_MARK)
1754 struct predicate p = add_condition (summary, index, &aggpos,
1755 this_code,
1756 gimple_cond_rhs (last));
1757 e->aux = pool_alloc (edge_predicate_pool);
1758 *(struct predicate *) e->aux = p;
1763 if (TREE_CODE (op) != SSA_NAME)
1764 return;
1765 /* Special case
1766 if (builtin_constant_p (op))
1767 constant_code
1768 else
1769 nonconstant_code.
1770 Here we can predicate nonconstant_code. We can't
1771 really handle constant_code since we have no predicate
1772 for this and also the constant code is not known to be
1773 optimized away when inliner doen't see operand is constant.
1774 Other optimizers might think otherwise. */
1775 if (gimple_cond_code (last) != NE_EXPR
1776 || !integer_zerop (gimple_cond_rhs (last)))
1777 return;
1778 set_stmt = SSA_NAME_DEF_STMT (op);
1779 if (!gimple_call_builtin_p (set_stmt, BUILT_IN_CONSTANT_P)
1780 || gimple_call_num_args (set_stmt) != 1)
1781 return;
1782 op2 = gimple_call_arg (set_stmt, 0);
1783 if (!unmodified_parm_or_parm_agg_item
1784 (info, set_stmt, op2, &index, &aggpos))
1785 return;
1786 FOR_EACH_EDGE (e, ei, bb->succs) if (e->flags & EDGE_FALSE_VALUE)
1788 struct predicate p = add_condition (summary, index, &aggpos,
1789 IS_NOT_CONSTANT, NULL_TREE);
1790 e->aux = pool_alloc (edge_predicate_pool);
1791 *(struct predicate *) e->aux = p;
1796 /* If BB ends by a switch we can turn into predicates, attach corresponding
1797 predicates to the CFG edges. */
1799 static void
1800 set_switch_stmt_execution_predicate (struct ipa_node_params *info,
1801 struct inline_summary *summary,
1802 basic_block bb)
1804 gimple last;
1805 tree op;
1806 int index;
1807 struct agg_position_info aggpos;
1808 edge e;
1809 edge_iterator ei;
1810 size_t n;
1811 size_t case_idx;
1813 last = last_stmt (bb);
1814 if (!last || gimple_code (last) != GIMPLE_SWITCH)
1815 return;
1816 op = gimple_switch_index (last);
1817 if (!unmodified_parm_or_parm_agg_item (info, last, op, &index, &aggpos))
1818 return;
1820 FOR_EACH_EDGE (e, ei, bb->succs)
1822 e->aux = pool_alloc (edge_predicate_pool);
1823 *(struct predicate *) e->aux = false_predicate ();
1825 n = gimple_switch_num_labels (last);
1826 for (case_idx = 0; case_idx < n; ++case_idx)
1828 tree cl = gimple_switch_label (last, case_idx);
1829 tree min, max;
1830 struct predicate p;
1832 e = find_edge (bb, label_to_block (CASE_LABEL (cl)));
1833 min = CASE_LOW (cl);
1834 max = CASE_HIGH (cl);
1836 /* For default we might want to construct predicate that none
1837 of cases is met, but it is bit hard to do not having negations
1838 of conditionals handy. */
1839 if (!min && !max)
1840 p = true_predicate ();
1841 else if (!max)
1842 p = add_condition (summary, index, &aggpos, EQ_EXPR, min);
1843 else
1845 struct predicate p1, p2;
1846 p1 = add_condition (summary, index, &aggpos, GE_EXPR, min);
1847 p2 = add_condition (summary, index, &aggpos, LE_EXPR, max);
1848 p = and_predicates (summary->conds, &p1, &p2);
1850 *(struct predicate *) e->aux
1851 = or_predicates (summary->conds, &p, (struct predicate *) e->aux);
1856 /* For each BB in NODE attach to its AUX pointer predicate under
1857 which it is executable. */
1859 static void
1860 compute_bb_predicates (struct cgraph_node *node,
1861 struct ipa_node_params *parms_info,
1862 struct inline_summary *summary)
1864 struct function *my_function = DECL_STRUCT_FUNCTION (node->decl);
1865 bool done = false;
1866 basic_block bb;
1868 FOR_EACH_BB_FN (bb, my_function)
1870 set_cond_stmt_execution_predicate (parms_info, summary, bb);
1871 set_switch_stmt_execution_predicate (parms_info, summary, bb);
1874 /* Entry block is always executable. */
1875 ENTRY_BLOCK_PTR_FOR_FN (my_function)->aux
1876 = pool_alloc (edge_predicate_pool);
1877 *(struct predicate *) ENTRY_BLOCK_PTR_FOR_FN (my_function)->aux
1878 = true_predicate ();
1880 /* A simple dataflow propagation of predicates forward in the CFG.
1881 TODO: work in reverse postorder. */
1882 while (!done)
1884 done = true;
1885 FOR_EACH_BB_FN (bb, my_function)
1887 struct predicate p = false_predicate ();
1888 edge e;
1889 edge_iterator ei;
1890 FOR_EACH_EDGE (e, ei, bb->preds)
1892 if (e->src->aux)
1894 struct predicate this_bb_predicate
1895 = *(struct predicate *) e->src->aux;
1896 if (e->aux)
1897 this_bb_predicate
1898 = and_predicates (summary->conds, &this_bb_predicate,
1899 (struct predicate *) e->aux);
1900 p = or_predicates (summary->conds, &p, &this_bb_predicate);
1901 if (true_predicate_p (&p))
1902 break;
1905 if (false_predicate_p (&p))
1906 gcc_assert (!bb->aux);
1907 else
1909 if (!bb->aux)
1911 done = false;
1912 bb->aux = pool_alloc (edge_predicate_pool);
1913 *((struct predicate *) bb->aux) = p;
1915 else if (!predicates_equal_p (&p, (struct predicate *) bb->aux))
1917 /* This OR operation is needed to ensure monotonous data flow
1918 in the case we hit the limit on number of clauses and the
1919 and/or operations above give approximate answers. */
1920 p = or_predicates (summary->conds, &p, (struct predicate *)bb->aux);
1921 if (!predicates_equal_p (&p, (struct predicate *) bb->aux))
1923 done = false;
1924 *((struct predicate *) bb->aux) = p;
1933 /* We keep info about constantness of SSA names. */
1935 typedef struct predicate predicate_t;
1936 /* Return predicate specifying when the STMT might have result that is not
1937 a compile time constant. */
1939 static struct predicate
1940 will_be_nonconstant_expr_predicate (struct ipa_node_params *info,
1941 struct inline_summary *summary,
1942 tree expr,
1943 vec<predicate_t> nonconstant_names)
1945 tree parm;
1946 int index;
1948 while (UNARY_CLASS_P (expr))
1949 expr = TREE_OPERAND (expr, 0);
1951 parm = unmodified_parm (NULL, expr);
1952 if (parm && (index = ipa_get_param_decl_index (info, parm)) >= 0)
1953 return add_condition (summary, index, NULL, CHANGED, NULL_TREE);
1954 if (is_gimple_min_invariant (expr))
1955 return false_predicate ();
1956 if (TREE_CODE (expr) == SSA_NAME)
1957 return nonconstant_names[SSA_NAME_VERSION (expr)];
1958 if (BINARY_CLASS_P (expr) || COMPARISON_CLASS_P (expr))
1960 struct predicate p1 = will_be_nonconstant_expr_predicate
1961 (info, summary, TREE_OPERAND (expr, 0),
1962 nonconstant_names);
1963 struct predicate p2;
1964 if (true_predicate_p (&p1))
1965 return p1;
1966 p2 = will_be_nonconstant_expr_predicate (info, summary,
1967 TREE_OPERAND (expr, 1),
1968 nonconstant_names);
1969 return or_predicates (summary->conds, &p1, &p2);
1971 else if (TREE_CODE (expr) == COND_EXPR)
1973 struct predicate p1 = will_be_nonconstant_expr_predicate
1974 (info, summary, TREE_OPERAND (expr, 0),
1975 nonconstant_names);
1976 struct predicate p2;
1977 if (true_predicate_p (&p1))
1978 return p1;
1979 p2 = will_be_nonconstant_expr_predicate (info, summary,
1980 TREE_OPERAND (expr, 1),
1981 nonconstant_names);
1982 if (true_predicate_p (&p2))
1983 return p2;
1984 p1 = or_predicates (summary->conds, &p1, &p2);
1985 p2 = will_be_nonconstant_expr_predicate (info, summary,
1986 TREE_OPERAND (expr, 2),
1987 nonconstant_names);
1988 return or_predicates (summary->conds, &p1, &p2);
1990 else
1992 debug_tree (expr);
1993 gcc_unreachable ();
1995 return false_predicate ();
1999 /* Return predicate specifying when the STMT might have result that is not
2000 a compile time constant. */
2002 static struct predicate
2003 will_be_nonconstant_predicate (struct ipa_node_params *info,
2004 struct inline_summary *summary,
2005 gimple stmt,
2006 vec<predicate_t> nonconstant_names)
2008 struct predicate p = true_predicate ();
2009 ssa_op_iter iter;
2010 tree use;
2011 struct predicate op_non_const;
2012 bool is_load;
2013 int base_index;
2014 struct agg_position_info aggpos;
2016 /* What statments might be optimized away
2017 when their arguments are constant
2018 TODO: also trivial builtins.
2019 builtin_constant_p is already handled later. */
2020 if (gimple_code (stmt) != GIMPLE_ASSIGN
2021 && gimple_code (stmt) != GIMPLE_COND
2022 && gimple_code (stmt) != GIMPLE_SWITCH)
2023 return p;
2025 /* Stores will stay anyway. */
2026 if (gimple_store_p (stmt))
2027 return p;
2029 is_load = gimple_assign_load_p (stmt);
2031 /* Loads can be optimized when the value is known. */
2032 if (is_load)
2034 tree op;
2035 gcc_assert (gimple_assign_single_p (stmt));
2036 op = gimple_assign_rhs1 (stmt);
2037 if (!unmodified_parm_or_parm_agg_item (info, stmt, op, &base_index,
2038 &aggpos))
2039 return p;
2041 else
2042 base_index = -1;
2044 /* See if we understand all operands before we start
2045 adding conditionals. */
2046 FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter, SSA_OP_USE)
2048 tree parm = unmodified_parm (stmt, use);
2049 /* For arguments we can build a condition. */
2050 if (parm && ipa_get_param_decl_index (info, parm) >= 0)
2051 continue;
2052 if (TREE_CODE (use) != SSA_NAME)
2053 return p;
2054 /* If we know when operand is constant,
2055 we still can say something useful. */
2056 if (!true_predicate_p (&nonconstant_names[SSA_NAME_VERSION (use)]))
2057 continue;
2058 return p;
2061 if (is_load)
2062 op_non_const =
2063 add_condition (summary, base_index, &aggpos, CHANGED, NULL);
2064 else
2065 op_non_const = false_predicate ();
2066 FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter, SSA_OP_USE)
2068 tree parm = unmodified_parm (stmt, use);
2069 int index;
2071 if (parm && (index = ipa_get_param_decl_index (info, parm)) >= 0)
2073 if (index != base_index)
2074 p = add_condition (summary, index, NULL, CHANGED, NULL_TREE);
2075 else
2076 continue;
2078 else
2079 p = nonconstant_names[SSA_NAME_VERSION (use)];
2080 op_non_const = or_predicates (summary->conds, &p, &op_non_const);
2082 if (gimple_code (stmt) == GIMPLE_ASSIGN
2083 && TREE_CODE (gimple_assign_lhs (stmt)) == SSA_NAME)
2084 nonconstant_names[SSA_NAME_VERSION (gimple_assign_lhs (stmt))]
2085 = op_non_const;
2086 return op_non_const;
2089 struct record_modified_bb_info
2091 bitmap bb_set;
2092 gimple stmt;
2095 /* Callback of walk_aliased_vdefs. Records basic blocks where the value may be
2096 set except for info->stmt. */
2098 static bool
2099 record_modified (ao_ref *ao ATTRIBUTE_UNUSED, tree vdef, void *data)
2101 struct record_modified_bb_info *info =
2102 (struct record_modified_bb_info *) data;
2103 if (SSA_NAME_DEF_STMT (vdef) == info->stmt)
2104 return false;
2105 bitmap_set_bit (info->bb_set,
2106 SSA_NAME_IS_DEFAULT_DEF (vdef)
2107 ? ENTRY_BLOCK_PTR_FOR_FN (cfun)->index
2108 : gimple_bb (SSA_NAME_DEF_STMT (vdef))->index);
2109 return false;
2112 /* Return probability (based on REG_BR_PROB_BASE) that I-th parameter of STMT
2113 will change since last invocation of STMT.
2115 Value 0 is reserved for compile time invariants.
2116 For common parameters it is REG_BR_PROB_BASE. For loop invariants it
2117 ought to be REG_BR_PROB_BASE / estimated_iters. */
2119 static int
2120 param_change_prob (gimple stmt, int i)
2122 tree op = gimple_call_arg (stmt, i);
2123 basic_block bb = gimple_bb (stmt);
2124 tree base;
2126 /* Global invariants neve change. */
2127 if (is_gimple_min_invariant (op))
2128 return 0;
2129 /* We would have to do non-trivial analysis to really work out what
2130 is the probability of value to change (i.e. when init statement
2131 is in a sibling loop of the call).
2133 We do an conservative estimate: when call is executed N times more often
2134 than the statement defining value, we take the frequency 1/N. */
2135 if (TREE_CODE (op) == SSA_NAME)
2137 int init_freq;
2139 if (!bb->frequency)
2140 return REG_BR_PROB_BASE;
2142 if (SSA_NAME_IS_DEFAULT_DEF (op))
2143 init_freq = ENTRY_BLOCK_PTR_FOR_FN (cfun)->frequency;
2144 else
2145 init_freq = gimple_bb (SSA_NAME_DEF_STMT (op))->frequency;
2147 if (!init_freq)
2148 init_freq = 1;
2149 if (init_freq < bb->frequency)
2150 return MAX (GCOV_COMPUTE_SCALE (init_freq, bb->frequency), 1);
2151 else
2152 return REG_BR_PROB_BASE;
2155 base = get_base_address (op);
2156 if (base)
2158 ao_ref refd;
2159 int max;
2160 struct record_modified_bb_info info;
2161 bitmap_iterator bi;
2162 unsigned index;
2163 tree init = ctor_for_folding (base);
2165 if (init != error_mark_node)
2166 return 0;
2167 if (!bb->frequency)
2168 return REG_BR_PROB_BASE;
2169 ao_ref_init (&refd, op);
2170 info.stmt = stmt;
2171 info.bb_set = BITMAP_ALLOC (NULL);
2172 walk_aliased_vdefs (&refd, gimple_vuse (stmt), record_modified, &info,
2173 NULL);
2174 if (bitmap_bit_p (info.bb_set, bb->index))
2176 BITMAP_FREE (info.bb_set);
2177 return REG_BR_PROB_BASE;
2180 /* Assume that every memory is initialized at entry.
2181 TODO: Can we easilly determine if value is always defined
2182 and thus we may skip entry block? */
2183 if (ENTRY_BLOCK_PTR_FOR_FN (cfun)->frequency)
2184 max = ENTRY_BLOCK_PTR_FOR_FN (cfun)->frequency;
2185 else
2186 max = 1;
2188 EXECUTE_IF_SET_IN_BITMAP (info.bb_set, 0, index, bi)
2189 max = MIN (max, BASIC_BLOCK_FOR_FN (cfun, index)->frequency);
2191 BITMAP_FREE (info.bb_set);
2192 if (max < bb->frequency)
2193 return MAX (GCOV_COMPUTE_SCALE (max, bb->frequency), 1);
2194 else
2195 return REG_BR_PROB_BASE;
2197 return REG_BR_PROB_BASE;
2200 /* Find whether a basic block BB is the final block of a (half) diamond CFG
2201 sub-graph and if the predicate the condition depends on is known. If so,
2202 return true and store the pointer the predicate in *P. */
2204 static bool
2205 phi_result_unknown_predicate (struct ipa_node_params *info,
2206 struct inline_summary *summary, basic_block bb,
2207 struct predicate *p,
2208 vec<predicate_t> nonconstant_names)
2210 edge e;
2211 edge_iterator ei;
2212 basic_block first_bb = NULL;
2213 gimple stmt;
2215 if (single_pred_p (bb))
2217 *p = false_predicate ();
2218 return true;
2221 FOR_EACH_EDGE (e, ei, bb->preds)
2223 if (single_succ_p (e->src))
2225 if (!single_pred_p (e->src))
2226 return false;
2227 if (!first_bb)
2228 first_bb = single_pred (e->src);
2229 else if (single_pred (e->src) != first_bb)
2230 return false;
2232 else
2234 if (!first_bb)
2235 first_bb = e->src;
2236 else if (e->src != first_bb)
2237 return false;
2241 if (!first_bb)
2242 return false;
2244 stmt = last_stmt (first_bb);
2245 if (!stmt
2246 || gimple_code (stmt) != GIMPLE_COND
2247 || !is_gimple_ip_invariant (gimple_cond_rhs (stmt)))
2248 return false;
2250 *p = will_be_nonconstant_expr_predicate (info, summary,
2251 gimple_cond_lhs (stmt),
2252 nonconstant_names);
2253 if (true_predicate_p (p))
2254 return false;
2255 else
2256 return true;
2259 /* Given a PHI statement in a function described by inline properties SUMMARY
2260 and *P being the predicate describing whether the selected PHI argument is
2261 known, store a predicate for the result of the PHI statement into
2262 NONCONSTANT_NAMES, if possible. */
2264 static void
2265 predicate_for_phi_result (struct inline_summary *summary, gimple phi,
2266 struct predicate *p,
2267 vec<predicate_t> nonconstant_names)
2269 unsigned i;
2271 for (i = 0; i < gimple_phi_num_args (phi); i++)
2273 tree arg = gimple_phi_arg (phi, i)->def;
2274 if (!is_gimple_min_invariant (arg))
2276 gcc_assert (TREE_CODE (arg) == SSA_NAME);
2277 *p = or_predicates (summary->conds, p,
2278 &nonconstant_names[SSA_NAME_VERSION (arg)]);
2279 if (true_predicate_p (p))
2280 return;
2284 if (dump_file && (dump_flags & TDF_DETAILS))
2286 fprintf (dump_file, "\t\tphi predicate: ");
2287 dump_predicate (dump_file, summary->conds, p);
2289 nonconstant_names[SSA_NAME_VERSION (gimple_phi_result (phi))] = *p;
2292 /* Return predicate specifying when array index in access OP becomes non-constant. */
2294 static struct predicate
2295 array_index_predicate (struct inline_summary *info,
2296 vec< predicate_t> nonconstant_names, tree op)
2298 struct predicate p = false_predicate ();
2299 while (handled_component_p (op))
2301 if (TREE_CODE (op) == ARRAY_REF || TREE_CODE (op) == ARRAY_RANGE_REF)
2303 if (TREE_CODE (TREE_OPERAND (op, 1)) == SSA_NAME)
2304 p = or_predicates (info->conds, &p,
2305 &nonconstant_names[SSA_NAME_VERSION
2306 (TREE_OPERAND (op, 1))]);
2308 op = TREE_OPERAND (op, 0);
2310 return p;
2313 /* For a typical usage of __builtin_expect (a<b, 1), we
2314 may introduce an extra relation stmt:
2315 With the builtin, we have
2316 t1 = a <= b;
2317 t2 = (long int) t1;
2318 t3 = __builtin_expect (t2, 1);
2319 if (t3 != 0)
2320 goto ...
2321 Without the builtin, we have
2322 if (a<=b)
2323 goto...
2324 This affects the size/time estimation and may have
2325 an impact on the earlier inlining.
2326 Here find this pattern and fix it up later. */
2328 static gimple
2329 find_foldable_builtin_expect (basic_block bb)
2331 gimple_stmt_iterator bsi;
2333 for (bsi = gsi_start_bb (bb); !gsi_end_p (bsi); gsi_next (&bsi))
2335 gimple stmt = gsi_stmt (bsi);
2336 if (gimple_call_builtin_p (stmt, BUILT_IN_EXPECT)
2337 || (is_gimple_call (stmt)
2338 && gimple_call_internal_p (stmt)
2339 && gimple_call_internal_fn (stmt) == IFN_BUILTIN_EXPECT))
2341 tree var = gimple_call_lhs (stmt);
2342 tree arg = gimple_call_arg (stmt, 0);
2343 use_operand_p use_p;
2344 gimple use_stmt;
2345 bool match = false;
2346 bool done = false;
2348 if (!var || !arg)
2349 continue;
2350 gcc_assert (TREE_CODE (var) == SSA_NAME);
2352 while (TREE_CODE (arg) == SSA_NAME)
2354 gimple stmt_tmp = SSA_NAME_DEF_STMT (arg);
2355 if (!is_gimple_assign (stmt_tmp))
2356 break;
2357 switch (gimple_assign_rhs_code (stmt_tmp))
2359 case LT_EXPR:
2360 case LE_EXPR:
2361 case GT_EXPR:
2362 case GE_EXPR:
2363 case EQ_EXPR:
2364 case NE_EXPR:
2365 match = true;
2366 done = true;
2367 break;
2368 case NOP_EXPR:
2369 break;
2370 default:
2371 done = true;
2372 break;
2374 if (done)
2375 break;
2376 arg = gimple_assign_rhs1 (stmt_tmp);
2379 if (match && single_imm_use (var, &use_p, &use_stmt)
2380 && gimple_code (use_stmt) == GIMPLE_COND)
2381 return use_stmt;
2384 return NULL;
2387 /* Return true when the basic blocks contains only clobbers followed by RESX.
2388 Such BBs are kept around to make removal of dead stores possible with
2389 presence of EH and will be optimized out by optimize_clobbers later in the
2390 game.
2392 NEED_EH is used to recurse in case the clobber has non-EH predecestors
2393 that can be clobber only, too.. When it is false, the RESX is not necessary
2394 on the end of basic block. */
2396 static bool
2397 clobber_only_eh_bb_p (basic_block bb, bool need_eh = true)
2399 gimple_stmt_iterator gsi = gsi_last_bb (bb);
2400 edge_iterator ei;
2401 edge e;
2403 if (need_eh)
2405 if (gsi_end_p (gsi))
2406 return false;
2407 if (gimple_code (gsi_stmt (gsi)) != GIMPLE_RESX)
2408 return false;
2409 gsi_prev (&gsi);
2411 else if (!single_succ_p (bb))
2412 return false;
2414 for (; !gsi_end_p (gsi); gsi_prev (&gsi))
2416 gimple stmt = gsi_stmt (gsi);
2417 if (is_gimple_debug (stmt))
2418 continue;
2419 if (gimple_clobber_p (stmt))
2420 continue;
2421 if (gimple_code (stmt) == GIMPLE_LABEL)
2422 break;
2423 return false;
2426 /* See if all predecestors are either throws or clobber only BBs. */
2427 FOR_EACH_EDGE (e, ei, bb->preds)
2428 if (!(e->flags & EDGE_EH)
2429 && !clobber_only_eh_bb_p (e->src, false))
2430 return false;
2432 return true;
2435 /* Compute function body size parameters for NODE.
2436 When EARLY is true, we compute only simple summaries without
2437 non-trivial predicates to drive the early inliner. */
2439 static void
2440 estimate_function_body_sizes (struct cgraph_node *node, bool early)
2442 gcov_type time = 0;
2443 /* Estimate static overhead for function prologue/epilogue and alignment. */
2444 int size = 2;
2445 /* Benefits are scaled by probability of elimination that is in range
2446 <0,2>. */
2447 basic_block bb;
2448 gimple_stmt_iterator bsi;
2449 struct function *my_function = DECL_STRUCT_FUNCTION (node->decl);
2450 int freq;
2451 struct inline_summary *info = inline_summary (node);
2452 struct predicate bb_predicate;
2453 struct ipa_node_params *parms_info = NULL;
2454 vec<predicate_t> nonconstant_names = vNULL;
2455 int nblocks, n;
2456 int *order;
2457 predicate array_index = true_predicate ();
2458 gimple fix_builtin_expect_stmt;
2460 info->conds = NULL;
2461 info->entry = NULL;
2463 if (optimize && !early)
2465 calculate_dominance_info (CDI_DOMINATORS);
2466 loop_optimizer_init (LOOPS_NORMAL | LOOPS_HAVE_RECORDED_EXITS);
2468 if (ipa_node_params_vector.exists ())
2470 parms_info = IPA_NODE_REF (node);
2471 nonconstant_names.safe_grow_cleared
2472 (SSANAMES (my_function)->length ());
2476 if (dump_file)
2477 fprintf (dump_file, "\nAnalyzing function body size: %s\n",
2478 node->name ());
2480 /* When we run into maximal number of entries, we assign everything to the
2481 constant truth case. Be sure to have it in list. */
2482 bb_predicate = true_predicate ();
2483 account_size_time (info, 0, 0, &bb_predicate);
2485 bb_predicate = not_inlined_predicate ();
2486 account_size_time (info, 2 * INLINE_SIZE_SCALE, 0, &bb_predicate);
2488 gcc_assert (my_function && my_function->cfg);
2489 if (parms_info)
2490 compute_bb_predicates (node, parms_info, info);
2491 gcc_assert (cfun == my_function);
2492 order = XNEWVEC (int, n_basic_blocks_for_fn (cfun));
2493 nblocks = pre_and_rev_post_order_compute (NULL, order, false);
2494 for (n = 0; n < nblocks; n++)
2496 bb = BASIC_BLOCK_FOR_FN (cfun, order[n]);
2497 freq = compute_call_stmt_bb_frequency (node->decl, bb);
2498 if (clobber_only_eh_bb_p (bb))
2500 if (dump_file && (dump_flags & TDF_DETAILS))
2501 fprintf (dump_file, "\n Ignoring BB %i;"
2502 " it will be optimized away by cleanup_clobbers\n",
2503 bb->index);
2504 continue;
2507 /* TODO: Obviously predicates can be propagated down across CFG. */
2508 if (parms_info)
2510 if (bb->aux)
2511 bb_predicate = *(struct predicate *) bb->aux;
2512 else
2513 bb_predicate = false_predicate ();
2515 else
2516 bb_predicate = true_predicate ();
2518 if (dump_file && (dump_flags & TDF_DETAILS))
2520 fprintf (dump_file, "\n BB %i predicate:", bb->index);
2521 dump_predicate (dump_file, info->conds, &bb_predicate);
2524 if (parms_info && nonconstant_names.exists ())
2526 struct predicate phi_predicate;
2527 bool first_phi = true;
2529 for (bsi = gsi_start_phis (bb); !gsi_end_p (bsi); gsi_next (&bsi))
2531 if (first_phi
2532 && !phi_result_unknown_predicate (parms_info, info, bb,
2533 &phi_predicate,
2534 nonconstant_names))
2535 break;
2536 first_phi = false;
2537 if (dump_file && (dump_flags & TDF_DETAILS))
2539 fprintf (dump_file, " ");
2540 print_gimple_stmt (dump_file, gsi_stmt (bsi), 0, 0);
2542 predicate_for_phi_result (info, gsi_stmt (bsi), &phi_predicate,
2543 nonconstant_names);
2547 fix_builtin_expect_stmt = find_foldable_builtin_expect (bb);
2549 for (bsi = gsi_start_bb (bb); !gsi_end_p (bsi); gsi_next (&bsi))
2551 gimple stmt = gsi_stmt (bsi);
2552 int this_size = estimate_num_insns (stmt, &eni_size_weights);
2553 int this_time = estimate_num_insns (stmt, &eni_time_weights);
2554 int prob;
2555 struct predicate will_be_nonconstant;
2557 /* This relation stmt should be folded after we remove
2558 buildin_expect call. Adjust the cost here. */
2559 if (stmt == fix_builtin_expect_stmt)
2561 this_size--;
2562 this_time--;
2565 if (dump_file && (dump_flags & TDF_DETAILS))
2567 fprintf (dump_file, " ");
2568 print_gimple_stmt (dump_file, stmt, 0, 0);
2569 fprintf (dump_file, "\t\tfreq:%3.2f size:%3i time:%3i\n",
2570 ((double) freq) / CGRAPH_FREQ_BASE, this_size,
2571 this_time);
2574 if (gimple_assign_load_p (stmt) && nonconstant_names.exists ())
2576 struct predicate this_array_index;
2577 this_array_index =
2578 array_index_predicate (info, nonconstant_names,
2579 gimple_assign_rhs1 (stmt));
2580 if (!false_predicate_p (&this_array_index))
2581 array_index =
2582 and_predicates (info->conds, &array_index,
2583 &this_array_index);
2585 if (gimple_store_p (stmt) && nonconstant_names.exists ())
2587 struct predicate this_array_index;
2588 this_array_index =
2589 array_index_predicate (info, nonconstant_names,
2590 gimple_get_lhs (stmt));
2591 if (!false_predicate_p (&this_array_index))
2592 array_index =
2593 and_predicates (info->conds, &array_index,
2594 &this_array_index);
2598 if (is_gimple_call (stmt)
2599 && !gimple_call_internal_p (stmt))
2601 struct cgraph_edge *edge = cgraph_edge (node, stmt);
2602 struct inline_edge_summary *es = inline_edge_summary (edge);
2604 /* Special case: results of BUILT_IN_CONSTANT_P will be always
2605 resolved as constant. We however don't want to optimize
2606 out the cgraph edges. */
2607 if (nonconstant_names.exists ()
2608 && gimple_call_builtin_p (stmt, BUILT_IN_CONSTANT_P)
2609 && gimple_call_lhs (stmt)
2610 && TREE_CODE (gimple_call_lhs (stmt)) == SSA_NAME)
2612 struct predicate false_p = false_predicate ();
2613 nonconstant_names[SSA_NAME_VERSION (gimple_call_lhs (stmt))]
2614 = false_p;
2616 if (ipa_node_params_vector.exists ())
2618 int count = gimple_call_num_args (stmt);
2619 int i;
2621 if (count)
2622 es->param.safe_grow_cleared (count);
2623 for (i = 0; i < count; i++)
2625 int prob = param_change_prob (stmt, i);
2626 gcc_assert (prob >= 0 && prob <= REG_BR_PROB_BASE);
2627 es->param[i].change_prob = prob;
2631 es->call_stmt_size = this_size;
2632 es->call_stmt_time = this_time;
2633 es->loop_depth = bb_loop_depth (bb);
2634 edge_set_predicate (edge, &bb_predicate);
2637 /* TODO: When conditional jump or swithc is known to be constant, but
2638 we did not translate it into the predicates, we really can account
2639 just maximum of the possible paths. */
2640 if (parms_info)
2641 will_be_nonconstant
2642 = will_be_nonconstant_predicate (parms_info, info,
2643 stmt, nonconstant_names);
2644 if (this_time || this_size)
2646 struct predicate p;
2648 this_time *= freq;
2650 prob = eliminated_by_inlining_prob (stmt);
2651 if (prob == 1 && dump_file && (dump_flags & TDF_DETAILS))
2652 fprintf (dump_file,
2653 "\t\t50%% will be eliminated by inlining\n");
2654 if (prob == 2 && dump_file && (dump_flags & TDF_DETAILS))
2655 fprintf (dump_file, "\t\tWill be eliminated by inlining\n");
2657 if (parms_info)
2658 p = and_predicates (info->conds, &bb_predicate,
2659 &will_be_nonconstant);
2660 else
2661 p = true_predicate ();
2663 if (!false_predicate_p (&p))
2665 time += this_time;
2666 size += this_size;
2667 if (time > MAX_TIME * INLINE_TIME_SCALE)
2668 time = MAX_TIME * INLINE_TIME_SCALE;
2671 /* We account everything but the calls. Calls have their own
2672 size/time info attached to cgraph edges. This is necessary
2673 in order to make the cost disappear after inlining. */
2674 if (!is_gimple_call (stmt))
2676 if (prob)
2678 struct predicate ip = not_inlined_predicate ();
2679 ip = and_predicates (info->conds, &ip, &p);
2680 account_size_time (info, this_size * prob,
2681 this_time * prob, &ip);
2683 if (prob != 2)
2684 account_size_time (info, this_size * (2 - prob),
2685 this_time * (2 - prob), &p);
2688 gcc_assert (time >= 0);
2689 gcc_assert (size >= 0);
2693 set_hint_predicate (&inline_summary (node)->array_index, array_index);
2694 time = (time + CGRAPH_FREQ_BASE / 2) / CGRAPH_FREQ_BASE;
2695 if (time > MAX_TIME)
2696 time = MAX_TIME;
2697 free (order);
2699 if (!early && nonconstant_names.exists ())
2701 struct loop *loop;
2702 predicate loop_iterations = true_predicate ();
2703 predicate loop_stride = true_predicate ();
2705 if (dump_file && (dump_flags & TDF_DETAILS))
2706 flow_loops_dump (dump_file, NULL, 0);
2707 scev_initialize ();
2708 FOR_EACH_LOOP (loop, 0)
2710 vec<edge> exits;
2711 edge ex;
2712 unsigned int j, i;
2713 struct tree_niter_desc niter_desc;
2714 basic_block *body = get_loop_body (loop);
2715 bb_predicate = *(struct predicate *) loop->header->aux;
2717 exits = get_loop_exit_edges (loop);
2718 FOR_EACH_VEC_ELT (exits, j, ex)
2719 if (number_of_iterations_exit (loop, ex, &niter_desc, false)
2720 && !is_gimple_min_invariant (niter_desc.niter))
2722 predicate will_be_nonconstant
2723 = will_be_nonconstant_expr_predicate (parms_info, info,
2724 niter_desc.niter,
2725 nonconstant_names);
2726 if (!true_predicate_p (&will_be_nonconstant))
2727 will_be_nonconstant = and_predicates (info->conds,
2728 &bb_predicate,
2729 &will_be_nonconstant);
2730 if (!true_predicate_p (&will_be_nonconstant)
2731 && !false_predicate_p (&will_be_nonconstant))
2732 /* This is slightly inprecise. We may want to represent each
2733 loop with independent predicate. */
2734 loop_iterations =
2735 and_predicates (info->conds, &loop_iterations,
2736 &will_be_nonconstant);
2738 exits.release ();
2740 for (i = 0; i < loop->num_nodes; i++)
2742 gimple_stmt_iterator gsi;
2743 bb_predicate = *(struct predicate *) body[i]->aux;
2744 for (gsi = gsi_start_bb (body[i]); !gsi_end_p (gsi);
2745 gsi_next (&gsi))
2747 gimple stmt = gsi_stmt (gsi);
2748 affine_iv iv;
2749 ssa_op_iter iter;
2750 tree use;
2752 FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter, SSA_OP_USE)
2754 predicate will_be_nonconstant;
2756 if (!simple_iv
2757 (loop, loop_containing_stmt (stmt), use, &iv, true)
2758 || is_gimple_min_invariant (iv.step))
2759 continue;
2760 will_be_nonconstant
2761 = will_be_nonconstant_expr_predicate (parms_info, info,
2762 iv.step,
2763 nonconstant_names);
2764 if (!true_predicate_p (&will_be_nonconstant))
2765 will_be_nonconstant
2766 = and_predicates (info->conds,
2767 &bb_predicate,
2768 &will_be_nonconstant);
2769 if (!true_predicate_p (&will_be_nonconstant)
2770 && !false_predicate_p (&will_be_nonconstant))
2771 /* This is slightly inprecise. We may want to represent
2772 each loop with independent predicate. */
2773 loop_stride =
2774 and_predicates (info->conds, &loop_stride,
2775 &will_be_nonconstant);
2779 free (body);
2781 set_hint_predicate (&inline_summary (node)->loop_iterations,
2782 loop_iterations);
2783 set_hint_predicate (&inline_summary (node)->loop_stride, loop_stride);
2784 scev_finalize ();
2786 FOR_ALL_BB_FN (bb, my_function)
2788 edge e;
2789 edge_iterator ei;
2791 if (bb->aux)
2792 pool_free (edge_predicate_pool, bb->aux);
2793 bb->aux = NULL;
2794 FOR_EACH_EDGE (e, ei, bb->succs)
2796 if (e->aux)
2797 pool_free (edge_predicate_pool, e->aux);
2798 e->aux = NULL;
2801 inline_summary (node)->self_time = time;
2802 inline_summary (node)->self_size = size;
2803 nonconstant_names.release ();
2804 if (optimize && !early)
2806 loop_optimizer_finalize ();
2807 free_dominance_info (CDI_DOMINATORS);
2809 if (dump_file)
2811 fprintf (dump_file, "\n");
2812 dump_inline_summary (dump_file, node);
2817 /* Compute parameters of functions used by inliner.
2818 EARLY is true when we compute parameters for the early inliner */
2820 void
2821 compute_inline_parameters (struct cgraph_node *node, bool early)
2823 HOST_WIDE_INT self_stack_size;
2824 struct cgraph_edge *e;
2825 struct inline_summary *info;
2827 gcc_assert (!node->global.inlined_to);
2829 inline_summary_alloc ();
2831 info = inline_summary (node);
2832 reset_inline_summary (node);
2834 /* FIXME: Thunks are inlinable, but tree-inline don't know how to do that.
2835 Once this happen, we will need to more curefully predict call
2836 statement size. */
2837 if (node->thunk.thunk_p)
2839 struct inline_edge_summary *es = inline_edge_summary (node->callees);
2840 struct predicate t = true_predicate ();
2842 info->inlinable = 0;
2843 node->callees->call_stmt_cannot_inline_p = true;
2844 node->local.can_change_signature = false;
2845 es->call_stmt_time = 1;
2846 es->call_stmt_size = 1;
2847 account_size_time (info, 0, 0, &t);
2848 return;
2851 /* Even is_gimple_min_invariant rely on current_function_decl. */
2852 push_cfun (DECL_STRUCT_FUNCTION (node->decl));
2854 /* Estimate the stack size for the function if we're optimizing. */
2855 self_stack_size = optimize ? estimated_stack_frame_size (node) : 0;
2856 info->estimated_self_stack_size = self_stack_size;
2857 info->estimated_stack_size = self_stack_size;
2858 info->stack_frame_offset = 0;
2860 /* Can this function be inlined at all? */
2861 if (!optimize && !lookup_attribute ("always_inline",
2862 DECL_ATTRIBUTES (node->decl)))
2863 info->inlinable = false;
2864 else
2865 info->inlinable = tree_inlinable_function_p (node->decl);
2867 /* Type attributes can use parameter indices to describe them. */
2868 if (TYPE_ATTRIBUTES (TREE_TYPE (node->decl)))
2869 node->local.can_change_signature = false;
2870 else
2872 /* Otherwise, inlinable functions always can change signature. */
2873 if (info->inlinable)
2874 node->local.can_change_signature = true;
2875 else
2877 /* Functions calling builtin_apply can not change signature. */
2878 for (e = node->callees; e; e = e->next_callee)
2880 tree cdecl = e->callee->decl;
2881 if (DECL_BUILT_IN (cdecl)
2882 && DECL_BUILT_IN_CLASS (cdecl) == BUILT_IN_NORMAL
2883 && (DECL_FUNCTION_CODE (cdecl) == BUILT_IN_APPLY_ARGS
2884 || DECL_FUNCTION_CODE (cdecl) == BUILT_IN_VA_START))
2885 break;
2887 node->local.can_change_signature = !e;
2890 estimate_function_body_sizes (node, early);
2892 for (e = node->callees; e; e = e->next_callee)
2893 if (symtab_comdat_local_p (e->callee))
2894 break;
2895 node->calls_comdat_local = (e != NULL);
2897 /* Inlining characteristics are maintained by the cgraph_mark_inline. */
2898 info->time = info->self_time;
2899 info->size = info->self_size;
2900 info->stack_frame_offset = 0;
2901 info->estimated_stack_size = info->estimated_self_stack_size;
2902 #ifdef ENABLE_CHECKING
2903 inline_update_overall_summary (node);
2904 gcc_assert (info->time == info->self_time && info->size == info->self_size);
2905 #endif
2907 pop_cfun ();
2911 /* Compute parameters of functions used by inliner using
2912 current_function_decl. */
2914 static unsigned int
2915 compute_inline_parameters_for_current (void)
2917 compute_inline_parameters (cgraph_get_node (current_function_decl), true);
2918 return 0;
2921 namespace {
2923 const pass_data pass_data_inline_parameters =
2925 GIMPLE_PASS, /* type */
2926 "inline_param", /* name */
2927 OPTGROUP_INLINE, /* optinfo_flags */
2928 TV_INLINE_PARAMETERS, /* tv_id */
2929 0, /* properties_required */
2930 0, /* properties_provided */
2931 0, /* properties_destroyed */
2932 0, /* todo_flags_start */
2933 0, /* todo_flags_finish */
2936 class pass_inline_parameters : public gimple_opt_pass
2938 public:
2939 pass_inline_parameters (gcc::context *ctxt)
2940 : gimple_opt_pass (pass_data_inline_parameters, ctxt)
2943 /* opt_pass methods: */
2944 opt_pass * clone () { return new pass_inline_parameters (m_ctxt); }
2945 virtual unsigned int execute (function *)
2947 return compute_inline_parameters_for_current ();
2950 }; // class pass_inline_parameters
2952 } // anon namespace
2954 gimple_opt_pass *
2955 make_pass_inline_parameters (gcc::context *ctxt)
2957 return new pass_inline_parameters (ctxt);
2961 /* Estimate benefit devirtualizing indirect edge IE, provided KNOWN_VALS and
2962 KNOWN_BINFOS. */
2964 static bool
2965 estimate_edge_devirt_benefit (struct cgraph_edge *ie,
2966 int *size, int *time,
2967 vec<tree> known_vals,
2968 vec<tree> known_binfos,
2969 vec<ipa_agg_jump_function_p> known_aggs)
2971 tree target;
2972 struct cgraph_node *callee;
2973 struct inline_summary *isummary;
2974 enum availability avail;
2976 if (!known_vals.exists () && !known_binfos.exists ())
2977 return false;
2978 if (!flag_indirect_inlining)
2979 return false;
2981 target = ipa_get_indirect_edge_target (ie, known_vals, known_binfos,
2982 known_aggs);
2983 if (!target)
2984 return false;
2986 /* Account for difference in cost between indirect and direct calls. */
2987 *size -= (eni_size_weights.indirect_call_cost - eni_size_weights.call_cost);
2988 *time -= (eni_time_weights.indirect_call_cost - eni_time_weights.call_cost);
2989 gcc_checking_assert (*time >= 0);
2990 gcc_checking_assert (*size >= 0);
2992 callee = cgraph_get_node (target);
2993 if (!callee || !callee->definition)
2994 return false;
2995 callee = cgraph_function_node (callee, &avail);
2996 if (avail < AVAIL_AVAILABLE)
2997 return false;
2998 isummary = inline_summary (callee);
2999 return isummary->inlinable;
3002 /* Increase SIZE, MIN_SIZE (if non-NULL) and TIME for size and time needed to
3003 handle edge E with probability PROB.
3004 Set HINTS if edge may be devirtualized.
3005 KNOWN_VALS, KNOWN_AGGS and KNOWN_BINFOS describe context of the call
3006 site. */
3008 static inline void
3009 estimate_edge_size_and_time (struct cgraph_edge *e, int *size, int *min_size,
3010 int *time,
3011 int prob,
3012 vec<tree> known_vals,
3013 vec<tree> known_binfos,
3014 vec<ipa_agg_jump_function_p> known_aggs,
3015 inline_hints *hints)
3017 struct inline_edge_summary *es = inline_edge_summary (e);
3018 int call_size = es->call_stmt_size;
3019 int call_time = es->call_stmt_time;
3020 int cur_size;
3021 if (!e->callee
3022 && estimate_edge_devirt_benefit (e, &call_size, &call_time,
3023 known_vals, known_binfos, known_aggs)
3024 && hints && cgraph_maybe_hot_edge_p (e))
3025 *hints |= INLINE_HINT_indirect_call;
3026 cur_size = call_size * INLINE_SIZE_SCALE;
3027 *size += cur_size;
3028 if (min_size)
3029 *min_size += cur_size;
3030 *time += apply_probability ((gcov_type) call_time, prob)
3031 * e->frequency * (INLINE_TIME_SCALE / CGRAPH_FREQ_BASE);
3032 if (*time > MAX_TIME * INLINE_TIME_SCALE)
3033 *time = MAX_TIME * INLINE_TIME_SCALE;
3038 /* Increase SIZE, MIN_SIZE and TIME for size and time needed to handle all
3039 calls in NODE.
3040 POSSIBLE_TRUTHS, KNOWN_VALS, KNOWN_AGGS and KNOWN_BINFOS describe context of
3041 the call site. */
3043 static void
3044 estimate_calls_size_and_time (struct cgraph_node *node, int *size,
3045 int *min_size, int *time,
3046 inline_hints *hints,
3047 clause_t possible_truths,
3048 vec<tree> known_vals,
3049 vec<tree> known_binfos,
3050 vec<ipa_agg_jump_function_p> known_aggs)
3052 struct cgraph_edge *e;
3053 for (e = node->callees; e; e = e->next_callee)
3055 struct inline_edge_summary *es = inline_edge_summary (e);
3056 if (!es->predicate
3057 || evaluate_predicate (es->predicate, possible_truths))
3059 if (e->inline_failed)
3061 /* Predicates of calls shall not use NOT_CHANGED codes,
3062 sowe do not need to compute probabilities. */
3063 estimate_edge_size_and_time (e, size,
3064 es->predicate ? NULL : min_size,
3065 time, REG_BR_PROB_BASE,
3066 known_vals, known_binfos,
3067 known_aggs, hints);
3069 else
3070 estimate_calls_size_and_time (e->callee, size, min_size, time,
3071 hints,
3072 possible_truths,
3073 known_vals, known_binfos,
3074 known_aggs);
3077 for (e = node->indirect_calls; e; e = e->next_callee)
3079 struct inline_edge_summary *es = inline_edge_summary (e);
3080 if (!es->predicate
3081 || evaluate_predicate (es->predicate, possible_truths))
3082 estimate_edge_size_and_time (e, size,
3083 es->predicate ? NULL : min_size,
3084 time, REG_BR_PROB_BASE,
3085 known_vals, known_binfos, known_aggs,
3086 hints);
3091 /* Estimate size and time needed to execute NODE assuming
3092 POSSIBLE_TRUTHS clause, and KNOWN_VALS, KNOWN_AGGS and KNOWN_BINFOS
3093 information about NODE's arguments. If non-NULL use also probability
3094 information present in INLINE_PARAM_SUMMARY vector.
3095 Additionally detemine hints determined by the context. Finally compute
3096 minimal size needed for the call that is independent on the call context and
3097 can be used for fast estimates. Return the values in RET_SIZE,
3098 RET_MIN_SIZE, RET_TIME and RET_HINTS. */
3100 static void
3101 estimate_node_size_and_time (struct cgraph_node *node,
3102 clause_t possible_truths,
3103 vec<tree> known_vals,
3104 vec<tree> known_binfos,
3105 vec<ipa_agg_jump_function_p> known_aggs,
3106 int *ret_size, int *ret_min_size, int *ret_time,
3107 inline_hints *ret_hints,
3108 vec<inline_param_summary>
3109 inline_param_summary)
3111 struct inline_summary *info = inline_summary (node);
3112 size_time_entry *e;
3113 int size = 0;
3114 int time = 0;
3115 int min_size = 0;
3116 inline_hints hints = 0;
3117 int i;
3119 if (dump_file && (dump_flags & TDF_DETAILS))
3121 bool found = false;
3122 fprintf (dump_file, " Estimating body: %s/%i\n"
3123 " Known to be false: ", node->name (),
3124 node->order);
3126 for (i = predicate_not_inlined_condition;
3127 i < (predicate_first_dynamic_condition
3128 + (int) vec_safe_length (info->conds)); i++)
3129 if (!(possible_truths & (1 << i)))
3131 if (found)
3132 fprintf (dump_file, ", ");
3133 found = true;
3134 dump_condition (dump_file, info->conds, i);
3138 for (i = 0; vec_safe_iterate (info->entry, i, &e); i++)
3139 if (evaluate_predicate (&e->predicate, possible_truths))
3141 size += e->size;
3142 gcc_checking_assert (e->time >= 0);
3143 gcc_checking_assert (time >= 0);
3144 if (!inline_param_summary.exists ())
3145 time += e->time;
3146 else
3148 int prob = predicate_probability (info->conds,
3149 &e->predicate,
3150 possible_truths,
3151 inline_param_summary);
3152 gcc_checking_assert (prob >= 0);
3153 gcc_checking_assert (prob <= REG_BR_PROB_BASE);
3154 time += apply_probability ((gcov_type) e->time, prob);
3156 if (time > MAX_TIME * INLINE_TIME_SCALE)
3157 time = MAX_TIME * INLINE_TIME_SCALE;
3158 gcc_checking_assert (time >= 0);
3161 gcc_checking_assert (true_predicate_p (&(*info->entry)[0].predicate));
3162 min_size = (*info->entry)[0].size;
3163 gcc_checking_assert (size >= 0);
3164 gcc_checking_assert (time >= 0);
3166 if (info->loop_iterations
3167 && !evaluate_predicate (info->loop_iterations, possible_truths))
3168 hints |= INLINE_HINT_loop_iterations;
3169 if (info->loop_stride
3170 && !evaluate_predicate (info->loop_stride, possible_truths))
3171 hints |= INLINE_HINT_loop_stride;
3172 if (info->array_index
3173 && !evaluate_predicate (info->array_index, possible_truths))
3174 hints |= INLINE_HINT_array_index;
3175 if (info->scc_no)
3176 hints |= INLINE_HINT_in_scc;
3177 if (DECL_DECLARED_INLINE_P (node->decl))
3178 hints |= INLINE_HINT_declared_inline;
3180 estimate_calls_size_and_time (node, &size, &min_size, &time, &hints, possible_truths,
3181 known_vals, known_binfos, known_aggs);
3182 gcc_checking_assert (size >= 0);
3183 gcc_checking_assert (time >= 0);
3184 time = RDIV (time, INLINE_TIME_SCALE);
3185 size = RDIV (size, INLINE_SIZE_SCALE);
3186 min_size = RDIV (min_size, INLINE_SIZE_SCALE);
3188 if (dump_file && (dump_flags & TDF_DETAILS))
3189 fprintf (dump_file, "\n size:%i time:%i\n", (int) size, (int) time);
3190 if (ret_time)
3191 *ret_time = time;
3192 if (ret_size)
3193 *ret_size = size;
3194 if (ret_min_size)
3195 *ret_min_size = min_size;
3196 if (ret_hints)
3197 *ret_hints = hints;
3198 return;
3202 /* Estimate size and time needed to execute callee of EDGE assuming that
3203 parameters known to be constant at caller of EDGE are propagated.
3204 KNOWN_VALS and KNOWN_BINFOS are vectors of assumed known constant values
3205 and types for parameters. */
3207 void
3208 estimate_ipcp_clone_size_and_time (struct cgraph_node *node,
3209 vec<tree> known_vals,
3210 vec<tree> known_binfos,
3211 vec<ipa_agg_jump_function_p> known_aggs,
3212 int *ret_size, int *ret_time,
3213 inline_hints *hints)
3215 clause_t clause;
3217 clause = evaluate_conditions_for_known_args (node, false, known_vals,
3218 known_aggs);
3219 estimate_node_size_and_time (node, clause, known_vals, known_binfos,
3220 known_aggs, ret_size, NULL, ret_time, hints, vNULL);
3223 /* Translate all conditions from callee representation into caller
3224 representation and symbolically evaluate predicate P into new predicate.
3226 INFO is inline_summary of function we are adding predicate into, CALLEE_INFO
3227 is summary of function predicate P is from. OPERAND_MAP is array giving
3228 callee formal IDs the caller formal IDs. POSSSIBLE_TRUTHS is clausule of all
3229 callee conditions that may be true in caller context. TOPLEV_PREDICATE is
3230 predicate under which callee is executed. OFFSET_MAP is an array of of
3231 offsets that need to be added to conditions, negative offset means that
3232 conditions relying on values passed by reference have to be discarded
3233 because they might not be preserved (and should be considered offset zero
3234 for other purposes). */
3236 static struct predicate
3237 remap_predicate (struct inline_summary *info,
3238 struct inline_summary *callee_info,
3239 struct predicate *p,
3240 vec<int> operand_map,
3241 vec<int> offset_map,
3242 clause_t possible_truths, struct predicate *toplev_predicate)
3244 int i;
3245 struct predicate out = true_predicate ();
3247 /* True predicate is easy. */
3248 if (true_predicate_p (p))
3249 return *toplev_predicate;
3250 for (i = 0; p->clause[i]; i++)
3252 clause_t clause = p->clause[i];
3253 int cond;
3254 struct predicate clause_predicate = false_predicate ();
3256 gcc_assert (i < MAX_CLAUSES);
3258 for (cond = 0; cond < NUM_CONDITIONS; cond++)
3259 /* Do we have condition we can't disprove? */
3260 if (clause & possible_truths & (1 << cond))
3262 struct predicate cond_predicate;
3263 /* Work out if the condition can translate to predicate in the
3264 inlined function. */
3265 if (cond >= predicate_first_dynamic_condition)
3267 struct condition *c;
3269 c = &(*callee_info->conds)[cond
3271 predicate_first_dynamic_condition];
3272 /* See if we can remap condition operand to caller's operand.
3273 Otherwise give up. */
3274 if (!operand_map.exists ()
3275 || (int) operand_map.length () <= c->operand_num
3276 || operand_map[c->operand_num] == -1
3277 /* TODO: For non-aggregate conditions, adding an offset is
3278 basically an arithmetic jump function processing which
3279 we should support in future. */
3280 || ((!c->agg_contents || !c->by_ref)
3281 && offset_map[c->operand_num] > 0)
3282 || (c->agg_contents && c->by_ref
3283 && offset_map[c->operand_num] < 0))
3284 cond_predicate = true_predicate ();
3285 else
3287 struct agg_position_info ap;
3288 HOST_WIDE_INT offset_delta = offset_map[c->operand_num];
3289 if (offset_delta < 0)
3291 gcc_checking_assert (!c->agg_contents || !c->by_ref);
3292 offset_delta = 0;
3294 gcc_assert (!c->agg_contents
3295 || c->by_ref || offset_delta == 0);
3296 ap.offset = c->offset + offset_delta;
3297 ap.agg_contents = c->agg_contents;
3298 ap.by_ref = c->by_ref;
3299 cond_predicate = add_condition (info,
3300 operand_map[c->operand_num],
3301 &ap, c->code, c->val);
3304 /* Fixed conditions remains same, construct single
3305 condition predicate. */
3306 else
3308 cond_predicate.clause[0] = 1 << cond;
3309 cond_predicate.clause[1] = 0;
3311 clause_predicate = or_predicates (info->conds, &clause_predicate,
3312 &cond_predicate);
3314 out = and_predicates (info->conds, &out, &clause_predicate);
3316 return and_predicates (info->conds, &out, toplev_predicate);
3320 /* Update summary information of inline clones after inlining.
3321 Compute peak stack usage. */
3323 static void
3324 inline_update_callee_summaries (struct cgraph_node *node, int depth)
3326 struct cgraph_edge *e;
3327 struct inline_summary *callee_info = inline_summary (node);
3328 struct inline_summary *caller_info = inline_summary (node->callers->caller);
3329 HOST_WIDE_INT peak;
3331 callee_info->stack_frame_offset
3332 = caller_info->stack_frame_offset
3333 + caller_info->estimated_self_stack_size;
3334 peak = callee_info->stack_frame_offset
3335 + callee_info->estimated_self_stack_size;
3336 if (inline_summary (node->global.inlined_to)->estimated_stack_size < peak)
3337 inline_summary (node->global.inlined_to)->estimated_stack_size = peak;
3338 ipa_propagate_frequency (node);
3339 for (e = node->callees; e; e = e->next_callee)
3341 if (!e->inline_failed)
3342 inline_update_callee_summaries (e->callee, depth);
3343 inline_edge_summary (e)->loop_depth += depth;
3345 for (e = node->indirect_calls; e; e = e->next_callee)
3346 inline_edge_summary (e)->loop_depth += depth;
3349 /* Update change_prob of EDGE after INLINED_EDGE has been inlined.
3350 When functoin A is inlined in B and A calls C with parameter that
3351 changes with probability PROB1 and C is known to be passthroug
3352 of argument if B that change with probability PROB2, the probability
3353 of change is now PROB1*PROB2. */
3355 static void
3356 remap_edge_change_prob (struct cgraph_edge *inlined_edge,
3357 struct cgraph_edge *edge)
3359 if (ipa_node_params_vector.exists ())
3361 int i;
3362 struct ipa_edge_args *args = IPA_EDGE_REF (edge);
3363 struct inline_edge_summary *es = inline_edge_summary (edge);
3364 struct inline_edge_summary *inlined_es
3365 = inline_edge_summary (inlined_edge);
3367 for (i = 0; i < ipa_get_cs_argument_count (args); i++)
3369 struct ipa_jump_func *jfunc = ipa_get_ith_jump_func (args, i);
3370 if (jfunc->type == IPA_JF_PASS_THROUGH
3371 && (ipa_get_jf_pass_through_formal_id (jfunc)
3372 < (int) inlined_es->param.length ()))
3374 int jf_formal_id = ipa_get_jf_pass_through_formal_id (jfunc);
3375 int prob1 = es->param[i].change_prob;
3376 int prob2 = inlined_es->param[jf_formal_id].change_prob;
3377 int prob = combine_probabilities (prob1, prob2);
3379 if (prob1 && prob2 && !prob)
3380 prob = 1;
3382 es->param[i].change_prob = prob;
3388 /* Update edge summaries of NODE after INLINED_EDGE has been inlined.
3390 Remap predicates of callees of NODE. Rest of arguments match
3391 remap_predicate.
3393 Also update change probabilities. */
3395 static void
3396 remap_edge_summaries (struct cgraph_edge *inlined_edge,
3397 struct cgraph_node *node,
3398 struct inline_summary *info,
3399 struct inline_summary *callee_info,
3400 vec<int> operand_map,
3401 vec<int> offset_map,
3402 clause_t possible_truths,
3403 struct predicate *toplev_predicate)
3405 struct cgraph_edge *e;
3406 for (e = node->callees; e; e = e->next_callee)
3408 struct inline_edge_summary *es = inline_edge_summary (e);
3409 struct predicate p;
3411 if (e->inline_failed)
3413 remap_edge_change_prob (inlined_edge, e);
3415 if (es->predicate)
3417 p = remap_predicate (info, callee_info,
3418 es->predicate, operand_map, offset_map,
3419 possible_truths, toplev_predicate);
3420 edge_set_predicate (e, &p);
3421 /* TODO: We should remove the edge for code that will be
3422 optimized out, but we need to keep verifiers and tree-inline
3423 happy. Make it cold for now. */
3424 if (false_predicate_p (&p))
3426 e->count = 0;
3427 e->frequency = 0;
3430 else
3431 edge_set_predicate (e, toplev_predicate);
3433 else
3434 remap_edge_summaries (inlined_edge, e->callee, info, callee_info,
3435 operand_map, offset_map, possible_truths,
3436 toplev_predicate);
3438 for (e = node->indirect_calls; e; e = e->next_callee)
3440 struct inline_edge_summary *es = inline_edge_summary (e);
3441 struct predicate p;
3443 remap_edge_change_prob (inlined_edge, e);
3444 if (es->predicate)
3446 p = remap_predicate (info, callee_info,
3447 es->predicate, operand_map, offset_map,
3448 possible_truths, toplev_predicate);
3449 edge_set_predicate (e, &p);
3450 /* TODO: We should remove the edge for code that will be optimized
3451 out, but we need to keep verifiers and tree-inline happy.
3452 Make it cold for now. */
3453 if (false_predicate_p (&p))
3455 e->count = 0;
3456 e->frequency = 0;
3459 else
3460 edge_set_predicate (e, toplev_predicate);
3464 /* Same as remap_predicate, but set result into hint *HINT. */
3466 static void
3467 remap_hint_predicate (struct inline_summary *info,
3468 struct inline_summary *callee_info,
3469 struct predicate **hint,
3470 vec<int> operand_map,
3471 vec<int> offset_map,
3472 clause_t possible_truths,
3473 struct predicate *toplev_predicate)
3475 predicate p;
3477 if (!*hint)
3478 return;
3479 p = remap_predicate (info, callee_info,
3480 *hint,
3481 operand_map, offset_map,
3482 possible_truths, toplev_predicate);
3483 if (!false_predicate_p (&p) && !true_predicate_p (&p))
3485 if (!*hint)
3486 set_hint_predicate (hint, p);
3487 else
3488 **hint = and_predicates (info->conds, *hint, &p);
3492 /* We inlined EDGE. Update summary of the function we inlined into. */
3494 void
3495 inline_merge_summary (struct cgraph_edge *edge)
3497 struct inline_summary *callee_info = inline_summary (edge->callee);
3498 struct cgraph_node *to = (edge->caller->global.inlined_to
3499 ? edge->caller->global.inlined_to : edge->caller);
3500 struct inline_summary *info = inline_summary (to);
3501 clause_t clause = 0; /* not_inline is known to be false. */
3502 size_time_entry *e;
3503 vec<int> operand_map = vNULL;
3504 vec<int> offset_map = vNULL;
3505 int i;
3506 struct predicate toplev_predicate;
3507 struct predicate true_p = true_predicate ();
3508 struct inline_edge_summary *es = inline_edge_summary (edge);
3510 if (es->predicate)
3511 toplev_predicate = *es->predicate;
3512 else
3513 toplev_predicate = true_predicate ();
3515 if (ipa_node_params_vector.exists () && callee_info->conds)
3517 struct ipa_edge_args *args = IPA_EDGE_REF (edge);
3518 int count = ipa_get_cs_argument_count (args);
3519 int i;
3521 evaluate_properties_for_edge (edge, true, &clause, NULL, NULL, NULL);
3522 if (count)
3524 operand_map.safe_grow_cleared (count);
3525 offset_map.safe_grow_cleared (count);
3527 for (i = 0; i < count; i++)
3529 struct ipa_jump_func *jfunc = ipa_get_ith_jump_func (args, i);
3530 int map = -1;
3532 /* TODO: handle non-NOPs when merging. */
3533 if (jfunc->type == IPA_JF_PASS_THROUGH)
3535 if (ipa_get_jf_pass_through_operation (jfunc) == NOP_EXPR)
3536 map = ipa_get_jf_pass_through_formal_id (jfunc);
3537 if (!ipa_get_jf_pass_through_agg_preserved (jfunc))
3538 offset_map[i] = -1;
3540 else if (jfunc->type == IPA_JF_ANCESTOR)
3542 HOST_WIDE_INT offset = ipa_get_jf_ancestor_offset (jfunc);
3543 if (offset >= 0 && offset < INT_MAX)
3545 map = ipa_get_jf_ancestor_formal_id (jfunc);
3546 if (!ipa_get_jf_ancestor_agg_preserved (jfunc))
3547 offset = -1;
3548 offset_map[i] = offset;
3551 operand_map[i] = map;
3552 gcc_assert (map < ipa_get_param_count (IPA_NODE_REF (to)));
3555 for (i = 0; vec_safe_iterate (callee_info->entry, i, &e); i++)
3557 struct predicate p = remap_predicate (info, callee_info,
3558 &e->predicate, operand_map,
3559 offset_map, clause,
3560 &toplev_predicate);
3561 if (!false_predicate_p (&p))
3563 gcov_type add_time = ((gcov_type) e->time * edge->frequency
3564 + CGRAPH_FREQ_BASE / 2) / CGRAPH_FREQ_BASE;
3565 int prob = predicate_probability (callee_info->conds,
3566 &e->predicate,
3567 clause, es->param);
3568 add_time = apply_probability ((gcov_type) add_time, prob);
3569 if (add_time > MAX_TIME * INLINE_TIME_SCALE)
3570 add_time = MAX_TIME * INLINE_TIME_SCALE;
3571 if (prob != REG_BR_PROB_BASE
3572 && dump_file && (dump_flags & TDF_DETAILS))
3574 fprintf (dump_file, "\t\tScaling time by probability:%f\n",
3575 (double) prob / REG_BR_PROB_BASE);
3577 account_size_time (info, e->size, add_time, &p);
3580 remap_edge_summaries (edge, edge->callee, info, callee_info, operand_map,
3581 offset_map, clause, &toplev_predicate);
3582 remap_hint_predicate (info, callee_info,
3583 &callee_info->loop_iterations,
3584 operand_map, offset_map, clause, &toplev_predicate);
3585 remap_hint_predicate (info, callee_info,
3586 &callee_info->loop_stride,
3587 operand_map, offset_map, clause, &toplev_predicate);
3588 remap_hint_predicate (info, callee_info,
3589 &callee_info->array_index,
3590 operand_map, offset_map, clause, &toplev_predicate);
3592 inline_update_callee_summaries (edge->callee,
3593 inline_edge_summary (edge)->loop_depth);
3595 /* We do not maintain predicates of inlined edges, free it. */
3596 edge_set_predicate (edge, &true_p);
3597 /* Similarly remove param summaries. */
3598 es->param.release ();
3599 operand_map.release ();
3600 offset_map.release ();
3603 /* For performance reasons inline_merge_summary is not updating overall size
3604 and time. Recompute it. */
3606 void
3607 inline_update_overall_summary (struct cgraph_node *node)
3609 struct inline_summary *info = inline_summary (node);
3610 size_time_entry *e;
3611 int i;
3613 info->size = 0;
3614 info->time = 0;
3615 for (i = 0; vec_safe_iterate (info->entry, i, &e); i++)
3617 info->size += e->size, info->time += e->time;
3618 if (info->time > MAX_TIME * INLINE_TIME_SCALE)
3619 info->time = MAX_TIME * INLINE_TIME_SCALE;
3621 estimate_calls_size_and_time (node, &info->size, &info->min_size,
3622 &info->time, NULL,
3623 ~(clause_t) (1 << predicate_false_condition),
3624 vNULL, vNULL, vNULL);
3625 info->time = (info->time + INLINE_TIME_SCALE / 2) / INLINE_TIME_SCALE;
3626 info->size = (info->size + INLINE_SIZE_SCALE / 2) / INLINE_SIZE_SCALE;
3629 /* Return hints derrived from EDGE. */
3631 simple_edge_hints (struct cgraph_edge *edge)
3633 int hints = 0;
3634 struct cgraph_node *to = (edge->caller->global.inlined_to
3635 ? edge->caller->global.inlined_to : edge->caller);
3636 if (inline_summary (to)->scc_no
3637 && inline_summary (to)->scc_no == inline_summary (edge->callee)->scc_no
3638 && !cgraph_edge_recursive_p (edge))
3639 hints |= INLINE_HINT_same_scc;
3641 if (to->lto_file_data && edge->callee->lto_file_data
3642 && to->lto_file_data != edge->callee->lto_file_data)
3643 hints |= INLINE_HINT_cross_module;
3645 return hints;
3648 /* Estimate the time cost for the caller when inlining EDGE.
3649 Only to be called via estimate_edge_time, that handles the
3650 caching mechanism.
3652 When caching, also update the cache entry. Compute both time and
3653 size, since we always need both metrics eventually. */
3656 do_estimate_edge_time (struct cgraph_edge *edge)
3658 int time;
3659 int size;
3660 inline_hints hints;
3661 struct cgraph_node *callee;
3662 clause_t clause;
3663 vec<tree> known_vals;
3664 vec<tree> known_binfos;
3665 vec<ipa_agg_jump_function_p> known_aggs;
3666 struct inline_edge_summary *es = inline_edge_summary (edge);
3667 int min_size;
3669 callee = cgraph_function_or_thunk_node (edge->callee, NULL);
3671 gcc_checking_assert (edge->inline_failed);
3672 evaluate_properties_for_edge (edge, true,
3673 &clause, &known_vals, &known_binfos,
3674 &known_aggs);
3675 estimate_node_size_and_time (callee, clause, known_vals, known_binfos,
3676 known_aggs, &size, &min_size, &time, &hints, es->param);
3678 /* When we have profile feedback, we can quite safely identify hot
3679 edges and for those we disable size limits. Don't do that when
3680 probability that caller will call the callee is low however, since it
3681 may hurt optimization of the caller's hot path. */
3682 if (edge->count && cgraph_maybe_hot_edge_p (edge)
3683 && (edge->count * 2
3684 > (edge->caller->global.inlined_to
3685 ? edge->caller->global.inlined_to->count : edge->caller->count)))
3686 hints |= INLINE_HINT_known_hot;
3688 known_vals.release ();
3689 known_binfos.release ();
3690 known_aggs.release ();
3691 gcc_checking_assert (size >= 0);
3692 gcc_checking_assert (time >= 0);
3694 /* When caching, update the cache entry. */
3695 if (edge_growth_cache.exists ())
3697 inline_summary (edge->callee)->min_size = min_size;
3698 if ((int) edge_growth_cache.length () <= edge->uid)
3699 edge_growth_cache.safe_grow_cleared (cgraph_edge_max_uid);
3700 edge_growth_cache[edge->uid].time = time + (time >= 0);
3702 edge_growth_cache[edge->uid].size = size + (size >= 0);
3703 hints |= simple_edge_hints (edge);
3704 edge_growth_cache[edge->uid].hints = hints + 1;
3706 return time;
3710 /* Return estimated callee growth after inlining EDGE.
3711 Only to be called via estimate_edge_size. */
3714 do_estimate_edge_size (struct cgraph_edge *edge)
3716 int size;
3717 struct cgraph_node *callee;
3718 clause_t clause;
3719 vec<tree> known_vals;
3720 vec<tree> known_binfos;
3721 vec<ipa_agg_jump_function_p> known_aggs;
3723 /* When we do caching, use do_estimate_edge_time to populate the entry. */
3725 if (edge_growth_cache.exists ())
3727 do_estimate_edge_time (edge);
3728 size = edge_growth_cache[edge->uid].size;
3729 gcc_checking_assert (size);
3730 return size - (size > 0);
3733 callee = cgraph_function_or_thunk_node (edge->callee, NULL);
3735 /* Early inliner runs without caching, go ahead and do the dirty work. */
3736 gcc_checking_assert (edge->inline_failed);
3737 evaluate_properties_for_edge (edge, true,
3738 &clause, &known_vals, &known_binfos,
3739 &known_aggs);
3740 estimate_node_size_and_time (callee, clause, known_vals, known_binfos,
3741 known_aggs, &size, NULL, NULL, NULL, vNULL);
3742 known_vals.release ();
3743 known_binfos.release ();
3744 known_aggs.release ();
3745 return size;
3749 /* Estimate the growth of the caller when inlining EDGE.
3750 Only to be called via estimate_edge_size. */
3752 inline_hints
3753 do_estimate_edge_hints (struct cgraph_edge *edge)
3755 inline_hints hints;
3756 struct cgraph_node *callee;
3757 clause_t clause;
3758 vec<tree> known_vals;
3759 vec<tree> known_binfos;
3760 vec<ipa_agg_jump_function_p> known_aggs;
3762 /* When we do caching, use do_estimate_edge_time to populate the entry. */
3764 if (edge_growth_cache.exists ())
3766 do_estimate_edge_time (edge);
3767 hints = edge_growth_cache[edge->uid].hints;
3768 gcc_checking_assert (hints);
3769 return hints - 1;
3772 callee = cgraph_function_or_thunk_node (edge->callee, NULL);
3774 /* Early inliner runs without caching, go ahead and do the dirty work. */
3775 gcc_checking_assert (edge->inline_failed);
3776 evaluate_properties_for_edge (edge, true,
3777 &clause, &known_vals, &known_binfos,
3778 &known_aggs);
3779 estimate_node_size_and_time (callee, clause, known_vals, known_binfos,
3780 known_aggs, NULL, NULL, NULL, &hints, vNULL);
3781 known_vals.release ();
3782 known_binfos.release ();
3783 known_aggs.release ();
3784 hints |= simple_edge_hints (edge);
3785 return hints;
3789 /* Estimate self time of the function NODE after inlining EDGE. */
3792 estimate_time_after_inlining (struct cgraph_node *node,
3793 struct cgraph_edge *edge)
3795 struct inline_edge_summary *es = inline_edge_summary (edge);
3796 if (!es->predicate || !false_predicate_p (es->predicate))
3798 gcov_type time =
3799 inline_summary (node)->time + estimate_edge_time (edge);
3800 if (time < 0)
3801 time = 0;
3802 if (time > MAX_TIME)
3803 time = MAX_TIME;
3804 return time;
3806 return inline_summary (node)->time;
3810 /* Estimate the size of NODE after inlining EDGE which should be an
3811 edge to either NODE or a call inlined into NODE. */
3814 estimate_size_after_inlining (struct cgraph_node *node,
3815 struct cgraph_edge *edge)
3817 struct inline_edge_summary *es = inline_edge_summary (edge);
3818 if (!es->predicate || !false_predicate_p (es->predicate))
3820 int size = inline_summary (node)->size + estimate_edge_growth (edge);
3821 gcc_assert (size >= 0);
3822 return size;
3824 return inline_summary (node)->size;
3828 struct growth_data
3830 struct cgraph_node *node;
3831 bool self_recursive;
3832 int growth;
3836 /* Worker for do_estimate_growth. Collect growth for all callers. */
3838 static bool
3839 do_estimate_growth_1 (struct cgraph_node *node, void *data)
3841 struct cgraph_edge *e;
3842 struct growth_data *d = (struct growth_data *) data;
3844 for (e = node->callers; e; e = e->next_caller)
3846 gcc_checking_assert (e->inline_failed);
3848 if (e->caller == d->node
3849 || (e->caller->global.inlined_to
3850 && e->caller->global.inlined_to == d->node))
3851 d->self_recursive = true;
3852 d->growth += estimate_edge_growth (e);
3854 return false;
3858 /* Estimate the growth caused by inlining NODE into all callees. */
3861 do_estimate_growth (struct cgraph_node *node)
3863 struct growth_data d = { node, 0, false };
3864 struct inline_summary *info = inline_summary (node);
3866 cgraph_for_node_and_aliases (node, do_estimate_growth_1, &d, true);
3868 /* For self recursive functions the growth estimation really should be
3869 infinity. We don't want to return very large values because the growth
3870 plays various roles in badness computation fractions. Be sure to not
3871 return zero or negative growths. */
3872 if (d.self_recursive)
3873 d.growth = d.growth < info->size ? info->size : d.growth;
3874 else if (DECL_EXTERNAL (node->decl))
3876 else
3878 if (cgraph_will_be_removed_from_program_if_no_direct_calls (node))
3879 d.growth -= info->size;
3880 /* COMDAT functions are very often not shared across multiple units
3881 since they come from various template instantiations.
3882 Take this into account. */
3883 else if (DECL_COMDAT (node->decl)
3884 && cgraph_can_remove_if_no_direct_calls_p (node))
3885 d.growth -= (info->size
3886 * (100 - PARAM_VALUE (PARAM_COMDAT_SHARING_PROBABILITY))
3887 + 50) / 100;
3890 if (node_growth_cache.exists ())
3892 if ((int) node_growth_cache.length () <= node->uid)
3893 node_growth_cache.safe_grow_cleared (cgraph_max_uid);
3894 node_growth_cache[node->uid] = d.growth + (d.growth >= 0);
3896 return d.growth;
3900 /* Make cheap estimation if growth of NODE is likely positive knowing
3901 EDGE_GROWTH of one particular edge.
3902 We assume that most of other edges will have similar growth
3903 and skip computation if there are too many callers. */
3905 bool
3906 growth_likely_positive (struct cgraph_node *node, int edge_growth ATTRIBUTE_UNUSED)
3908 int max_callers;
3909 int ret;
3910 struct cgraph_edge *e;
3911 gcc_checking_assert (edge_growth > 0);
3913 /* Unlike for functions called once, we play unsafe with
3914 COMDATs. We can allow that since we know functions
3915 in consideration are small (and thus risk is small) and
3916 moreover grow estimates already accounts that COMDAT
3917 functions may or may not disappear when eliminated from
3918 current unit. With good probability making aggressive
3919 choice in all units is going to make overall program
3920 smaller.
3922 Consequently we ask cgraph_can_remove_if_no_direct_calls_p
3923 instead of
3924 cgraph_will_be_removed_from_program_if_no_direct_calls */
3925 if (DECL_EXTERNAL (node->decl)
3926 || !cgraph_can_remove_if_no_direct_calls_p (node))
3927 return true;
3929 /* If there is cached value, just go ahead. */
3930 if ((int)node_growth_cache.length () > node->uid
3931 && (ret = node_growth_cache[node->uid]))
3932 return ret > 0;
3933 if (!cgraph_will_be_removed_from_program_if_no_direct_calls (node)
3934 && (!DECL_COMDAT (node->decl)
3935 || !cgraph_can_remove_if_no_direct_calls_p (node)))
3936 return true;
3937 max_callers = inline_summary (node)->size * 4 / edge_growth + 2;
3939 for (e = node->callers; e; e = e->next_caller)
3941 max_callers--;
3942 if (!max_callers)
3943 return true;
3945 return estimate_growth (node) > 0;
3949 /* This function performs intraprocedural analysis in NODE that is required to
3950 inline indirect calls. */
3952 static void
3953 inline_indirect_intraprocedural_analysis (struct cgraph_node *node)
3955 ipa_analyze_node (node);
3956 if (dump_file && (dump_flags & TDF_DETAILS))
3958 ipa_print_node_params (dump_file, node);
3959 ipa_print_node_jump_functions (dump_file, node);
3964 /* Note function body size. */
3966 void
3967 inline_analyze_function (struct cgraph_node *node)
3969 push_cfun (DECL_STRUCT_FUNCTION (node->decl));
3971 if (dump_file)
3972 fprintf (dump_file, "\nAnalyzing function: %s/%u\n",
3973 node->name (), node->order);
3974 if (optimize && !node->thunk.thunk_p)
3975 inline_indirect_intraprocedural_analysis (node);
3976 compute_inline_parameters (node, false);
3977 if (!optimize)
3979 struct cgraph_edge *e;
3980 for (e = node->callees; e; e = e->next_callee)
3982 if (e->inline_failed == CIF_FUNCTION_NOT_CONSIDERED)
3983 e->inline_failed = CIF_FUNCTION_NOT_OPTIMIZED;
3984 e->call_stmt_cannot_inline_p = true;
3986 for (e = node->indirect_calls; e; e = e->next_callee)
3988 if (e->inline_failed == CIF_FUNCTION_NOT_CONSIDERED)
3989 e->inline_failed = CIF_FUNCTION_NOT_OPTIMIZED;
3990 e->call_stmt_cannot_inline_p = true;
3994 pop_cfun ();
3998 /* Called when new function is inserted to callgraph late. */
4000 static void
4001 add_new_function (struct cgraph_node *node, void *data ATTRIBUTE_UNUSED)
4003 inline_analyze_function (node);
4007 /* Note function body size. */
4009 void
4010 inline_generate_summary (void)
4012 struct cgraph_node *node;
4014 /* When not optimizing, do not bother to analyze. Inlining is still done
4015 because edge redirection needs to happen there. */
4016 if (!optimize && !flag_lto && !flag_wpa)
4017 return;
4019 function_insertion_hook_holder =
4020 cgraph_add_function_insertion_hook (&add_new_function, NULL);
4022 ipa_register_cgraph_hooks ();
4023 inline_free_summary ();
4025 FOR_EACH_DEFINED_FUNCTION (node)
4026 if (!node->alias)
4027 inline_analyze_function (node);
4031 /* Read predicate from IB. */
4033 static struct predicate
4034 read_predicate (struct lto_input_block *ib)
4036 struct predicate out;
4037 clause_t clause;
4038 int k = 0;
4042 gcc_assert (k <= MAX_CLAUSES);
4043 clause = out.clause[k++] = streamer_read_uhwi (ib);
4045 while (clause);
4047 /* Zero-initialize the remaining clauses in OUT. */
4048 while (k <= MAX_CLAUSES)
4049 out.clause[k++] = 0;
4051 return out;
4055 /* Write inline summary for edge E to OB. */
4057 static void
4058 read_inline_edge_summary (struct lto_input_block *ib, struct cgraph_edge *e)
4060 struct inline_edge_summary *es = inline_edge_summary (e);
4061 struct predicate p;
4062 int length, i;
4064 es->call_stmt_size = streamer_read_uhwi (ib);
4065 es->call_stmt_time = streamer_read_uhwi (ib);
4066 es->loop_depth = streamer_read_uhwi (ib);
4067 p = read_predicate (ib);
4068 edge_set_predicate (e, &p);
4069 length = streamer_read_uhwi (ib);
4070 if (length)
4072 es->param.safe_grow_cleared (length);
4073 for (i = 0; i < length; i++)
4074 es->param[i].change_prob = streamer_read_uhwi (ib);
4079 /* Stream in inline summaries from the section. */
4081 static void
4082 inline_read_section (struct lto_file_decl_data *file_data, const char *data,
4083 size_t len)
4085 const struct lto_function_header *header =
4086 (const struct lto_function_header *) data;
4087 const int cfg_offset = sizeof (struct lto_function_header);
4088 const int main_offset = cfg_offset + header->cfg_size;
4089 const int string_offset = main_offset + header->main_size;
4090 struct data_in *data_in;
4091 struct lto_input_block ib;
4092 unsigned int i, count2, j;
4093 unsigned int f_count;
4095 LTO_INIT_INPUT_BLOCK (ib, (const char *) data + main_offset, 0,
4096 header->main_size);
4098 data_in =
4099 lto_data_in_create (file_data, (const char *) data + string_offset,
4100 header->string_size, vNULL);
4101 f_count = streamer_read_uhwi (&ib);
4102 for (i = 0; i < f_count; i++)
4104 unsigned int index;
4105 struct cgraph_node *node;
4106 struct inline_summary *info;
4107 lto_symtab_encoder_t encoder;
4108 struct bitpack_d bp;
4109 struct cgraph_edge *e;
4110 predicate p;
4112 index = streamer_read_uhwi (&ib);
4113 encoder = file_data->symtab_node_encoder;
4114 node = cgraph (lto_symtab_encoder_deref (encoder, index));
4115 info = inline_summary (node);
4117 info->estimated_stack_size
4118 = info->estimated_self_stack_size = streamer_read_uhwi (&ib);
4119 info->size = info->self_size = streamer_read_uhwi (&ib);
4120 info->time = info->self_time = streamer_read_uhwi (&ib);
4122 bp = streamer_read_bitpack (&ib);
4123 info->inlinable = bp_unpack_value (&bp, 1);
4125 count2 = streamer_read_uhwi (&ib);
4126 gcc_assert (!info->conds);
4127 for (j = 0; j < count2; j++)
4129 struct condition c;
4130 c.operand_num = streamer_read_uhwi (&ib);
4131 c.code = (enum tree_code) streamer_read_uhwi (&ib);
4132 c.val = stream_read_tree (&ib, data_in);
4133 bp = streamer_read_bitpack (&ib);
4134 c.agg_contents = bp_unpack_value (&bp, 1);
4135 c.by_ref = bp_unpack_value (&bp, 1);
4136 if (c.agg_contents)
4137 c.offset = streamer_read_uhwi (&ib);
4138 vec_safe_push (info->conds, c);
4140 count2 = streamer_read_uhwi (&ib);
4141 gcc_assert (!info->entry);
4142 for (j = 0; j < count2; j++)
4144 struct size_time_entry e;
4146 e.size = streamer_read_uhwi (&ib);
4147 e.time = streamer_read_uhwi (&ib);
4148 e.predicate = read_predicate (&ib);
4150 vec_safe_push (info->entry, e);
4153 p = read_predicate (&ib);
4154 set_hint_predicate (&info->loop_iterations, p);
4155 p = read_predicate (&ib);
4156 set_hint_predicate (&info->loop_stride, p);
4157 p = read_predicate (&ib);
4158 set_hint_predicate (&info->array_index, p);
4159 for (e = node->callees; e; e = e->next_callee)
4160 read_inline_edge_summary (&ib, e);
4161 for (e = node->indirect_calls; e; e = e->next_callee)
4162 read_inline_edge_summary (&ib, e);
4165 lto_free_section_data (file_data, LTO_section_inline_summary, NULL, data,
4166 len);
4167 lto_data_in_delete (data_in);
4171 /* Read inline summary. Jump functions are shared among ipa-cp
4172 and inliner, so when ipa-cp is active, we don't need to write them
4173 twice. */
4175 void
4176 inline_read_summary (void)
4178 struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
4179 struct lto_file_decl_data *file_data;
4180 unsigned int j = 0;
4182 inline_summary_alloc ();
4184 while ((file_data = file_data_vec[j++]))
4186 size_t len;
4187 const char *data = lto_get_section_data (file_data,
4188 LTO_section_inline_summary,
4189 NULL, &len);
4190 if (data)
4191 inline_read_section (file_data, data, len);
4192 else
4193 /* Fatal error here. We do not want to support compiling ltrans units
4194 with different version of compiler or different flags than the WPA
4195 unit, so this should never happen. */
4196 fatal_error ("ipa inline summary is missing in input file");
4198 if (optimize)
4200 ipa_register_cgraph_hooks ();
4201 if (!flag_ipa_cp)
4202 ipa_prop_read_jump_functions ();
4204 function_insertion_hook_holder =
4205 cgraph_add_function_insertion_hook (&add_new_function, NULL);
4209 /* Write predicate P to OB. */
4211 static void
4212 write_predicate (struct output_block *ob, struct predicate *p)
4214 int j;
4215 if (p)
4216 for (j = 0; p->clause[j]; j++)
4218 gcc_assert (j < MAX_CLAUSES);
4219 streamer_write_uhwi (ob, p->clause[j]);
4221 streamer_write_uhwi (ob, 0);
4225 /* Write inline summary for edge E to OB. */
4227 static void
4228 write_inline_edge_summary (struct output_block *ob, struct cgraph_edge *e)
4230 struct inline_edge_summary *es = inline_edge_summary (e);
4231 int i;
4233 streamer_write_uhwi (ob, es->call_stmt_size);
4234 streamer_write_uhwi (ob, es->call_stmt_time);
4235 streamer_write_uhwi (ob, es->loop_depth);
4236 write_predicate (ob, es->predicate);
4237 streamer_write_uhwi (ob, es->param.length ());
4238 for (i = 0; i < (int) es->param.length (); i++)
4239 streamer_write_uhwi (ob, es->param[i].change_prob);
4243 /* Write inline summary for node in SET.
4244 Jump functions are shared among ipa-cp and inliner, so when ipa-cp is
4245 active, we don't need to write them twice. */
4247 void
4248 inline_write_summary (void)
4250 struct cgraph_node *node;
4251 struct output_block *ob = create_output_block (LTO_section_inline_summary);
4252 lto_symtab_encoder_t encoder = ob->decl_state->symtab_node_encoder;
4253 unsigned int count = 0;
4254 int i;
4256 for (i = 0; i < lto_symtab_encoder_size (encoder); i++)
4258 symtab_node *snode = lto_symtab_encoder_deref (encoder, i);
4259 cgraph_node *cnode = dyn_cast <cgraph_node *> (snode);
4260 if (cnode && cnode->definition && !cnode->alias)
4261 count++;
4263 streamer_write_uhwi (ob, count);
4265 for (i = 0; i < lto_symtab_encoder_size (encoder); i++)
4267 symtab_node *snode = lto_symtab_encoder_deref (encoder, i);
4268 cgraph_node *cnode = dyn_cast <cgraph_node *> (snode);
4269 if (cnode && (node = cnode)->definition && !node->alias)
4271 struct inline_summary *info = inline_summary (node);
4272 struct bitpack_d bp;
4273 struct cgraph_edge *edge;
4274 int i;
4275 size_time_entry *e;
4276 struct condition *c;
4278 streamer_write_uhwi (ob,
4279 lto_symtab_encoder_encode (encoder,
4281 node));
4282 streamer_write_hwi (ob, info->estimated_self_stack_size);
4283 streamer_write_hwi (ob, info->self_size);
4284 streamer_write_hwi (ob, info->self_time);
4285 bp = bitpack_create (ob->main_stream);
4286 bp_pack_value (&bp, info->inlinable, 1);
4287 streamer_write_bitpack (&bp);
4288 streamer_write_uhwi (ob, vec_safe_length (info->conds));
4289 for (i = 0; vec_safe_iterate (info->conds, i, &c); i++)
4291 streamer_write_uhwi (ob, c->operand_num);
4292 streamer_write_uhwi (ob, c->code);
4293 stream_write_tree (ob, c->val, true);
4294 bp = bitpack_create (ob->main_stream);
4295 bp_pack_value (&bp, c->agg_contents, 1);
4296 bp_pack_value (&bp, c->by_ref, 1);
4297 streamer_write_bitpack (&bp);
4298 if (c->agg_contents)
4299 streamer_write_uhwi (ob, c->offset);
4301 streamer_write_uhwi (ob, vec_safe_length (info->entry));
4302 for (i = 0; vec_safe_iterate (info->entry, i, &e); i++)
4304 streamer_write_uhwi (ob, e->size);
4305 streamer_write_uhwi (ob, e->time);
4306 write_predicate (ob, &e->predicate);
4308 write_predicate (ob, info->loop_iterations);
4309 write_predicate (ob, info->loop_stride);
4310 write_predicate (ob, info->array_index);
4311 for (edge = node->callees; edge; edge = edge->next_callee)
4312 write_inline_edge_summary (ob, edge);
4313 for (edge = node->indirect_calls; edge; edge = edge->next_callee)
4314 write_inline_edge_summary (ob, edge);
4317 streamer_write_char_stream (ob->main_stream, 0);
4318 produce_asm (ob, NULL);
4319 destroy_output_block (ob);
4321 if (optimize && !flag_ipa_cp)
4322 ipa_prop_write_jump_functions ();
4326 /* Release inline summary. */
4328 void
4329 inline_free_summary (void)
4331 struct cgraph_node *node;
4332 if (!inline_edge_summary_vec.exists ())
4333 return;
4334 FOR_EACH_DEFINED_FUNCTION (node)
4335 if (!node->alias)
4336 reset_inline_summary (node);
4337 if (function_insertion_hook_holder)
4338 cgraph_remove_function_insertion_hook (function_insertion_hook_holder);
4339 function_insertion_hook_holder = NULL;
4340 if (node_removal_hook_holder)
4341 cgraph_remove_node_removal_hook (node_removal_hook_holder);
4342 node_removal_hook_holder = NULL;
4343 if (edge_removal_hook_holder)
4344 cgraph_remove_edge_removal_hook (edge_removal_hook_holder);
4345 edge_removal_hook_holder = NULL;
4346 if (node_duplication_hook_holder)
4347 cgraph_remove_node_duplication_hook (node_duplication_hook_holder);
4348 node_duplication_hook_holder = NULL;
4349 if (edge_duplication_hook_holder)
4350 cgraph_remove_edge_duplication_hook (edge_duplication_hook_holder);
4351 edge_duplication_hook_holder = NULL;
4352 vec_free (inline_summary_vec);
4353 inline_edge_summary_vec.release ();
4354 if (edge_predicate_pool)
4355 free_alloc_pool (edge_predicate_pool);
4356 edge_predicate_pool = 0;