OSDN Git Service

* ipa-inline-analysis.c: Fix overly long lines.
[pf3gnuchains/gcc-fork.git] / gcc / ipa-inline-analysis.c
1 /* Inlining decision heuristics.
2    Copyright (C) 2003, 2004, 2007, 2008, 2009, 2010, 2011
3    Free Software Foundation, Inc.
4    Contributed by Jan Hubicka
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
12
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3.  If not see
20 <http://www.gnu.org/licenses/>.  */
21
22 /* Analysis used by the inliner and other passes limiting code size growth.
23
24    We estimate for each function
25      - function body size
26      - average function execution time
27      - inlining size benefit (that is how much of function body size
28        and its call sequence is expected to disappear by inlining)
29      - inlining time benefit
30      - function frame size
31    For each call
32      - call statement size and time
33
34    inlinie_summary datastructures store above information locally (i.e.
35    parameters of the function itself) and globally (i.e. parameters of
36    the function created by applying all the inline decisions already
37    present in the callgraph).
38
39    We provide accestor to the inline_summary datastructure and
40    basic logic updating the parameters when inlining is performed. 
41
42    The summaries are context sensitive.  Context means
43      1) partial assignment of known constant values of operands
44      2) whether function is inlined into the call or not.
45    It is easy to add more variants.  To represent function size and time
46    that depends on context (i.e. it is known to be optimized away when
47    context is known either by inlining or from IP-CP and clonning),
48    we use predicates. Predicates are logical formulas in
49    conjunctive-disjunctive form consisting of clauses. Clauses are bitmaps
50    specifying what conditions must be true. Conditions are simple test
51    of the form described above.
52
53    In order to make predicate (possibly) true, all of its clauses must
54    be (possibly) true. To make clause (possibly) true, one of conditions
55    it mentions must be (possibly) true.  There are fixed bounds on
56    number of clauses and conditions and all the manipulation functions
57    are conservative in positive direction. I.e. we may lose precision
58    by thinking that predicate may be true even when it is not.
59
60    estimate_edge_size and estimate_edge_growth can be used to query
61    function size/time in the given context.  inline_merge_summary merges
62    properties of caller and callee after inlining.
63
64    Finally pass_inline_parameters is exported.  This is used to drive
65    computation of function parameters used by the early inliner. IPA
66    inlined performs analysis via its analyze_function method. */
67
68 #include "config.h"
69 #include "system.h"
70 #include "coretypes.h"
71 #include "tm.h"
72 #include "tree.h"
73 #include "tree-inline.h"
74 #include "langhooks.h"
75 #include "flags.h"
76 #include "cgraph.h"
77 #include "diagnostic.h"
78 #include "gimple-pretty-print.h"
79 #include "timevar.h"
80 #include "params.h"
81 #include "tree-pass.h"
82 #include "coverage.h"
83 #include "ggc.h"
84 #include "tree-flow.h"
85 #include "ipa-prop.h"
86 #include "lto-streamer.h"
87 #include "data-streamer.h"
88 #include "tree-streamer.h"
89 #include "ipa-inline.h"
90 #include "alloc-pool.h"
91
92 /* Estimate runtime of function can easilly run into huge numbers with many
93    nested loops.  Be sure we can compute time * INLINE_SIZE_SCALE in integer.
94    For anything larger we use gcov_type.  */
95 #define MAX_TIME 1000000
96
97 /* Number of bits in integer, but we really want to be stable across different
98    hosts.  */
99 #define NUM_CONDITIONS 32
100
101 enum predicate_conditions
102 {
103   predicate_false_condition = 0,
104   predicate_not_inlined_condition = 1,
105   predicate_first_dynamic_condition = 2
106 };
107
108 /* Special condition code we use to represent test that operand is compile time
109    constant.  */
110 #define IS_NOT_CONSTANT ERROR_MARK
111
112 /* Holders of ipa cgraph hooks: */
113 static struct cgraph_node_hook_list *function_insertion_hook_holder;
114 static struct cgraph_node_hook_list *node_removal_hook_holder;
115 static struct cgraph_2node_hook_list *node_duplication_hook_holder;
116 static struct cgraph_2edge_hook_list *edge_duplication_hook_holder;
117 static struct cgraph_edge_hook_list *edge_removal_hook_holder;
118 static void inline_node_removal_hook (struct cgraph_node *, void *);
119 static void inline_node_duplication_hook (struct cgraph_node *,
120                                           struct cgraph_node *, void *);
121 static void inline_edge_removal_hook (struct cgraph_edge *, void *);
122 static void inline_edge_duplication_hook (struct cgraph_edge *,
123                                           struct cgraph_edge *,
124                                           void *);
125
126 /* VECtor holding inline summaries.  
127    In GGC memory because conditions might point to constant trees.  */
128 VEC(inline_summary_t,gc) *inline_summary_vec;
129 VEC(inline_edge_summary_t,heap) *inline_edge_summary_vec;
130
131 /* Cached node/edge growths.  */
132 VEC(int,heap) *node_growth_cache;
133 VEC(edge_growth_cache_entry,heap) *edge_growth_cache;
134
135 /* Edge predicates goes here.  */
136 static alloc_pool edge_predicate_pool;
137
138 /* Return true predicate (tautology).
139    We represent it by empty list of clauses.  */
140
141 static inline struct predicate
142 true_predicate (void)
143 {
144   struct predicate p;
145   p.clause[0]=0;
146   return p;
147 }
148
149
150 /* Return predicate testing single condition number COND.  */
151
152 static inline struct predicate
153 single_cond_predicate (int cond)
154 {
155   struct predicate p;
156   p.clause[0]=1 << cond;
157   p.clause[1]=0;
158   return p;
159 }
160
161
162 /* Return false predicate.  First clause require false condition.  */
163
164 static inline struct predicate
165 false_predicate (void)
166 {
167   return single_cond_predicate (predicate_false_condition);
168 }
169
170
171 /* Return true if P is (false).  */
172
173 static inline bool
174 true_predicate_p (struct predicate *p)
175 {
176   return !p->clause[0];
177 }
178
179
180 /* Return true if P is (false).  */
181
182 static inline bool
183 false_predicate_p (struct predicate *p)
184 {
185   if (p->clause[0] == (1 << predicate_false_condition))
186     {
187       gcc_checking_assert (!p->clause[1]
188                            && p->clause[0] == 1 << predicate_false_condition);
189       return true;
190     }
191   return false;
192 }
193
194
195 /* Return predicate that is set true when function is not inlined.  */
196 static inline struct predicate
197 not_inlined_predicate (void)
198 {
199   return single_cond_predicate (predicate_not_inlined_condition);
200 }
201
202
203 /* Add condition to condition list CONDS.  */
204
205 static struct predicate
206 add_condition (struct inline_summary *summary, int operand_num,
207                enum tree_code code, tree val)
208 {
209   int i;
210   struct condition *c;
211   struct condition new_cond;
212
213   for (i = 0; VEC_iterate (condition, summary->conds, i, c); i++)
214     {
215       if (c->operand_num == operand_num
216           && c->code == code
217           && c->val == val)
218         return single_cond_predicate (i + predicate_first_dynamic_condition);
219     }
220   /* Too many conditions.  Give up and return constant true.  */
221   if (i == NUM_CONDITIONS - predicate_first_dynamic_condition)
222     return true_predicate ();
223
224   new_cond.operand_num = operand_num;
225   new_cond.code = code;
226   new_cond.val = val;
227   VEC_safe_push (condition, gc, summary->conds, &new_cond);
228   return single_cond_predicate (i + predicate_first_dynamic_condition);
229 }
230
231
232 /* Add clause CLAUSE into the predicate P.  */
233
234 static inline void
235 add_clause (conditions conditions, struct predicate *p, clause_t clause)
236 {
237   int i;
238   int i2;
239   int insert_here = -1;
240   int c1, c2;
241
242   /* True clause.  */
243   if (!clause)
244     return;
245
246   /* False clause makes the whole predicate false.  Kill the other variants.  */
247   if (clause == (1 << predicate_false_condition))
248     {
249       p->clause[0] = (1 << predicate_false_condition);
250       p->clause[1] = 0;
251       return;
252     }
253   if (false_predicate_p (p))
254     return;
255
256   /* No one should be sily enough to add false into nontrivial clauses.  */
257   gcc_checking_assert (!(clause & (1 << predicate_false_condition)));
258
259   /* Look where to insert the clause.  At the same time prune out
260      clauses of P that are implied by the new clause and thus
261      redundant.  */
262   for (i = 0, i2 = 0; i <= MAX_CLAUSES; i++)
263     {
264       p->clause[i2] = p->clause[i];
265
266       if (!p->clause[i])
267         break;
268
269       /* If p->clause[i] implies clause, there is nothing to add.  */
270       if ((p->clause[i] & clause) == p->clause[i])
271         {
272           /* We had nothing to add, none of clauses should've become
273              redundant.  */
274           gcc_checking_assert (i == i2);
275           return;
276         }
277
278       if (p->clause[i] < clause && insert_here < 0)
279         insert_here = i2;
280
281       /* If clause implies p->clause[i], then p->clause[i] becomes redundant.
282          Otherwise the p->clause[i] has to stay.  */
283       if ((p->clause[i] & clause) != clause)
284         i2++;
285     }
286
287   /* Look for clauses that are obviously true.  I.e.
288      op0 == 5 || op0 != 5.  */
289   for (c1 = predicate_first_dynamic_condition; c1 < NUM_CONDITIONS; c1++)
290     for (c2 = c1 + 1; c2 <= NUM_CONDITIONS; c2++)
291       if ((clause & (1 << c1))
292           && (clause & (1 << c2)))
293         {
294           condition *cc1 = VEC_index (condition,
295                                       conditions,
296                                       c1 - predicate_first_dynamic_condition);
297           condition *cc2 = VEC_index (condition,
298                                       conditions,
299                                       c2 - predicate_first_dynamic_condition);
300           if (cc1->operand_num == cc2->operand_num
301               && cc1->val == cc2->val
302               && cc1->code == invert_tree_comparison (cc2->code,
303                                                       HONOR_NANS (TYPE_MODE (TREE_TYPE (cc1->val)))))
304             return;
305         }
306         
307
308   /* We run out of variants.  Be conservative in positive direction.  */
309   if (i2 == MAX_CLAUSES)
310     return;
311   /* Keep clauses in decreasing order. This makes equivalence testing easy.  */
312   p->clause[i2 + 1] = 0;
313   if (insert_here >= 0)
314     for (;i2 > insert_here; i2--)
315       p->clause[i2] = p->clause[i2 - 1];
316   else
317     insert_here = i2;
318   p->clause[insert_here] = clause;
319 }
320
321
322 /* Return P & P2.  */
323
324 static struct predicate
325 and_predicates (conditions conditions,
326                 struct predicate *p, struct predicate *p2)
327 {
328   struct predicate out = *p;
329   int i;
330
331   /* Avoid busy work.  */
332   if (false_predicate_p (p2) || true_predicate_p (p))
333     return *p2;
334   if (false_predicate_p (p) || true_predicate_p (p2))
335     return *p;
336
337   /* See how far predicates match.  */
338   for (i = 0; p->clause[i] && p->clause[i] == p2->clause[i]; i++)
339     {
340       gcc_checking_assert (i < MAX_CLAUSES);
341     }
342     
343   /* Combine the predicates rest.  */
344   for (; p2->clause[i]; i++)
345     {
346       gcc_checking_assert (i < MAX_CLAUSES);
347       add_clause (conditions, &out, p2->clause[i]);
348     }
349   return out;
350 }
351
352
353 /* Return true if predicates are obviously equal.  */
354
355 static inline bool
356 predicates_equal_p (struct predicate *p, struct predicate *p2)
357 {
358   int i;
359   for (i = 0; p->clause[i]; i++)
360     {
361       gcc_checking_assert (i < MAX_CLAUSES);
362       gcc_checking_assert (p->clause [i] > p->clause[i + 1]);
363       gcc_checking_assert (!p2->clause[i]
364                            || p2->clause [i] > p2->clause[i + 1]);
365       if (p->clause[i] != p2->clause[i])
366         return false;
367     }
368   return !p2->clause[i];
369 }
370
371
372 /* Return P | P2.  */
373
374 static struct predicate
375 or_predicates (conditions conditions, struct predicate *p, struct predicate *p2)
376 {
377   struct predicate out = true_predicate ();
378   int i,j;
379
380   /* Avoid busy work.  */
381   if (false_predicate_p (p2) || true_predicate_p (p))
382     return *p;
383   if (false_predicate_p (p) || true_predicate_p (p2))
384     return *p2;
385   if (predicates_equal_p (p, p2))
386     return *p;
387
388   /* OK, combine the predicates.  */
389   for (i = 0; p->clause[i]; i++)
390     for (j = 0; p2->clause[j]; j++)
391       {
392         gcc_checking_assert (i < MAX_CLAUSES && j < MAX_CLAUSES);
393         add_clause (conditions, &out, p->clause[i] | p2->clause[j]);
394       }
395   return out;
396 }
397
398
399 /* Having partial truth assignment in POSSIBLE_TRUTHS, return false
400    if predicate P is known to be false.  */
401
402 static bool
403 evaluate_predicate (struct predicate *p, clause_t possible_truths)
404 {
405   int i;
406
407   /* True remains true.  */
408   if (true_predicate_p (p))
409     return true;
410
411   gcc_assert (!(possible_truths & (1 << predicate_false_condition)));
412
413   /* See if we can find clause we can disprove.  */
414   for (i = 0; p->clause[i]; i++)
415     {
416       gcc_checking_assert (i < MAX_CLAUSES);
417       if (!(p->clause[i] & possible_truths))
418         return false;
419     }
420   return true;
421 }
422
423
424 /* Dump conditional COND.  */
425
426 static void
427 dump_condition (FILE *f, conditions conditions, int cond)
428 {
429   condition *c;
430   if (cond == predicate_false_condition)
431     fprintf (f, "false");
432   else if (cond == predicate_not_inlined_condition)
433     fprintf (f, "not inlined");
434   else
435     {
436       c = VEC_index (condition, conditions, cond - predicate_first_dynamic_condition);
437       fprintf (f, "op%i", c->operand_num);
438       if (c->code == IS_NOT_CONSTANT)
439         {
440           fprintf (f, " not constant");
441           return;
442         }
443       fprintf (f, " %s ", op_symbol_code (c->code));
444       print_generic_expr (f, c->val, 1);
445     }
446 }
447
448
449 /* Dump clause CLAUSE.  */
450
451 static void
452 dump_clause (FILE *f, conditions conds, clause_t clause)
453 {
454   int i;
455   bool found = false;
456   fprintf (f, "(");
457   if (!clause)
458     fprintf (f, "true");
459   for (i = 0; i < NUM_CONDITIONS; i++)
460     if (clause & (1 << i))
461       {
462         if (found)
463           fprintf (f, " || ");
464         found = true;
465         dump_condition (f, conds, i);
466       }
467   fprintf (f, ")");
468 }
469
470
471 /* Dump predicate PREDICATE.  */
472
473 static void
474 dump_predicate (FILE *f, conditions conds, struct predicate *pred)
475 {
476   int i;
477   if (true_predicate_p (pred))
478     dump_clause (f, conds, 0);
479   else
480     for (i = 0; pred->clause[i]; i++)
481       {
482         if (i)
483           fprintf (f, " && ");
484         dump_clause (f, conds, pred->clause[i]);
485       }
486   fprintf (f, "\n");
487 }
488
489
490 /* Record SIZE and TIME under condition PRED into the inline summary.  */
491
492 static void
493 account_size_time (struct inline_summary *summary, int size, int time,
494                    struct predicate *pred)
495 {
496   size_time_entry *e;
497   bool found = false;
498   int i;
499
500   if (false_predicate_p (pred))
501     return;
502
503   /* We need to create initial empty unconitional clause, but otherwie
504      we don't need to account empty times and sizes.  */
505   if (!size && !time && summary->entry)
506     return;
507
508   /* Watch overflow that might result from insane profiles.  */
509   if (time > MAX_TIME * INLINE_TIME_SCALE)
510     time = MAX_TIME * INLINE_TIME_SCALE;
511   gcc_assert (time >= 0);
512
513   for (i = 0; VEC_iterate (size_time_entry, summary->entry, i, e); i++)
514     if (predicates_equal_p (&e->predicate, pred))
515       {
516         found = true;
517         break;
518       }
519   if (i == 32)
520     {
521       i = 0;
522       found = true;
523       e = VEC_index (size_time_entry, summary->entry, 0);
524       gcc_assert (!e->predicate.clause[0]);
525     }
526   if (dump_file && (dump_flags & TDF_DETAILS) && (time || size))
527     {
528       fprintf (dump_file, "\t\tAccounting size:%3.2f, time:%3.2f on %spredicate:",
529                ((double)size) / INLINE_SIZE_SCALE,
530                ((double)time) / INLINE_TIME_SCALE,
531                found ? "" : "new ");
532       dump_predicate (dump_file, summary->conds, pred);
533     }
534   if (!found)
535     {
536       struct size_time_entry new_entry;
537       new_entry.size = size;
538       new_entry.time = time;
539       new_entry.predicate = *pred;
540       VEC_safe_push (size_time_entry, gc, summary->entry, &new_entry);
541     }
542   else
543     {
544       e->size += size;
545       e->time += time;
546       if (e->time > MAX_TIME * INLINE_TIME_SCALE)
547         e->time = MAX_TIME * INLINE_TIME_SCALE;
548     }
549 }
550
551 /* Set predicate for edge E.  */
552
553 static void
554 edge_set_predicate (struct cgraph_edge *e, struct predicate *predicate)
555 {
556   struct inline_edge_summary *es = inline_edge_summary (e);
557   if (predicate && !true_predicate_p (predicate))
558     {
559       if (!es->predicate)
560         es->predicate = (struct predicate *)pool_alloc (edge_predicate_pool);
561       *es->predicate = *predicate;
562     }
563   else
564     {
565       if (es->predicate)
566         pool_free (edge_predicate_pool, es->predicate);
567       es->predicate = NULL;
568     }
569 }
570
571
572 /* KNOWN_VALS is partial mapping of parameters of NODE to constant values.
573    Return clause of possible truths. When INLINE_P is true, assume that
574    we are inlining.  */
575
576 static clause_t
577 evaluate_conditions_for_known_args (struct cgraph_node *node,
578                                     bool inline_p,
579                                     VEC (tree, heap) *known_vals)
580 {
581   clause_t clause = inline_p ? 0 : 1 << predicate_not_inlined_condition;
582   struct inline_summary *info = inline_summary (node);
583   int i;
584   struct condition *c;
585
586   for (i = 0; VEC_iterate (condition, info->conds, i, c); i++)
587     {
588       tree val;
589       tree res;
590
591       /* We allow call stmt to have fewer arguments than the callee
592          function (especially for K&R style programs).  So bound
593          check here.  */
594       if (c->operand_num < (int)VEC_length (tree, known_vals))
595         val = VEC_index (tree, known_vals, c->operand_num);
596       else
597         val = NULL;
598
599       if (!val)
600         {
601           clause |= 1 << (i + predicate_first_dynamic_condition);
602           continue;
603         }
604       if (c->code == IS_NOT_CONSTANT)
605         continue;
606       res = fold_binary_to_constant (c->code, boolean_type_node, val, c->val);
607       if (res
608           && integer_zerop (res))
609         continue;
610       clause |= 1 << (i + predicate_first_dynamic_condition);
611     }
612   return clause;
613 }
614
615
616 /* Work out what conditions might be true at invocation of E.  */
617
618 static clause_t
619 evaluate_conditions_for_edge (struct cgraph_edge *e, bool inline_p)
620 {
621   clause_t clause = inline_p ? 0 : 1 << predicate_not_inlined_condition;
622   struct cgraph_node *callee = cgraph_function_or_thunk_node (e->callee, NULL);
623   struct inline_summary *info = inline_summary (callee);
624   int i;
625
626   if (ipa_node_params_vector && info->conds)
627     {
628       struct ipa_node_params *parms_info;
629       struct ipa_edge_args *args = IPA_EDGE_REF (e);
630       int i, count = ipa_get_cs_argument_count (args);
631       VEC (tree, heap) *known_vals = NULL;
632
633       if (e->caller->global.inlined_to)
634         parms_info = IPA_NODE_REF (e->caller->global.inlined_to);
635       else
636         parms_info = IPA_NODE_REF (e->caller);
637
638       if (count)
639         VEC_safe_grow_cleared (tree, heap, known_vals, count);
640       for (i = 0; i < count; i++)
641         {
642           tree cst = ipa_cst_from_jfunc (parms_info,
643                                          ipa_get_ith_jump_func (args, i));
644           if (cst)
645             VEC_replace (tree, known_vals, i, cst);
646         }
647       clause = evaluate_conditions_for_known_args (callee,
648                                                    inline_p, known_vals);
649       VEC_free (tree, heap, known_vals);
650     }
651   else
652     for (i = 0; i < (int)VEC_length (condition, info->conds); i++)
653       clause |= 1 << (i + predicate_first_dynamic_condition);
654
655   return clause;
656 }
657
658
659 /* Allocate the inline summary vector or resize it to cover all cgraph nodes. */
660
661 static void
662 inline_summary_alloc (void)
663 {
664   if (!node_removal_hook_holder)
665     node_removal_hook_holder =
666       cgraph_add_node_removal_hook (&inline_node_removal_hook, NULL);
667   if (!edge_removal_hook_holder)
668     edge_removal_hook_holder =
669       cgraph_add_edge_removal_hook (&inline_edge_removal_hook, NULL);
670   if (!node_duplication_hook_holder)
671     node_duplication_hook_holder =
672       cgraph_add_node_duplication_hook (&inline_node_duplication_hook, NULL);
673   if (!edge_duplication_hook_holder)
674     edge_duplication_hook_holder =
675       cgraph_add_edge_duplication_hook (&inline_edge_duplication_hook, NULL);
676
677   if (VEC_length (inline_summary_t, inline_summary_vec)
678       <= (unsigned) cgraph_max_uid)
679     VEC_safe_grow_cleared (inline_summary_t, gc,
680                            inline_summary_vec, cgraph_max_uid + 1);
681   if (VEC_length (inline_edge_summary_t, inline_edge_summary_vec)
682       <= (unsigned) cgraph_edge_max_uid)
683     VEC_safe_grow_cleared (inline_edge_summary_t, heap,
684                            inline_edge_summary_vec, cgraph_edge_max_uid + 1);
685   if (!edge_predicate_pool)
686     edge_predicate_pool = create_alloc_pool ("edge predicates",
687                                              sizeof (struct predicate),
688                                              10);
689 }
690
691 /* Hook that is called by cgraph.c when a node is removed.  */
692
693 static void
694 inline_node_removal_hook (struct cgraph_node *node, void *data ATTRIBUTE_UNUSED)
695 {
696   struct inline_summary *info;
697   if (VEC_length (inline_summary_t, inline_summary_vec)
698       <= (unsigned)node->uid)
699     return;
700   info = inline_summary (node);
701   reset_node_growth_cache (node);
702   VEC_free (condition, gc, info->conds);
703   VEC_free (size_time_entry, gc, info->entry);
704   info->conds = NULL;
705   info->entry = NULL;
706   memset (info, 0, sizeof (inline_summary_t));
707 }
708
709
710 /* Hook that is called by cgraph.c when a node is duplicated.  */
711
712 static void
713 inline_node_duplication_hook (struct cgraph_node *src, struct cgraph_node *dst,
714                               ATTRIBUTE_UNUSED void *data)
715 {
716   struct inline_summary *info;
717   inline_summary_alloc ();
718   info = inline_summary (dst);
719   memcpy (info, inline_summary (src),
720           sizeof (struct inline_summary));
721   /* TODO: as an optimization, we may avoid copying conditions
722      that are known to be false or true.  */
723   info->conds = VEC_copy (condition, gc, info->conds);
724
725   /* When there are any replacements in the function body, see if we can figure
726      out that something was optimized out.  */
727   if (ipa_node_params_vector && dst->clone.tree_map)
728     {
729       VEC(size_time_entry,gc) *entry = info->entry;
730       /* Use SRC parm info since it may not be copied yet.  */
731       struct ipa_node_params *parms_info = IPA_NODE_REF (src);
732       VEC (tree, heap) *known_vals = NULL;
733       int count = ipa_get_param_count (parms_info);
734       int i,j;
735       clause_t possible_truths;
736       struct predicate true_pred = true_predicate ();
737       size_time_entry *e;
738       int optimized_out_size = 0;
739       gcov_type optimized_out_time = 0;
740       bool inlined_to_p = false;
741       struct cgraph_edge *edge;
742
743       info->entry = 0;
744       VEC_safe_grow_cleared (tree, heap, known_vals, count);
745       for (i = 0; i < count; i++)
746         {
747           tree t = ipa_get_param (parms_info, i);
748           struct ipa_replace_map *r;
749
750           for (j = 0;
751                VEC_iterate (ipa_replace_map_p, dst->clone.tree_map, j, r);
752                j++)
753             {
754               if (r->old_tree == t
755                   && r->replace_p
756                   && !r->ref_p)
757                 {
758                   VEC_replace (tree, known_vals, i, r->new_tree);
759                   break;
760                 }
761             }
762         }
763       possible_truths = evaluate_conditions_for_known_args (dst,
764                                                             false, known_vals);
765       VEC_free (tree, heap, known_vals);
766
767       account_size_time (info, 0, 0, &true_pred);
768
769       /* Remap size_time vectors.
770          Simplify the predicate by prunning out alternatives that are known
771          to be false.
772          TODO: as on optimization, we can also eliminate conditions known
773          to be true.  */
774       for (i = 0; VEC_iterate (size_time_entry, entry, i, e); i++)
775         {
776           struct predicate new_predicate = true_predicate ();
777           for (j = 0; e->predicate.clause[j]; j++)
778             if (!(possible_truths & e->predicate.clause[j]))
779               {
780                 new_predicate = false_predicate ();
781                 break;
782               }
783             else
784               add_clause (info->conds, &new_predicate,
785                           possible_truths & e->predicate.clause[j]);
786           if (false_predicate_p (&new_predicate))
787             {
788               optimized_out_size += e->size;
789               optimized_out_time += e->time;
790             }
791           else
792             account_size_time (info, e->size, e->time, &new_predicate);
793         }
794
795       /* Remap edge predicates with the same simplification as above.
796          Also copy constantness arrays.   */
797       for (edge = dst->callees; edge; edge = edge->next_callee)
798         {
799           struct predicate new_predicate = true_predicate ();
800           struct inline_edge_summary *es = inline_edge_summary (edge);
801
802           if (!edge->inline_failed)
803             inlined_to_p = true;
804           if (!es->predicate)
805             continue;
806           for (j = 0; es->predicate->clause[j]; j++)
807             if (!(possible_truths & es->predicate->clause[j]))
808               {
809                 new_predicate = false_predicate ();
810                 break;
811               }
812             else
813               add_clause (info->conds, &new_predicate,
814                           possible_truths & es->predicate->clause[j]);
815           if (false_predicate_p (&new_predicate)
816               && !false_predicate_p (es->predicate))
817             {
818               optimized_out_size += es->call_stmt_size * INLINE_SIZE_SCALE;
819               optimized_out_time += (es->call_stmt_time
820                                      * (INLINE_TIME_SCALE / CGRAPH_FREQ_BASE)
821                                      * edge->frequency);
822               edge->frequency = 0;
823             }
824           *es->predicate = new_predicate;
825         }
826
827       /* Remap indirect edge predicates with the same simplificaiton as above. 
828          Also copy constantness arrays.   */
829       for (edge = dst->indirect_calls; edge; edge = edge->next_callee)
830         {
831           struct predicate new_predicate = true_predicate ();
832           struct inline_edge_summary *es = inline_edge_summary (edge);
833
834           if (!edge->inline_failed)
835             inlined_to_p = true;
836           if (!es->predicate)
837             continue;
838           for (j = 0; es->predicate->clause[j]; j++)
839             if (!(possible_truths & es->predicate->clause[j]))
840               {
841                 new_predicate = false_predicate ();
842                 break;
843               }
844             else
845               add_clause (info->conds, &new_predicate,
846                           possible_truths & es->predicate->clause[j]);
847           if (false_predicate_p (&new_predicate)
848               && !false_predicate_p (es->predicate))
849             {
850               optimized_out_size += es->call_stmt_size * INLINE_SIZE_SCALE;
851               optimized_out_time += (es->call_stmt_time
852                                      * (INLINE_TIME_SCALE / CGRAPH_FREQ_BASE)
853                                      * edge->frequency);
854               edge->frequency = 0;
855             }
856           *es->predicate = new_predicate;
857         }
858
859       /* If inliner or someone after inliner will ever start producing
860          non-trivial clones, we will get trouble with lack of information
861          about updating self sizes, because size vectors already contains
862          sizes of the calees.  */
863       gcc_assert (!inlined_to_p 
864                   || (!optimized_out_size && !optimized_out_time));
865
866       info->size -= optimized_out_size / INLINE_SIZE_SCALE;
867       info->self_size -= optimized_out_size / INLINE_SIZE_SCALE;
868       gcc_assert (info->size > 0);
869       gcc_assert (info->self_size > 0);
870
871       optimized_out_time /= INLINE_TIME_SCALE;
872       if (optimized_out_time > MAX_TIME)
873         optimized_out_time = MAX_TIME;
874       info->time -= optimized_out_time;
875       info->self_time -= optimized_out_time;
876       if (info->time < 0)
877         info->time = 0;
878       if (info->self_time < 0)
879         info->self_time = 0;
880     }
881   else
882     info->entry = VEC_copy (size_time_entry, gc, info->entry);
883 }
884
885
886 /* Hook that is called by cgraph.c when a node is duplicated.  */
887
888 static void
889 inline_edge_duplication_hook (struct cgraph_edge *src, struct cgraph_edge *dst,
890                               ATTRIBUTE_UNUSED void *data)
891 {
892   struct inline_edge_summary *info;
893   struct inline_edge_summary *srcinfo;
894   inline_summary_alloc ();
895   info = inline_edge_summary (dst);
896   srcinfo = inline_edge_summary (src);
897   memcpy (info, srcinfo,
898           sizeof (struct inline_edge_summary));
899   info->predicate = NULL;
900   edge_set_predicate (dst, srcinfo->predicate);
901 }
902
903
904 /* Keep edge cache consistent across edge removal.  */
905
906 static void
907 inline_edge_removal_hook (struct cgraph_edge *edge, void *data ATTRIBUTE_UNUSED)
908 {
909   if (edge_growth_cache)
910     reset_edge_growth_cache (edge);
911   if (edge->uid < (int)VEC_length (inline_edge_summary_t, inline_edge_summary_vec))
912     {
913       edge_set_predicate (edge, NULL);
914       memset (inline_edge_summary (edge), 0, sizeof (struct inline_edge_summary));
915     }
916 }
917
918
919 /* Initialize growth caches.  */
920
921 void
922 initialize_growth_caches (void)
923 {
924   if (cgraph_edge_max_uid)
925     VEC_safe_grow_cleared (edge_growth_cache_entry, heap, edge_growth_cache,
926                            cgraph_edge_max_uid);
927   if (cgraph_max_uid)
928     VEC_safe_grow_cleared (int, heap, node_growth_cache, cgraph_max_uid);
929 }
930
931
932 /* Free growth caches.  */
933
934 void
935 free_growth_caches (void)
936 {
937   VEC_free (edge_growth_cache_entry, heap, edge_growth_cache);
938   edge_growth_cache = 0;
939   VEC_free (int, heap, node_growth_cache);
940   node_growth_cache = 0;
941 }
942
943
944 /* Dump edge summaries associated to NODE and recursively to all clones.
945    Indent by INDENT.  */
946
947 static void
948 dump_inline_edge_summary (FILE * f, int indent, struct cgraph_node *node,
949                           struct inline_summary *info)
950 {
951   struct cgraph_edge *edge;
952   for (edge = node->callees; edge; edge = edge->next_callee)
953     {
954       struct inline_edge_summary *es = inline_edge_summary (edge);
955       struct cgraph_node *callee = cgraph_function_or_thunk_node (edge->callee, NULL);
956       fprintf (f, "%*s%s/%i %s\n%*s  loop depth:%2i freq:%4i size:%2i time: %2i callee size:%2i stack:%2i",
957                indent, "", cgraph_node_name (callee),
958                callee->uid, 
959                !edge->inline_failed ? "inlined"
960                : cgraph_inline_failed_string (edge->inline_failed),
961                indent, "",
962                es->loop_depth,  
963                edge->frequency,
964                es->call_stmt_size,
965                es->call_stmt_time,
966                (int)inline_summary (callee)->size,
967                (int)inline_summary (callee)->estimated_stack_size);
968       if (es->predicate)
969         {
970           fprintf (f, " predicate: ");
971           dump_predicate (f, info->conds, es->predicate);
972         }
973       else
974           fprintf (f, "\n");
975       if (!edge->inline_failed)
976         {
977           fprintf (f, "%*sStack frame offset %i, callee self size %i, callee size %i\n",
978                    indent+2, "",
979                    (int)inline_summary (callee)->stack_frame_offset,
980                    (int)inline_summary (callee)->estimated_self_stack_size,
981                    (int)inline_summary (callee)->estimated_stack_size);
982           dump_inline_edge_summary (f, indent+2, callee, info);
983         }
984     }
985   for (edge = node->indirect_calls; edge; edge = edge->next_callee)
986     {
987       struct inline_edge_summary *es = inline_edge_summary (edge);
988       fprintf (f, "%*sindirect call loop depth:%2i freq:%4i size:%2i"
989                " time: %2i\n",
990                indent, "",
991                es->loop_depth,  
992                edge->frequency,
993                es->call_stmt_size,
994                es->call_stmt_time);
995       if (es->predicate)
996         {
997           fprintf (f, "predicate: ");
998           dump_predicate (f, info->conds, es->predicate);
999         }
1000       else
1001         fprintf (f, "\n");
1002     }
1003 }
1004
1005
1006 void
1007 dump_inline_summary (FILE * f, struct cgraph_node *node)
1008 {
1009   if (node->analyzed)
1010     {
1011       struct inline_summary *s = inline_summary (node);
1012       size_time_entry *e;
1013       int i;
1014       fprintf (f, "Inline summary for %s/%i", cgraph_node_name (node),
1015                node->uid);
1016       if (DECL_DISREGARD_INLINE_LIMITS (node->decl))
1017         fprintf (f, " always_inline");
1018       if (s->inlinable)
1019         fprintf (f, " inlinable");
1020       fprintf (f, "\n  self time:       %i\n",
1021                s->self_time);
1022       fprintf (f, "  global time:     %i\n", s->time);
1023       fprintf (f, "  self size:       %i\n",
1024                s->self_size);
1025       fprintf (f, "  global size:     %i\n", s->size);
1026       fprintf (f, "  self stack:      %i\n",
1027                (int) s->estimated_self_stack_size);
1028       fprintf (f, "  global stack:    %i\n",
1029                (int) s->estimated_stack_size);
1030       for (i = 0;
1031            VEC_iterate (size_time_entry, s->entry, i, e);
1032            i++)
1033         {
1034           fprintf (f, "    size:%f, time:%f, predicate:",
1035                    (double) e->size / INLINE_SIZE_SCALE,
1036                    (double) e->time / INLINE_TIME_SCALE);
1037           dump_predicate (f, s->conds, &e->predicate);
1038         }
1039       fprintf (f, "  calls:\n");
1040       dump_inline_edge_summary (f, 4, node, s);
1041       fprintf (f, "\n");
1042     }
1043 }
1044
1045 DEBUG_FUNCTION void
1046 debug_inline_summary (struct cgraph_node *node)
1047 {
1048   dump_inline_summary (stderr, node);
1049 }
1050
1051 void
1052 dump_inline_summaries (FILE *f)
1053 {
1054   struct cgraph_node *node;
1055
1056   for (node = cgraph_nodes; node; node = node->next)
1057     if (node->analyzed && !node->global.inlined_to)
1058       dump_inline_summary (f, node);
1059 }
1060
1061 /* Give initial reasons why inlining would fail on EDGE.  This gets either
1062    nullified or usually overwritten by more precise reasons later.  */
1063
1064 void
1065 initialize_inline_failed (struct cgraph_edge *e)
1066 {
1067   struct cgraph_node *callee = e->callee;
1068
1069   if (e->indirect_unknown_callee)
1070     e->inline_failed = CIF_INDIRECT_UNKNOWN_CALL;
1071   else if (!callee->analyzed)
1072     e->inline_failed = CIF_BODY_NOT_AVAILABLE;
1073   else if (callee->local.redefined_extern_inline)
1074     e->inline_failed = CIF_REDEFINED_EXTERN_INLINE;
1075   else if (e->call_stmt && gimple_call_cannot_inline_p (e->call_stmt))
1076     e->inline_failed = CIF_MISMATCHED_ARGUMENTS;
1077   else
1078     e->inline_failed = CIF_FUNCTION_NOT_CONSIDERED;
1079 }
1080
1081 /* Callback of walk_aliased_vdefs.  Flags that it has been invoked to the
1082    boolean variable pointed to by DATA.  */
1083
1084 static bool
1085 mark_modified (ao_ref *ao ATTRIBUTE_UNUSED, tree vdef ATTRIBUTE_UNUSED,
1086                      void *data)
1087 {
1088   bool *b = (bool *) data;
1089   *b = true;
1090   return true;
1091 }
1092
1093 /* If OP reffers to value of function parameter, return 
1094    the corresponding parameter.  */
1095
1096 static tree
1097 unmodified_parm (gimple stmt, tree op)
1098 {
1099   /* SSA_NAME referring to parm default def?  */
1100   if (TREE_CODE (op) == SSA_NAME
1101       && SSA_NAME_IS_DEFAULT_DEF (op)
1102       && TREE_CODE (SSA_NAME_VAR (op)) == PARM_DECL)
1103     return SSA_NAME_VAR (op);
1104   /* Non-SSA parm reference?  */
1105   if (TREE_CODE (op) == PARM_DECL)
1106     {
1107       bool modified = false;
1108
1109       ao_ref refd;
1110       ao_ref_init (&refd, op);
1111       walk_aliased_vdefs (&refd, gimple_vuse (stmt), mark_modified, &modified,
1112                           NULL);
1113       if (!modified)
1114         return op;
1115     }
1116   /* Assignment from a parameter?  */
1117   if (TREE_CODE (op) == SSA_NAME
1118       && !SSA_NAME_IS_DEFAULT_DEF (op)
1119       && gimple_assign_single_p (SSA_NAME_DEF_STMT (op)))
1120     return unmodified_parm (SSA_NAME_DEF_STMT (op),
1121                             gimple_assign_rhs1 (SSA_NAME_DEF_STMT (op)));
1122   return NULL;
1123 }
1124
1125 /* See if statement might disappear after inlining.
1126    0 - means not eliminated
1127    1 - half of statements goes away
1128    2 - for sure it is eliminated.
1129    We are not terribly sophisticated, basically looking for simple abstraction
1130    penalty wrappers.  */
1131
1132 static int
1133 eliminated_by_inlining_prob (gimple stmt)
1134 {
1135   enum gimple_code code = gimple_code (stmt);
1136
1137   if (!optimize)
1138     return 0;
1139
1140   switch (code)
1141     {
1142       case GIMPLE_RETURN:
1143         return 2;
1144       case GIMPLE_ASSIGN:
1145         if (gimple_num_ops (stmt) != 2)
1146           return 0;
1147
1148         /* Casts of parameters, loads from parameters passed by reference
1149            and stores to return value or parameters are often free after
1150            inlining dua to SRA and further combining.
1151            Assume that half of statements goes away.  */
1152         if (gimple_assign_rhs_code (stmt) == CONVERT_EXPR
1153             || gimple_assign_rhs_code (stmt) == NOP_EXPR
1154             || gimple_assign_rhs_code (stmt) == VIEW_CONVERT_EXPR
1155             || gimple_assign_rhs_class (stmt) == GIMPLE_SINGLE_RHS)
1156           {
1157             tree rhs = gimple_assign_rhs1 (stmt);
1158             tree lhs = gimple_assign_lhs (stmt);
1159             tree inner_rhs = get_base_address (rhs);
1160             tree inner_lhs = get_base_address (lhs);
1161             bool rhs_free = false;
1162             bool lhs_free = false;
1163
1164             if (!inner_rhs)
1165               inner_rhs = rhs;
1166             if (!inner_lhs)
1167               inner_lhs = lhs;
1168
1169             if (unmodified_parm (stmt, inner_rhs))
1170               rhs_free = true;
1171             if (rhs_free && is_gimple_reg (lhs))
1172               lhs_free = true;
1173             if (((TREE_CODE (inner_lhs) == PARM_DECL
1174                   || (TREE_CODE (inner_lhs) == SSA_NAME
1175                       && SSA_NAME_IS_DEFAULT_DEF (inner_lhs)
1176                       && TREE_CODE (SSA_NAME_VAR (inner_lhs)) == PARM_DECL))
1177                  && inner_lhs != lhs)
1178                 || TREE_CODE (inner_lhs) == RESULT_DECL
1179                 || (TREE_CODE (inner_lhs) == SSA_NAME
1180                     && TREE_CODE (SSA_NAME_VAR (inner_lhs)) == RESULT_DECL))
1181               lhs_free = true;
1182             if (lhs_free
1183                 && (is_gimple_reg (rhs) || is_gimple_min_invariant (rhs)))
1184               rhs_free = true;
1185             if (lhs_free && rhs_free)
1186               return 1;
1187           }
1188         return 0;
1189       default:
1190         return 0;
1191     }
1192 }
1193
1194
1195 /* If BB ends by a conditional we can turn into predicates, attach corresponding
1196    predicates to the CFG edges.   */
1197
1198 static void
1199 set_cond_stmt_execution_predicate (struct ipa_node_params *info,
1200                                    struct inline_summary *summary,
1201                                    basic_block bb)
1202 {
1203   gimple last;
1204   tree op;
1205   int index;
1206   enum tree_code code, inverted_code;
1207   edge e;
1208   edge_iterator ei;
1209   gimple set_stmt;
1210   tree op2;
1211   tree parm;
1212   tree base;
1213
1214   last = last_stmt (bb);
1215   if (!last
1216       || gimple_code (last) != GIMPLE_COND)
1217     return;
1218   if (!is_gimple_ip_invariant (gimple_cond_rhs (last)))
1219     return;
1220   op = gimple_cond_lhs (last);
1221   /* TODO: handle conditionals like
1222      var = op0 < 4;
1223      if (var != 0).  */
1224   parm = unmodified_parm (last, op);
1225   if (parm)
1226     {
1227       index = ipa_get_param_decl_index (info, parm);
1228       if (index == -1)
1229         return;
1230       code = gimple_cond_code (last);
1231       inverted_code
1232          = invert_tree_comparison (code,
1233                                    HONOR_NANS (TYPE_MODE (TREE_TYPE (op))));
1234
1235       FOR_EACH_EDGE (e, ei, bb->succs)
1236         {
1237           struct predicate p = add_condition (summary,
1238                                               index,
1239                                               e->flags & EDGE_TRUE_VALUE
1240                                               ? code : inverted_code,
1241                                               gimple_cond_rhs (last));
1242           e->aux = pool_alloc (edge_predicate_pool);
1243           *(struct predicate *)e->aux = p;
1244         }
1245     }
1246
1247   if (TREE_CODE (op) != SSA_NAME)
1248     return;
1249   /* Special case
1250      if (builtin_constant_p (op))
1251        constant_code
1252      else
1253        nonconstant_code.
1254      Here we can predicate nonconstant_code.  We can't
1255      really handle constant_code since we have no predicate
1256      for this and also the constant code is not known to be
1257      optimized away when inliner doen't see operand is constant.
1258      Other optimizers might think otherwise.  */
1259   set_stmt = SSA_NAME_DEF_STMT (op);
1260   if (!gimple_call_builtin_p (set_stmt, BUILT_IN_CONSTANT_P)
1261       || gimple_call_num_args (set_stmt) != 1)
1262     return;
1263   op2 = gimple_call_arg (set_stmt, 0);
1264   base = get_base_address (op2);
1265   parm = unmodified_parm (set_stmt, base ? base : op2);
1266   if (!parm)
1267     return;
1268   index = ipa_get_param_decl_index (info, parm);
1269   if (index == -1)
1270     return;
1271   if (gimple_cond_code (last) != NE_EXPR
1272       || !integer_zerop (gimple_cond_rhs (last)))
1273     return;
1274   FOR_EACH_EDGE (e, ei, bb->succs)
1275     if (e->flags & EDGE_FALSE_VALUE)
1276       {
1277         struct predicate p = add_condition (summary,
1278                                             index,
1279                                             IS_NOT_CONSTANT,
1280                                             NULL);
1281         e->aux = pool_alloc (edge_predicate_pool);
1282         *(struct predicate *)e->aux = p;
1283       }
1284 }
1285
1286
1287 /* If BB ends by a switch we can turn into predicates, attach corresponding
1288    predicates to the CFG edges.   */
1289
1290 static void
1291 set_switch_stmt_execution_predicate (struct ipa_node_params *info,
1292                                    struct inline_summary *summary,
1293                                    basic_block bb)
1294 {
1295   gimple last;
1296   tree op;
1297   int index;
1298   edge e;
1299   edge_iterator ei;
1300   size_t n;
1301   size_t case_idx;
1302   tree parm;
1303
1304   last = last_stmt (bb);
1305   if (!last
1306       || gimple_code (last) != GIMPLE_SWITCH)
1307     return;
1308   op = gimple_switch_index (last);
1309   parm = unmodified_parm (last, op);
1310   if (!parm)
1311     return;
1312   index = ipa_get_param_decl_index (info, parm);
1313   if (index == -1)
1314     return;
1315
1316   FOR_EACH_EDGE (e, ei, bb->succs)
1317     {
1318       e->aux = pool_alloc (edge_predicate_pool);
1319       *(struct predicate *)e->aux = false_predicate ();
1320     }
1321   n = gimple_switch_num_labels(last);
1322   for (case_idx = 0; case_idx < n; ++case_idx)
1323     {
1324       tree cl = gimple_switch_label (last, case_idx);
1325       tree min, max;
1326       struct predicate p;
1327
1328       e = find_edge (bb, label_to_block (CASE_LABEL (cl)));
1329       min = CASE_LOW (cl);
1330       max = CASE_HIGH (cl);
1331
1332       /* For default we might want to construct predicate that none
1333          of cases is met, but it is bit hard to do not having negations
1334          of conditionals handy.  */
1335       if (!min && !max)
1336         p = true_predicate ();
1337       else if (!max)
1338         p = add_condition (summary, index,
1339                            EQ_EXPR,
1340                            min);
1341       else
1342         {
1343           struct predicate p1, p2;
1344           p1 = add_condition (summary, index,
1345                               GE_EXPR,
1346                               min);
1347           p2 = add_condition (summary, index,
1348                               LE_EXPR,
1349                               max);
1350           p = and_predicates (summary->conds, &p1, &p2);
1351         }
1352       *(struct predicate *)e->aux
1353         = or_predicates (summary->conds, &p, (struct predicate *)e->aux);
1354     }
1355 }
1356
1357
1358 /* For each BB in NODE attach to its AUX pointer predicate under
1359    which it is executable.  */
1360
1361 static void
1362 compute_bb_predicates (struct cgraph_node *node,
1363                        struct ipa_node_params *parms_info,
1364                        struct inline_summary *summary)
1365 {
1366   struct function *my_function = DECL_STRUCT_FUNCTION (node->decl);
1367   bool done = false;
1368   basic_block bb;
1369
1370   FOR_EACH_BB_FN (bb, my_function)
1371     {
1372       set_cond_stmt_execution_predicate (parms_info, summary, bb);
1373       set_switch_stmt_execution_predicate (parms_info, summary, bb);
1374     }
1375
1376   /* Entry block is always executable.  */
1377   ENTRY_BLOCK_PTR_FOR_FUNCTION (my_function)->aux
1378     = pool_alloc (edge_predicate_pool);
1379   *(struct predicate *)ENTRY_BLOCK_PTR_FOR_FUNCTION (my_function)->aux
1380     = true_predicate ();
1381
1382   /* A simple dataflow propagation of predicates forward in the CFG.
1383      TODO: work in reverse postorder.  */
1384   while (!done)
1385     {
1386       done = true;
1387       FOR_EACH_BB_FN (bb, my_function)
1388         {
1389           struct predicate p = false_predicate ();
1390           edge e;
1391           edge_iterator ei;
1392           FOR_EACH_EDGE (e, ei, bb->preds)
1393             {
1394               if (e->src->aux)
1395                 {
1396                   struct predicate this_bb_predicate
1397                      = *(struct predicate *)e->src->aux;
1398                   if (e->aux)
1399                     this_bb_predicate
1400                        = and_predicates (summary->conds, &this_bb_predicate,
1401                                          (struct predicate *)e->aux);
1402                   p = or_predicates (summary->conds, &p, &this_bb_predicate);
1403                   if (true_predicate_p (&p))
1404                     break;
1405                 }
1406             }
1407           if (false_predicate_p (&p))
1408             gcc_assert (!bb->aux);
1409           else
1410             {
1411               if (!bb->aux)
1412                 {
1413                   done = false;
1414                   bb->aux = pool_alloc (edge_predicate_pool);
1415                   *((struct predicate *)bb->aux) = p;
1416                 }
1417               else if (!predicates_equal_p (&p, (struct predicate *)bb->aux))
1418                 {
1419                   done = false;
1420                   *((struct predicate *)bb->aux) = p;
1421                 }
1422             }
1423         }
1424     }
1425 }
1426
1427
1428 /* We keep info about constantness of SSA names.  */
1429
1430 typedef struct predicate predicate_t;
1431 DEF_VEC_O (predicate_t);
1432 DEF_VEC_ALLOC_O (predicate_t, heap);
1433
1434
1435 /* Return predicate specifying when the STMT might have result that is not
1436    a compile time constant.  */
1437
1438 static struct predicate
1439 will_be_nonconstant_predicate (struct ipa_node_params *info,
1440                                struct inline_summary *summary,
1441                                gimple stmt,
1442                                VEC (predicate_t, heap) *nonconstant_names)
1443                               
1444 {
1445   struct predicate p = true_predicate ();
1446   ssa_op_iter iter;
1447   tree use;
1448   struct predicate op_non_const;
1449   bool is_load;
1450
1451   /* What statments might be optimized away
1452      when their arguments are constant
1453      TODO: also trivial builtins.
1454      builtin_constant_p is already handled later.  */
1455   if (gimple_code (stmt) != GIMPLE_ASSIGN
1456       && gimple_code (stmt) != GIMPLE_COND
1457       && gimple_code (stmt) != GIMPLE_SWITCH)
1458     return p;
1459
1460   /* Stores will stay anyway.  */
1461   if (gimple_vdef (stmt))
1462     return p;
1463
1464   is_load = gimple_vuse (stmt) != NULL;
1465
1466   /* Loads can be optimized when the value is known.  */
1467   if (is_load)
1468     {
1469       tree op = gimple_assign_rhs1 (stmt);
1470       tree base = get_base_address (op);
1471       tree parm;
1472
1473       gcc_assert (gimple_assign_single_p (stmt));
1474       if (!base)
1475         return p;
1476       parm = unmodified_parm (stmt, base);
1477       if (!parm )
1478         return p;
1479       if (ipa_get_param_decl_index (info, parm) < 0)
1480         return p;
1481     }
1482
1483   /* See if we understand all operands before we start
1484      adding conditionals.  */
1485   FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter, SSA_OP_USE)
1486     {
1487       tree parm = unmodified_parm (stmt, use);
1488       /* For arguments we can build a condition.  */
1489       if (parm && ipa_get_param_decl_index (info, parm) >= 0)
1490         continue;
1491       if (TREE_CODE (use) != SSA_NAME)
1492         return p;
1493       /* If we know when operand is constant,
1494          we still can say something useful.  */
1495       if (!true_predicate_p (VEC_index (predicate_t, nonconstant_names,
1496                                         SSA_NAME_VERSION (use))))
1497         continue;
1498       return p;
1499     }
1500   op_non_const = false_predicate ();
1501   if (is_load)
1502     {
1503       tree parm = unmodified_parm
1504                     (stmt, get_base_address (gimple_assign_rhs1 (stmt)));
1505       p = add_condition (summary,
1506                          ipa_get_param_decl_index (info, parm),
1507                          IS_NOT_CONSTANT, NULL);
1508       op_non_const = or_predicates (summary->conds, &p, &op_non_const);
1509     }
1510   FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter, SSA_OP_USE)
1511     {
1512       tree parm = unmodified_parm (stmt, use);
1513       if (parm && ipa_get_param_decl_index (info, parm) >= 0)
1514         p = add_condition (summary,
1515                            ipa_get_param_decl_index (info, parm),
1516                            IS_NOT_CONSTANT, NULL);
1517       else
1518         p = *VEC_index (predicate_t, nonconstant_names,
1519                         SSA_NAME_VERSION (use));
1520       op_non_const = or_predicates (summary->conds, &p, &op_non_const);
1521     }
1522   if (gimple_code (stmt) == GIMPLE_ASSIGN
1523       && TREE_CODE (gimple_assign_lhs (stmt)) == SSA_NAME)
1524     VEC_replace (predicate_t, nonconstant_names,
1525                  SSA_NAME_VERSION (gimple_assign_lhs (stmt)), &op_non_const);
1526   return op_non_const;
1527 }
1528
1529
1530 /* Compute function body size parameters for NODE.
1531    When EARLY is true, we compute only simple summaries without
1532    non-trivial predicates to drive the early inliner.  */
1533
1534 static void
1535 estimate_function_body_sizes (struct cgraph_node *node, bool early)
1536 {
1537   gcov_type time = 0;
1538   /* Estimate static overhead for function prologue/epilogue and alignment. */
1539   int size = 2;
1540   /* Benefits are scaled by probability of elimination that is in range
1541      <0,2>.  */
1542   basic_block bb;
1543   gimple_stmt_iterator bsi;
1544   struct function *my_function = DECL_STRUCT_FUNCTION (node->decl);
1545   int freq;
1546   struct inline_summary *info = inline_summary (node);
1547   struct predicate bb_predicate;
1548   struct ipa_node_params *parms_info = NULL;
1549   VEC (predicate_t, heap) *nonconstant_names = NULL;
1550
1551   if (ipa_node_params_vector && !early && optimize)
1552     {
1553       parms_info = IPA_NODE_REF (node);
1554       VEC_safe_grow_cleared (predicate_t, heap, nonconstant_names,
1555                              VEC_length (tree, SSANAMES (my_function)));
1556     }
1557
1558   info->conds = 0;
1559   info->entry = 0;
1560
1561
1562   if (dump_file)
1563     fprintf (dump_file, "\nAnalyzing function body size: %s\n",
1564              cgraph_node_name (node));
1565
1566   /* When we run into maximal number of entries, we assign everything to the
1567      constant truth case.  Be sure to have it in list. */
1568   bb_predicate = true_predicate ();
1569   account_size_time (info, 0, 0, &bb_predicate);
1570
1571   bb_predicate = not_inlined_predicate ();
1572   account_size_time (info, 2 * INLINE_SIZE_SCALE, 0, &bb_predicate);
1573
1574   gcc_assert (my_function && my_function->cfg);
1575   if (parms_info)
1576     compute_bb_predicates (node, parms_info, info);
1577   FOR_EACH_BB_FN (bb, my_function)
1578     {
1579       freq = compute_call_stmt_bb_frequency (node->decl, bb);
1580
1581       /* TODO: Obviously predicates can be propagated down across CFG.  */
1582       if (parms_info)
1583         {
1584           if (bb->aux)
1585             bb_predicate = *(struct predicate *)bb->aux;
1586           else
1587             bb_predicate = false_predicate ();
1588         }
1589       else
1590         bb_predicate = true_predicate ();
1591
1592       if (dump_file && (dump_flags & TDF_DETAILS))
1593         {
1594           fprintf (dump_file, "\n BB %i predicate:", bb->index);
1595           dump_predicate (dump_file, info->conds, &bb_predicate);
1596         }
1597       
1598       for (bsi = gsi_start_bb (bb); !gsi_end_p (bsi); gsi_next (&bsi))
1599         {
1600           gimple stmt = gsi_stmt (bsi);
1601           int this_size = estimate_num_insns (stmt, &eni_size_weights);
1602           int this_time = estimate_num_insns (stmt, &eni_time_weights);
1603           int prob;
1604           struct predicate will_be_nonconstant;
1605
1606           if (dump_file && (dump_flags & TDF_DETAILS))
1607             {
1608               fprintf (dump_file, "  ");
1609               print_gimple_stmt (dump_file, stmt, 0, 0);
1610               fprintf (dump_file, "\t\tfreq:%3.2f size:%3i time:%3i\n",
1611                        ((double)freq)/CGRAPH_FREQ_BASE, this_size, this_time);
1612             }
1613
1614           if (is_gimple_call (stmt))
1615             {
1616               struct cgraph_edge *edge = cgraph_edge (node, stmt);
1617               struct inline_edge_summary *es = inline_edge_summary (edge);
1618
1619               /* Special case: results of BUILT_IN_CONSTANT_P will be always
1620                  resolved as constant.  We however don't want to optimize
1621                  out the cgraph edges.  */
1622               if (nonconstant_names
1623                   && gimple_call_builtin_p (stmt, BUILT_IN_CONSTANT_P)
1624                   && gimple_call_lhs (stmt)
1625                   && TREE_CODE (gimple_call_lhs (stmt)) == SSA_NAME)
1626                 {
1627                   struct predicate false_p = false_predicate ();
1628                   VEC_replace (predicate_t, nonconstant_names,
1629                                SSA_NAME_VERSION (gimple_call_lhs (stmt)), &false_p);
1630                 }
1631
1632               es->call_stmt_size = this_size;
1633               es->call_stmt_time = this_time;
1634               es->loop_depth = bb->loop_depth;
1635               edge_set_predicate (edge, &bb_predicate);
1636
1637               /* Do not inline calls where we cannot triviall work around
1638                  mismatches in argument or return types.  */
1639               if (edge->callee
1640                   && cgraph_function_or_thunk_node (edge->callee, NULL)
1641                   && !gimple_check_call_matching_types
1642                        (stmt, cgraph_function_or_thunk_node (edge->callee,
1643                         NULL)->decl))
1644                 {
1645                   edge->call_stmt_cannot_inline_p = true;
1646                   gimple_call_set_cannot_inline (stmt, true);
1647                 }
1648               else
1649                 gcc_assert (!gimple_call_cannot_inline_p (stmt));
1650             }
1651
1652           /* TODO: When conditional jump or swithc is known to be constant, but
1653              we did not translate it into the predicates, we really can account
1654              just maximum of the possible paths.  */
1655           if (parms_info)
1656             will_be_nonconstant
1657                = will_be_nonconstant_predicate (parms_info, info,
1658                                                 stmt, nonconstant_names);
1659           if (this_time || this_size)
1660             {
1661               struct predicate p;
1662
1663               this_time *= freq;
1664               time += this_time;
1665               size += this_size;
1666
1667               prob = eliminated_by_inlining_prob (stmt);
1668               if (prob == 1 && dump_file && (dump_flags & TDF_DETAILS))
1669                 fprintf (dump_file, "\t\t50%% will be eliminated by inlining\n");
1670               if (prob == 2 && dump_file && (dump_flags & TDF_DETAILS))
1671                 fprintf (dump_file, "\t\twill eliminated by inlining\n");
1672
1673               if (parms_info)
1674                 p = and_predicates (info->conds, &bb_predicate,
1675                                     &will_be_nonconstant);
1676               else
1677                 p = true_predicate ();
1678
1679               /* We account everything but the calls.  Calls have their own
1680                  size/time info attached to cgraph edges.  This is neccesary
1681                  in order to make the cost disappear after inlining.  */
1682               if (!is_gimple_call (stmt))
1683                 {
1684                   if (prob)
1685                     {
1686                       struct predicate ip = not_inlined_predicate ();
1687                       ip = and_predicates (info->conds, &ip, &p);
1688                       account_size_time (info, this_size * prob,
1689                                          this_time * prob, &ip);
1690                     }
1691                   if (prob != 2)
1692                     account_size_time (info, this_size * (2 - prob),
1693                                        this_time * (2 - prob), &p);
1694                 }
1695
1696               gcc_assert (time >= 0);
1697               gcc_assert (size >= 0);
1698             }
1699         }
1700     }
1701   FOR_ALL_BB_FN (bb, my_function)
1702     {
1703       edge e;
1704       edge_iterator ei;
1705
1706       if (bb->aux)
1707         pool_free (edge_predicate_pool, bb->aux);
1708       bb->aux = NULL;
1709       FOR_EACH_EDGE (e, ei, bb->succs)
1710         {
1711           if (e->aux)
1712             pool_free (edge_predicate_pool, e->aux);
1713           e->aux = NULL;
1714         }
1715     }
1716   time = (time + CGRAPH_FREQ_BASE / 2) / CGRAPH_FREQ_BASE;
1717   if (time > MAX_TIME)
1718     time = MAX_TIME;
1719   inline_summary (node)->self_time = time;
1720   inline_summary (node)->self_size = size;
1721   VEC_free (predicate_t, heap, nonconstant_names);
1722   if (dump_file)
1723     {
1724       fprintf (dump_file, "\n");
1725       dump_inline_summary (dump_file, node);
1726     }
1727 }
1728
1729
1730 /* Compute parameters of functions used by inliner.
1731    EARLY is true when we compute parameters for the early inliner  */
1732
1733 void
1734 compute_inline_parameters (struct cgraph_node *node, bool early)
1735 {
1736   HOST_WIDE_INT self_stack_size;
1737   struct cgraph_edge *e;
1738   struct inline_summary *info;
1739   tree old_decl = current_function_decl;
1740
1741   gcc_assert (!node->global.inlined_to);
1742
1743   inline_summary_alloc ();
1744
1745   info = inline_summary (node);
1746
1747   /* FIXME: Thunks are inlinable, but tree-inline don't know how to do that.
1748      Once this happen, we will need to more curefully predict call
1749      statement size.  */
1750   if (node->thunk.thunk_p)
1751     {
1752       struct inline_edge_summary *es = inline_edge_summary (node->callees);
1753       struct predicate t = true_predicate ();
1754
1755       info->inlinable = 0;
1756       node->callees->call_stmt_cannot_inline_p = true;
1757       node->local.can_change_signature = false;
1758       es->call_stmt_time = 1;
1759       es->call_stmt_size = 1;
1760       account_size_time (info, 0, 0, &t);
1761       return;
1762     }
1763
1764   /* Even is_gimple_min_invariant rely on current_function_decl.  */
1765   current_function_decl = node->decl;
1766   push_cfun (DECL_STRUCT_FUNCTION (node->decl));
1767
1768   /* Estimate the stack size for the function if we're optimizing.  */
1769   self_stack_size = optimize ? estimated_stack_frame_size (node) : 0;
1770   info->estimated_self_stack_size = self_stack_size;
1771   info->estimated_stack_size = self_stack_size;
1772   info->stack_frame_offset = 0;
1773
1774   /* Can this function be inlined at all?  */
1775   info->inlinable = tree_inlinable_function_p (node->decl);
1776
1777   /* Type attributes can use parameter indices to describe them.  */
1778   if (TYPE_ATTRIBUTES (TREE_TYPE (node->decl)))
1779     node->local.can_change_signature = false;
1780   else
1781     {
1782       /* Otherwise, inlinable functions always can change signature.  */
1783       if (info->inlinable)
1784         node->local.can_change_signature = true;
1785       else
1786         {
1787           /* Functions calling builtin_apply can not change signature.  */
1788           for (e = node->callees; e; e = e->next_callee)
1789             {
1790               tree cdecl = e->callee->decl;
1791               if (DECL_BUILT_IN (cdecl)
1792                   && DECL_BUILT_IN_CLASS (cdecl) == BUILT_IN_NORMAL
1793                   && (DECL_FUNCTION_CODE (cdecl) == BUILT_IN_APPLY_ARGS
1794                       || DECL_FUNCTION_CODE (cdecl) == BUILT_IN_VA_START))
1795                 break;
1796             }
1797           node->local.can_change_signature = !e;
1798         }
1799     }
1800   estimate_function_body_sizes (node, early);
1801
1802   /* Inlining characteristics are maintained by the cgraph_mark_inline.  */
1803   info->time = info->self_time;
1804   info->size = info->self_size;
1805   info->stack_frame_offset = 0;
1806   info->estimated_stack_size = info->estimated_self_stack_size;
1807   current_function_decl = old_decl;
1808   pop_cfun ();
1809 }
1810
1811
1812 /* Compute parameters of functions used by inliner using
1813    current_function_decl.  */
1814
1815 static unsigned int
1816 compute_inline_parameters_for_current (void)
1817 {
1818   compute_inline_parameters (cgraph_get_node (current_function_decl), true);
1819   return 0;
1820 }
1821
1822 struct gimple_opt_pass pass_inline_parameters =
1823 {
1824  {
1825   GIMPLE_PASS,
1826   "inline_param",                       /* name */
1827   NULL,                                 /* gate */
1828   compute_inline_parameters_for_current,/* execute */
1829   NULL,                                 /* sub */
1830   NULL,                                 /* next */
1831   0,                                    /* static_pass_number */
1832   TV_INLINE_HEURISTICS,                 /* tv_id */
1833   0,                                    /* properties_required */
1834   0,                                    /* properties_provided */
1835   0,                                    /* properties_destroyed */
1836   0,                                    /* todo_flags_start */
1837   0                                     /* todo_flags_finish */
1838  }
1839 };
1840
1841
1842 /* Increase SIZE and TIME for size and time needed to handle edge E.  */
1843
1844 static void
1845 estimate_edge_size_and_time (struct cgraph_edge *e, int *size, int *time)
1846 {
1847   struct inline_edge_summary *es = inline_edge_summary (e);
1848   *size += es->call_stmt_size * INLINE_SIZE_SCALE;
1849   *time += (es->call_stmt_time
1850             * e->frequency * (INLINE_TIME_SCALE / CGRAPH_FREQ_BASE));
1851   if (*time > MAX_TIME * INLINE_TIME_SCALE)
1852     *time = MAX_TIME * INLINE_TIME_SCALE;
1853 }
1854
1855
1856 /* Increase SIZE and TIME for size and time needed to handle all calls in NODE.  */
1857
1858 static void
1859 estimate_calls_size_and_time (struct cgraph_node *node, int *size, int *time,
1860                               clause_t possible_truths)
1861 {
1862   struct cgraph_edge *e;
1863   for (e = node->callees; e; e = e->next_callee)
1864     {
1865       struct inline_edge_summary *es = inline_edge_summary (e);
1866       if (!es->predicate || evaluate_predicate (es->predicate, possible_truths))
1867         {
1868           if (e->inline_failed)
1869             estimate_edge_size_and_time (e, size, time);
1870           else
1871             estimate_calls_size_and_time (e->callee, size, time,
1872                                           possible_truths);
1873         }
1874     }
1875   /* TODO: look for devirtualizing oppurtunities.  */
1876   for (e = node->indirect_calls; e; e = e->next_callee)
1877     {
1878       struct inline_edge_summary *es = inline_edge_summary (e);
1879       if (!es->predicate || evaluate_predicate (es->predicate, possible_truths))
1880         estimate_edge_size_and_time (e, size, time);
1881     }
1882 }
1883
1884
1885 /* Estimate size and time needed to execute NODE assuming
1886    POSSIBLE_TRUTHS clause. */
1887
1888 static void
1889 estimate_node_size_and_time (struct cgraph_node *node,
1890                              clause_t possible_truths,
1891                              int *ret_size, int *ret_time)
1892 {
1893   struct inline_summary *info = inline_summary (node);
1894   size_time_entry *e;
1895   int size = 0, time = 0;
1896   int i;
1897
1898   if (dump_file
1899       && (dump_flags & TDF_DETAILS))
1900     {
1901       bool found = false;
1902       fprintf (dump_file, "   Estimating body: %s/%i\n"
1903                           "   Known to be false: ",
1904                cgraph_node_name (node),
1905                node->uid);
1906
1907       for (i = predicate_not_inlined_condition;
1908            i < (predicate_first_dynamic_condition
1909                 + (int)VEC_length (condition, info->conds)); i++)
1910         if (!(possible_truths & (1 << i)))
1911           {
1912             if (found)
1913               fprintf (dump_file, ", ");
1914             found = true;
1915             dump_condition (dump_file, info->conds, i);
1916           }
1917     }
1918
1919   for (i = 0; VEC_iterate (size_time_entry, info->entry, i, e); i++)
1920     if (evaluate_predicate (&e->predicate, possible_truths))
1921       time += e->time, size += e->size;
1922
1923   if (time > MAX_TIME * INLINE_TIME_SCALE)
1924     time = MAX_TIME * INLINE_TIME_SCALE;
1925
1926   estimate_calls_size_and_time (node, &size, &time, possible_truths);
1927   time = (time + INLINE_TIME_SCALE / 2) / INLINE_TIME_SCALE;
1928   size = (size + INLINE_SIZE_SCALE / 2) / INLINE_SIZE_SCALE;
1929
1930
1931   if (dump_file
1932       && (dump_flags & TDF_DETAILS))
1933     fprintf (dump_file, "\n   size:%i time:%i\n", size, time);
1934   if (ret_time)
1935     *ret_time = time;
1936   if (ret_size)
1937     *ret_size = size;
1938   return;
1939 }
1940
1941
1942 /* Estimate size and time needed to execute callee of EDGE assuming that
1943    parameters known to be constant at caller of EDGE are propagated.
1944    KNOWN_VALs is a vector of assumed known constant values for parameters.  */
1945
1946 void
1947 estimate_ipcp_clone_size_and_time (struct cgraph_node *node,
1948                                    VEC (tree, heap) *known_vals,
1949                                    int *ret_size, int *ret_time)
1950 {
1951   clause_t clause;
1952
1953   clause = evaluate_conditions_for_known_args (node, false, known_vals);
1954   estimate_node_size_and_time (node, clause, ret_size, ret_time);
1955 }
1956
1957
1958 /* Translate all conditions from callee representation into caller representation and
1959    symbolically evaluate predicate P into new predicate.
1960
1961    INFO is inline_summary of function we are adding predicate into, CALLEE_INFO is summary
1962    of function predicate P is from. OPERAND_MAP is array giving callee formal IDs the
1963    caller formal IDs. POSSSIBLE_TRUTHS is clausule of all callee conditions that
1964    may be true in caller context. TOPLEV_PREDICATE is predicate under which callee
1965    is executed.  */
1966
1967 static struct predicate
1968 remap_predicate (struct inline_summary *info, struct inline_summary *callee_info,
1969                  struct predicate *p,
1970                  VEC (int, heap) *operand_map,
1971                  clause_t possible_truths,
1972                  struct predicate *toplev_predicate)
1973 {
1974   int i;
1975   struct predicate out = true_predicate ();
1976
1977   /* True predicate is easy.  */
1978   if (true_predicate_p (p))
1979     return *toplev_predicate;
1980   for (i = 0; p->clause[i]; i++)
1981     {
1982       clause_t clause = p->clause[i];
1983       int cond;
1984       struct predicate clause_predicate = false_predicate ();
1985
1986       gcc_assert (i < MAX_CLAUSES);
1987
1988       for (cond = 0; cond < NUM_CONDITIONS; cond ++)
1989         /* Do we have condition we can't disprove?   */
1990         if (clause & possible_truths & (1 << cond))
1991           {
1992             struct predicate cond_predicate;
1993             /* Work out if the condition can translate to predicate in the
1994                inlined function.  */
1995             if (cond >= predicate_first_dynamic_condition)
1996               {
1997                  struct condition *c;
1998
1999                  c = VEC_index (condition, callee_info->conds,
2000                                 cond - predicate_first_dynamic_condition);
2001                  /* See if we can remap condition operand to caller's operand.
2002                     Otherwise give up.  */
2003                  if (!operand_map
2004                      || (int)VEC_length (int, operand_map) <= c->operand_num
2005                      || VEC_index (int, operand_map, c->operand_num) == -1)
2006                    cond_predicate = true_predicate ();
2007                  else
2008                    cond_predicate = add_condition (info,
2009                                                    VEC_index (int, operand_map,
2010                                                               c->operand_num),
2011                                                    c->code, c->val);
2012               }
2013             /* Fixed conditions remains same, construct single
2014                condition predicate.  */
2015             else
2016               {
2017                 cond_predicate.clause[0] = 1 << cond;
2018                 cond_predicate.clause[1] = 0;
2019               }
2020             clause_predicate = or_predicates (info->conds, &clause_predicate,
2021                                               &cond_predicate);
2022           }
2023       out = and_predicates (info->conds, &out, &clause_predicate);
2024     }
2025   return and_predicates (info->conds, &out, toplev_predicate);
2026 }
2027
2028
2029 /* Update summary information of inline clones after inlining.
2030    Compute peak stack usage.  */
2031
2032 static void
2033 inline_update_callee_summaries (struct cgraph_node *node,
2034                                 int depth)
2035 {
2036   struct cgraph_edge *e;
2037   struct inline_summary *callee_info = inline_summary (node);
2038   struct inline_summary *caller_info = inline_summary (node->callers->caller);
2039   HOST_WIDE_INT peak;
2040
2041   callee_info->stack_frame_offset
2042     = caller_info->stack_frame_offset
2043       + caller_info->estimated_self_stack_size;
2044   peak = callee_info->stack_frame_offset
2045       + callee_info->estimated_self_stack_size;
2046   if (inline_summary (node->global.inlined_to)->estimated_stack_size
2047       < peak)
2048     inline_summary (node->global.inlined_to)->estimated_stack_size = peak;
2049   cgraph_propagate_frequency (node);
2050   for (e = node->callees; e; e = e->next_callee)
2051     {
2052       if (!e->inline_failed)
2053         inline_update_callee_summaries (e->callee, depth);
2054       inline_edge_summary (e)->loop_depth += depth;
2055     }
2056   for (e = node->indirect_calls; e; e = e->next_callee)
2057     inline_edge_summary (e)->loop_depth += depth;
2058 }
2059
2060
2061 /* Remap predicates of callees of NODE.  Rest of arguments match
2062    remap_predicate.  */
2063
2064 static void
2065 remap_edge_predicates (struct cgraph_node *node,
2066                        struct inline_summary *info,
2067                        struct inline_summary *callee_info,
2068                        VEC (int, heap) *operand_map,
2069                        clause_t possible_truths,
2070                        struct predicate *toplev_predicate)
2071 {
2072   struct cgraph_edge *e;
2073   for (e = node->callees; e; e = e->next_callee)
2074     {
2075       struct inline_edge_summary *es = inline_edge_summary (e);
2076       struct predicate p;
2077       if (e->inline_failed)
2078         {
2079           if (es->predicate)
2080             {
2081               p = remap_predicate (info, callee_info,
2082                                    es->predicate, operand_map, possible_truths,
2083                                    toplev_predicate);
2084               edge_set_predicate (e, &p);
2085               /* TODO: We should remove the edge for code that will be optimized out,
2086                  but we need to keep verifiers and tree-inline happy.
2087                  Make it cold for now.  */
2088               if (false_predicate_p (&p))
2089                 {
2090                   e->count = 0;
2091                   e->frequency = 0;
2092                 }
2093             }
2094           else
2095             edge_set_predicate (e, toplev_predicate);
2096         }
2097       else
2098         remap_edge_predicates (e->callee, info, callee_info, operand_map,
2099                                possible_truths, toplev_predicate);
2100     }
2101   for (e = node->indirect_calls; e; e = e->next_callee)
2102     {
2103       struct inline_edge_summary *es = inline_edge_summary (e);
2104       struct predicate p;
2105       if (es->predicate)
2106         {
2107           p = remap_predicate (info, callee_info,
2108                                es->predicate, operand_map, possible_truths,
2109                                toplev_predicate);
2110           edge_set_predicate (e, &p);
2111           /* TODO: We should remove the edge for code that will be optimized out,
2112              but we need to keep verifiers and tree-inline happy.
2113              Make it cold for now.  */
2114           if (false_predicate_p (&p))
2115             {
2116               e->count = 0;
2117               e->frequency = 0;
2118             }
2119         }
2120       else
2121         edge_set_predicate (e, toplev_predicate);
2122     }
2123 }
2124
2125
2126 /* We inlined EDGE.  Update summary of the function we inlined into.  */
2127
2128 void
2129 inline_merge_summary (struct cgraph_edge *edge)
2130 {
2131   struct inline_summary *callee_info = inline_summary (edge->callee);
2132   struct cgraph_node *to = (edge->caller->global.inlined_to
2133                             ? edge->caller->global.inlined_to : edge->caller);
2134   struct inline_summary *info = inline_summary (to);
2135   clause_t clause = 0;          /* not_inline is known to be false.  */
2136   size_time_entry *e;
2137   VEC (int, heap) *operand_map = NULL;
2138   int i;
2139   struct predicate toplev_predicate;
2140   struct predicate true_p = true_predicate ();
2141   struct inline_edge_summary *es = inline_edge_summary (edge);
2142
2143   if (es->predicate)
2144     toplev_predicate = *es->predicate;
2145   else
2146     toplev_predicate = true_predicate ();
2147
2148   if (ipa_node_params_vector && callee_info->conds)
2149     {
2150       struct ipa_edge_args *args = IPA_EDGE_REF (edge);
2151       int count = ipa_get_cs_argument_count (args);
2152       int i;
2153
2154       clause = evaluate_conditions_for_edge (edge, true);
2155       if (count)
2156         VEC_safe_grow_cleared (int, heap, operand_map, count);
2157       for (i = 0; i < count; i++)
2158         {
2159           struct ipa_jump_func *jfunc = ipa_get_ith_jump_func (args, i);
2160           int map = -1;
2161           /* TODO: handle non-NOPs when merging.  */
2162           if (jfunc->type == IPA_JF_PASS_THROUGH
2163               && jfunc->value.pass_through.operation == NOP_EXPR)
2164             map = jfunc->value.pass_through.formal_id;
2165           VEC_replace (int, operand_map, i, map);
2166           gcc_assert (map < ipa_get_param_count (IPA_NODE_REF (to)));
2167         }
2168     }
2169   for (i = 0; VEC_iterate (size_time_entry, callee_info->entry, i, e); i++)
2170     {
2171       struct predicate p = remap_predicate (info, callee_info,
2172                                             &e->predicate, operand_map, clause,
2173                                             &toplev_predicate);
2174       gcov_type add_time = ((gcov_type)e->time * edge->frequency
2175                             + CGRAPH_FREQ_BASE / 2) / CGRAPH_FREQ_BASE;
2176       if (add_time > MAX_TIME)
2177         add_time = MAX_TIME;
2178       account_size_time (info, e->size, add_time, &p);
2179     }
2180   remap_edge_predicates (edge->callee, info, callee_info, operand_map,
2181                          clause, &toplev_predicate);
2182   info->size = 0;
2183   info->time = 0;
2184   for (i = 0; VEC_iterate (size_time_entry, info->entry, i, e); i++)
2185     info->size += e->size, info->time += e->time;
2186   estimate_calls_size_and_time (to, &info->size, &info->time,
2187                                 ~(clause_t)(1 << predicate_false_condition));
2188
2189   inline_update_callee_summaries (edge->callee,
2190                                   inline_edge_summary (edge)->loop_depth);
2191
2192   /* We do not maintain predicates of inlined edges, free it.  */
2193   edge_set_predicate (edge, &true_p);
2194
2195   info->time = (info->time + INLINE_TIME_SCALE / 2) / INLINE_TIME_SCALE;
2196   info->size = (info->size + INLINE_SIZE_SCALE / 2) / INLINE_SIZE_SCALE;
2197 }
2198
2199
2200 /* Estimate the time cost for the caller when inlining EDGE.
2201    Only to be called via estimate_edge_time, that handles the
2202    caching mechanism.
2203
2204    When caching, also update the cache entry.  Compute both time and
2205    size, since we always need both metrics eventually.  */
2206
2207 int
2208 do_estimate_edge_time (struct cgraph_edge *edge)
2209 {
2210   int time;
2211   int size;
2212   gcov_type ret;
2213   struct inline_edge_summary *es = inline_edge_summary (edge);
2214
2215   gcc_checking_assert (edge->inline_failed);
2216   estimate_node_size_and_time (cgraph_function_or_thunk_node (edge->callee, NULL),
2217                                evaluate_conditions_for_edge (edge, true),
2218                                &size, &time);
2219
2220   ret = (((gcov_type)time
2221            - es->call_stmt_time) * edge->frequency
2222          + CGRAPH_FREQ_BASE / 2) / CGRAPH_FREQ_BASE;
2223
2224   /* When caching, update the cache entry.  */
2225   if (edge_growth_cache)
2226     {
2227       int ret_size;
2228       if ((int)VEC_length (edge_growth_cache_entry, edge_growth_cache)
2229           <= edge->uid)
2230         VEC_safe_grow_cleared (edge_growth_cache_entry, heap, edge_growth_cache,
2231                                cgraph_edge_max_uid);
2232       VEC_index (edge_growth_cache_entry, edge_growth_cache, edge->uid)->time
2233         = ret + (ret >= 0);
2234
2235       ret_size = size - es->call_stmt_size;
2236       gcc_checking_assert (es->call_stmt_size);
2237       VEC_index (edge_growth_cache_entry, edge_growth_cache, edge->uid)->size
2238         = ret_size + (ret_size >= 0);
2239     }
2240   return ret;
2241 }
2242
2243
2244 /* Estimate the growth of the caller when inlining EDGE.
2245    Only to be called via estimate_edge_size.  */
2246
2247 int
2248 do_estimate_edge_growth (struct cgraph_edge *edge)
2249 {
2250   int size;
2251   struct cgraph_node *callee;
2252
2253   /* When we do caching, use do_estimate_edge_time to populate the entry.  */
2254
2255   if (edge_growth_cache)
2256     {
2257       do_estimate_edge_time (edge);
2258       size = VEC_index (edge_growth_cache_entry,
2259                         edge_growth_cache,
2260                         edge->uid)->size;
2261       gcc_checking_assert (size);
2262       return size - (size > 0);
2263     }
2264   callee = cgraph_function_or_thunk_node (edge->callee, NULL);
2265
2266   /* Early inliner runs without caching, go ahead and do the dirty work.  */
2267   gcc_checking_assert (edge->inline_failed);
2268   estimate_node_size_and_time (callee,
2269                                evaluate_conditions_for_edge (edge, true),
2270                                &size, NULL);
2271   gcc_checking_assert (inline_edge_summary (edge)->call_stmt_size);
2272   return size - inline_edge_summary (edge)->call_stmt_size;
2273 }
2274
2275
2276 /* Estimate self time of the function NODE after inlining EDGE.  */
2277
2278 int
2279 estimate_time_after_inlining (struct cgraph_node *node,
2280                               struct cgraph_edge *edge)
2281 {
2282   struct inline_edge_summary *es = inline_edge_summary (edge);
2283   if (!es->predicate || !false_predicate_p (es->predicate))
2284     {
2285       gcov_type time = inline_summary (node)->time + estimate_edge_time (edge);
2286       if (time < 0)
2287         time = 0;
2288       if (time > MAX_TIME)
2289         time = MAX_TIME;
2290       return time;
2291     }
2292   return inline_summary (node)->time;
2293 }
2294
2295
2296 /* Estimate the size of NODE after inlining EDGE which should be an
2297    edge to either NODE or a call inlined into NODE.  */
2298
2299 int
2300 estimate_size_after_inlining (struct cgraph_node *node,
2301                               struct cgraph_edge *edge)
2302 {
2303   struct inline_edge_summary *es = inline_edge_summary (edge);
2304   if (!es->predicate || !false_predicate_p (es->predicate))
2305     {
2306       int size = inline_summary (node)->size + estimate_edge_growth (edge);
2307       gcc_assert (size >= 0);
2308       return size;
2309     }
2310   return inline_summary (node)->size;
2311 }
2312
2313
2314 struct growth_data
2315 {
2316   bool self_recursive;
2317   int growth;
2318 };
2319
2320
2321 /* Worker for do_estimate_growth.  Collect growth for all callers.  */
2322
2323 static bool
2324 do_estimate_growth_1 (struct cgraph_node *node, void *data)
2325 {
2326   struct cgraph_edge *e;
2327   struct growth_data *d = (struct growth_data *) data;
2328
2329   for (e = node->callers; e; e = e->next_caller)
2330     {
2331       gcc_checking_assert (e->inline_failed);
2332
2333       if (e->caller == node
2334           || (e->caller->global.inlined_to
2335               && e->caller->global.inlined_to == node))
2336         d->self_recursive = true;
2337       d->growth += estimate_edge_growth (e);
2338     }
2339   return false;
2340 }
2341
2342
2343 /* Estimate the growth caused by inlining NODE into all callees.  */
2344
2345 int
2346 do_estimate_growth (struct cgraph_node *node)
2347 {
2348   struct growth_data d = {0, false};
2349   struct inline_summary *info = inline_summary (node);
2350
2351   cgraph_for_node_and_aliases (node, do_estimate_growth_1, &d, true);
2352
2353   /* For self recursive functions the growth estimation really should be
2354      infinity.  We don't want to return very large values because the growth
2355      plays various roles in badness computation fractions.  Be sure to not
2356      return zero or negative growths. */
2357   if (d.self_recursive)
2358     d.growth = d.growth < info->size ? info->size : d.growth;
2359   else
2360     {
2361       if (!DECL_EXTERNAL (node->decl)
2362           && cgraph_will_be_removed_from_program_if_no_direct_calls (node))
2363         d.growth -= info->size;
2364       /* COMDAT functions are very often not shared across multiple units
2365          since they come from various template instantiations.
2366          Take this into account.  */
2367       else  if (DECL_COMDAT (node->decl)
2368                 && cgraph_can_remove_if_no_direct_calls_p (node))
2369         d.growth -= (info->size
2370                      * (100 - PARAM_VALUE (PARAM_COMDAT_SHARING_PROBABILITY))
2371                      + 50) / 100;
2372     }
2373
2374   if (node_growth_cache)
2375     {
2376       if ((int)VEC_length (int, node_growth_cache) <= node->uid)
2377         VEC_safe_grow_cleared (int, heap, node_growth_cache, cgraph_max_uid);
2378       VEC_replace (int, node_growth_cache, node->uid,
2379                    d.growth + (d.growth >= 0));
2380     }
2381   return d.growth;
2382 }
2383
2384
2385 /* This function performs intraprocedural analysis in NODE that is required to
2386    inline indirect calls.  */
2387
2388 static void
2389 inline_indirect_intraprocedural_analysis (struct cgraph_node *node)
2390 {
2391   ipa_analyze_node (node);
2392   if (dump_file && (dump_flags & TDF_DETAILS))
2393     {
2394       ipa_print_node_params (dump_file, node);
2395       ipa_print_node_jump_functions (dump_file, node);
2396     }
2397 }
2398
2399
2400 /* Note function body size.  */
2401
2402 static void
2403 inline_analyze_function (struct cgraph_node *node)
2404 {
2405   push_cfun (DECL_STRUCT_FUNCTION (node->decl));
2406   current_function_decl = node->decl;
2407
2408   if (dump_file)
2409     fprintf (dump_file, "\nAnalyzing function: %s/%u\n",
2410              cgraph_node_name (node), node->uid);
2411   if (optimize && !node->thunk.thunk_p)
2412     inline_indirect_intraprocedural_analysis (node);
2413   compute_inline_parameters (node, false);
2414
2415   current_function_decl = NULL;
2416   pop_cfun ();
2417 }
2418
2419
2420 /* Called when new function is inserted to callgraph late.  */
2421
2422 static void
2423 add_new_function (struct cgraph_node *node, void *data ATTRIBUTE_UNUSED)
2424 {
2425   inline_analyze_function (node);
2426 }
2427
2428
2429 /* Note function body size.  */
2430
2431 void
2432 inline_generate_summary (void)
2433 {
2434   struct cgraph_node *node;
2435
2436   function_insertion_hook_holder =
2437       cgraph_add_function_insertion_hook (&add_new_function, NULL);
2438
2439   ipa_register_cgraph_hooks ();
2440
2441   FOR_EACH_DEFINED_FUNCTION (node)
2442     if (!node->alias)
2443       inline_analyze_function (node);
2444 }
2445
2446
2447 /* Read predicate from IB.  */
2448
2449 static struct predicate
2450 read_predicate (struct lto_input_block *ib)
2451 {
2452   struct predicate out;
2453   clause_t clause;
2454   int k = 0;
2455
2456   do 
2457     {
2458       gcc_assert (k <= MAX_CLAUSES);
2459       clause = out.clause[k++] = streamer_read_uhwi (ib);
2460     }
2461   while (clause);
2462
2463   /* Zero-initialize the remaining clauses in OUT.  */
2464   while (k <= MAX_CLAUSES)
2465     out.clause[k++] = 0;
2466
2467   return out;
2468 }
2469
2470
2471 /* Write inline summary for edge E to OB.  */
2472
2473 static void
2474 read_inline_edge_summary (struct lto_input_block *ib, struct cgraph_edge *e)
2475 {
2476   struct inline_edge_summary *es = inline_edge_summary (e);
2477   struct predicate p;
2478
2479   es->call_stmt_size = streamer_read_uhwi (ib);
2480   es->call_stmt_time = streamer_read_uhwi (ib);
2481   es->loop_depth = streamer_read_uhwi (ib);
2482   p = read_predicate (ib);
2483   edge_set_predicate (e, &p);
2484 }
2485
2486
2487 /* Stream in inline summaries from the section.  */
2488
2489 static void
2490 inline_read_section (struct lto_file_decl_data *file_data, const char *data,
2491                      size_t len)
2492 {
2493   const struct lto_function_header *header =
2494     (const struct lto_function_header *) data;
2495   const int32_t cfg_offset = sizeof (struct lto_function_header);
2496   const int32_t main_offset = cfg_offset + header->cfg_size;
2497   const int32_t string_offset = main_offset + header->main_size;
2498   struct data_in *data_in;
2499   struct lto_input_block ib;
2500   unsigned int i, count2, j;
2501   unsigned int f_count;
2502
2503   LTO_INIT_INPUT_BLOCK (ib, (const char *) data + main_offset, 0,
2504                         header->main_size);
2505
2506   data_in =
2507     lto_data_in_create (file_data, (const char *) data + string_offset,
2508                         header->string_size, NULL);
2509   f_count = streamer_read_uhwi (&ib);
2510   for (i = 0; i < f_count; i++)
2511     {
2512       unsigned int index;
2513       struct cgraph_node *node;
2514       struct inline_summary *info;
2515       lto_cgraph_encoder_t encoder;
2516       struct bitpack_d bp;
2517       struct cgraph_edge *e;
2518
2519       index = streamer_read_uhwi (&ib);
2520       encoder = file_data->cgraph_node_encoder;
2521       node = lto_cgraph_encoder_deref (encoder, index);
2522       info = inline_summary (node);
2523
2524       info->estimated_stack_size
2525         = info->estimated_self_stack_size = streamer_read_uhwi (&ib);
2526       info->size = info->self_size = streamer_read_uhwi (&ib);
2527       info->time = info->self_time = streamer_read_uhwi (&ib);
2528
2529       bp = streamer_read_bitpack (&ib);
2530       info->inlinable = bp_unpack_value (&bp, 1);
2531
2532       count2 = streamer_read_uhwi (&ib);
2533       gcc_assert (!info->conds);
2534       for (j = 0; j < count2; j++)
2535         {
2536           struct condition c;
2537           c.operand_num = streamer_read_uhwi (&ib);
2538           c.code = (enum tree_code) streamer_read_uhwi (&ib);
2539           c.val = stream_read_tree (&ib, data_in);
2540           VEC_safe_push (condition, gc, info->conds, &c);
2541         }
2542       count2 = streamer_read_uhwi (&ib);
2543       gcc_assert (!info->entry);
2544       for (j = 0; j < count2; j++)
2545         {
2546           struct size_time_entry e;
2547
2548           e.size = streamer_read_uhwi (&ib);
2549           e.time = streamer_read_uhwi (&ib);
2550           e.predicate = read_predicate (&ib);
2551
2552           VEC_safe_push (size_time_entry, gc, info->entry, &e);
2553         }
2554       for (e = node->callees; e; e = e->next_callee)
2555         read_inline_edge_summary (&ib, e);
2556       for (e = node->indirect_calls; e; e = e->next_callee)
2557         read_inline_edge_summary (&ib, e);
2558     }
2559
2560   lto_free_section_data (file_data, LTO_section_inline_summary, NULL, data,
2561                          len);
2562   lto_data_in_delete (data_in);
2563 }
2564
2565
2566 /* Read inline summary.  Jump functions are shared among ipa-cp
2567    and inliner, so when ipa-cp is active, we don't need to write them
2568    twice.  */
2569
2570 void
2571 inline_read_summary (void)
2572 {
2573   struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data ();
2574   struct lto_file_decl_data *file_data;
2575   unsigned int j = 0;
2576
2577   inline_summary_alloc ();
2578
2579   while ((file_data = file_data_vec[j++]))
2580     {
2581       size_t len;
2582       const char *data = lto_get_section_data (file_data, LTO_section_inline_summary, NULL, &len);
2583       if (data)
2584         inline_read_section (file_data, data, len);
2585       else
2586         /* Fatal error here.  We do not want to support compiling ltrans units with
2587            different version of compiler or different flags than the WPA unit, so
2588            this should never happen.  */
2589         fatal_error ("ipa inline summary is missing in input file");
2590     }
2591   if (optimize)
2592     {
2593       ipa_register_cgraph_hooks ();
2594       if (!flag_ipa_cp)
2595         ipa_prop_read_jump_functions ();
2596     }
2597   function_insertion_hook_holder =
2598       cgraph_add_function_insertion_hook (&add_new_function, NULL);
2599 }
2600
2601
2602 /* Write predicate P to OB.  */
2603
2604 static void
2605 write_predicate (struct output_block *ob, struct predicate *p)
2606 {
2607   int j;
2608   if (p)
2609     for (j = 0; p->clause[j]; j++)
2610       {
2611          gcc_assert (j < MAX_CLAUSES);
2612          streamer_write_uhwi (ob, p->clause[j]);
2613       }
2614   streamer_write_uhwi (ob, 0);
2615 }
2616
2617
2618 /* Write inline summary for edge E to OB.  */
2619
2620 static void
2621 write_inline_edge_summary (struct output_block *ob, struct cgraph_edge *e)
2622 {
2623   struct inline_edge_summary *es = inline_edge_summary (e);
2624   streamer_write_uhwi (ob, es->call_stmt_size);
2625   streamer_write_uhwi (ob, es->call_stmt_time);
2626   streamer_write_uhwi (ob, es->loop_depth);
2627   write_predicate (ob, es->predicate);
2628 }
2629
2630
2631 /* Write inline summary for node in SET.
2632    Jump functions are shared among ipa-cp and inliner, so when ipa-cp is
2633    active, we don't need to write them twice.  */
2634
2635 void
2636 inline_write_summary (cgraph_node_set set,
2637                       varpool_node_set vset ATTRIBUTE_UNUSED)
2638 {
2639   struct cgraph_node *node;
2640   struct output_block *ob = create_output_block (LTO_section_inline_summary);
2641   lto_cgraph_encoder_t encoder = ob->decl_state->cgraph_node_encoder;
2642   unsigned int count = 0;
2643   int i;
2644
2645   for (i = 0; i < lto_cgraph_encoder_size (encoder); i++)
2646     if (lto_cgraph_encoder_deref (encoder, i)->analyzed)
2647       count++;
2648   streamer_write_uhwi (ob, count);
2649
2650   for (i = 0; i < lto_cgraph_encoder_size (encoder); i++)
2651     {
2652       node = lto_cgraph_encoder_deref (encoder, i);
2653       if (node->analyzed)
2654         {
2655           struct inline_summary *info = inline_summary (node);
2656           struct bitpack_d bp;
2657           struct cgraph_edge *edge;
2658           int i;
2659           size_time_entry *e;
2660           struct condition *c;
2661
2662           streamer_write_uhwi (ob, lto_cgraph_encoder_encode (encoder, node));
2663           streamer_write_hwi (ob, info->estimated_self_stack_size);
2664           streamer_write_hwi (ob, info->self_size);
2665           streamer_write_hwi (ob, info->self_time);
2666           bp = bitpack_create (ob->main_stream);
2667           bp_pack_value (&bp, info->inlinable, 1);
2668           streamer_write_bitpack (&bp);
2669           streamer_write_uhwi (ob, VEC_length (condition, info->conds));
2670           for (i = 0; VEC_iterate (condition, info->conds, i, c); i++)
2671             {
2672               streamer_write_uhwi (ob, c->operand_num);
2673               streamer_write_uhwi (ob, c->code);
2674               stream_write_tree (ob, c->val, true);
2675             }
2676           streamer_write_uhwi (ob, VEC_length (size_time_entry, info->entry));
2677           for (i = 0;
2678                VEC_iterate (size_time_entry, info->entry, i, e);
2679                i++)
2680             {
2681               streamer_write_uhwi (ob, e->size);
2682               streamer_write_uhwi (ob, e->time);
2683               write_predicate (ob, &e->predicate);
2684             }
2685           for (edge = node->callees; edge; edge = edge->next_callee)
2686             write_inline_edge_summary (ob, edge);
2687           for (edge = node->indirect_calls; edge; edge = edge->next_callee)
2688             write_inline_edge_summary (ob, edge);
2689         }
2690     }
2691   streamer_write_char_stream (ob->main_stream, 0);
2692   produce_asm (ob, NULL);
2693   destroy_output_block (ob);
2694
2695   if (optimize && !flag_ipa_cp)
2696     ipa_prop_write_jump_functions (set);
2697 }
2698
2699
2700 /* Release inline summary.  */
2701
2702 void
2703 inline_free_summary (void)
2704 {
2705   if (function_insertion_hook_holder)
2706     cgraph_remove_function_insertion_hook (function_insertion_hook_holder);
2707   function_insertion_hook_holder = NULL;
2708   if (node_removal_hook_holder)
2709     cgraph_remove_node_removal_hook (node_removal_hook_holder);
2710   if (edge_removal_hook_holder)
2711     cgraph_remove_edge_removal_hook (edge_removal_hook_holder);
2712   node_removal_hook_holder = NULL;
2713   if (node_duplication_hook_holder)
2714     cgraph_remove_node_duplication_hook (node_duplication_hook_holder);
2715   if (edge_duplication_hook_holder)
2716     cgraph_remove_edge_duplication_hook (edge_duplication_hook_holder);
2717   node_duplication_hook_holder = NULL;
2718   VEC_free (inline_summary_t, gc, inline_summary_vec);
2719   inline_summary_vec = NULL;
2720   VEC_free (inline_edge_summary_t, heap, inline_edge_summary_vec);
2721   inline_edge_summary_vec = NULL;
2722   if (edge_predicate_pool)
2723     free_alloc_pool (edge_predicate_pool);
2724   edge_predicate_pool = 0;
2725 }