* gcc.dg/vect/vect-outer-simd-1.c: Remove cleanup-tree-dump directive.
[official-gcc.git] / gcc / ipa-profile.c
blob7c967f9435ea2be7a41fd1d80be25fa527ff24f0
1 /* Basic IPA optimizations based on profile.
2 Copyright (C) 2003-2015 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 /* ipa-profile pass implements the following analysis propagating profille
21 inter-procedurally.
23 - Count histogram construction. This is a histogram analyzing how much
24 time is spent executing statements with a given execution count read
25 from profile feedback. This histogram is complete only with LTO,
26 otherwise it contains information only about the current unit.
28 Similar histogram is also estimated by coverage runtime. This histogram
29 is not dependent on LTO, but it suffers from various defects; first
30 gcov runtime is not weighting individual basic block by estimated execution
31 time and second the merging of multiple runs makes assumption that the
32 histogram distribution did not change. Consequentely histogram constructed
33 here may be more precise.
35 The information is used to set hot/cold thresholds.
36 - Next speculative indirect call resolution is performed: the local
37 profile pass assigns profile-id to each function and provide us with a
38 histogram specifying the most common target. We look up the callgraph
39 node corresponding to the target and produce a speculative call.
41 This call may or may not survive through IPA optimization based on decision
42 of inliner.
43 - Finally we propagate the following flags: unlikely executed, executed
44 once, executed at startup and executed at exit. These flags are used to
45 control code size/performance threshold and and code placement (by producing
46 .text.unlikely/.text.hot/.text.startup/.text.exit subsections). */
47 #include "config.h"
48 #include "system.h"
49 #include "coretypes.h"
50 #include "tm.h"
51 #include "hash-set.h"
52 #include "machmode.h"
53 #include "vec.h"
54 #include "double-int.h"
55 #include "input.h"
56 #include "alias.h"
57 #include "symtab.h"
58 #include "wide-int.h"
59 #include "inchash.h"
60 #include "tree.h"
61 #include "fold-const.h"
62 #include "predict.h"
63 #include "dominance.h"
64 #include "cfg.h"
65 #include "basic-block.h"
66 #include "hash-map.h"
67 #include "is-a.h"
68 #include "plugin-api.h"
69 #include "hard-reg-set.h"
70 #include "input.h"
71 #include "function.h"
72 #include "ipa-ref.h"
73 #include "cgraph.h"
74 #include "tree-pass.h"
75 #include "tree-ssa-alias.h"
76 #include "internal-fn.h"
77 #include "gimple-expr.h"
78 #include "gimple.h"
79 #include "gimple-iterator.h"
80 #include "flags.h"
81 #include "target.h"
82 #include "tree-iterator.h"
83 #include "ipa-utils.h"
84 #include "profile.h"
85 #include "params.h"
86 #include "value-prof.h"
87 #include "alloc-pool.h"
88 #include "tree-inline.h"
89 #include "lto-streamer.h"
90 #include "data-streamer.h"
91 #include "symbol-summary.h"
92 #include "ipa-prop.h"
93 #include "ipa-inline.h"
95 /* Entry in the histogram. */
97 struct histogram_entry
99 gcov_type count;
100 int time;
101 int size;
104 /* Histogram of profile values.
105 The histogram is represented as an ordered vector of entries allocated via
106 histogram_pool. During construction a separate hashtable is kept to lookup
107 duplicate entries. */
109 vec<histogram_entry *> histogram;
110 static pool_allocator<histogram_entry> histogram_pool
111 ("IPA histogram", 10);
113 /* Hashtable support for storing SSA names hashed by their SSA_NAME_VAR. */
115 struct histogram_hash : typed_noop_remove <histogram_entry>
117 typedef histogram_entry *value_type;
118 typedef histogram_entry *compare_type;
119 static inline hashval_t hash (const histogram_entry *);
120 static inline int equal (const histogram_entry *, const histogram_entry *);
123 inline hashval_t
124 histogram_hash::hash (const histogram_entry *val)
126 return val->count;
129 inline int
130 histogram_hash::equal (const histogram_entry *val, const histogram_entry *val2)
132 return val->count == val2->count;
135 /* Account TIME and SIZE executed COUNT times into HISTOGRAM.
136 HASHTABLE is the on-side hash kept to avoid duplicates. */
138 static void
139 account_time_size (hash_table<histogram_hash> *hashtable,
140 vec<histogram_entry *> &histogram,
141 gcov_type count, int time, int size)
143 histogram_entry key = {count, 0, 0};
144 histogram_entry **val = hashtable->find_slot (&key, INSERT);
146 if (!*val)
148 *val = histogram_pool.allocate ();
149 **val = key;
150 histogram.safe_push (*val);
152 (*val)->time += time;
153 (*val)->size += size;
157 cmp_counts (const void *v1, const void *v2)
159 const histogram_entry *h1 = *(const histogram_entry * const *)v1;
160 const histogram_entry *h2 = *(const histogram_entry * const *)v2;
161 if (h1->count < h2->count)
162 return 1;
163 if (h1->count > h2->count)
164 return -1;
165 return 0;
168 /* Dump HISTOGRAM to FILE. */
170 static void
171 dump_histogram (FILE *file, vec<histogram_entry *> histogram)
173 unsigned int i;
174 gcov_type overall_time = 0, cumulated_time = 0, cumulated_size = 0, overall_size = 0;
176 fprintf (dump_file, "Histogram:\n");
177 for (i = 0; i < histogram.length (); i++)
179 overall_time += histogram[i]->count * histogram[i]->time;
180 overall_size += histogram[i]->size;
182 if (!overall_time)
183 overall_time = 1;
184 if (!overall_size)
185 overall_size = 1;
186 for (i = 0; i < histogram.length (); i++)
188 cumulated_time += histogram[i]->count * histogram[i]->time;
189 cumulated_size += histogram[i]->size;
190 fprintf (file, " %" PRId64": time:%i (%2.2f) size:%i (%2.2f)\n",
191 (int64_t) histogram[i]->count,
192 histogram[i]->time,
193 cumulated_time * 100.0 / overall_time,
194 histogram[i]->size,
195 cumulated_size * 100.0 / overall_size);
199 /* Collect histogram from CFG profiles. */
201 static void
202 ipa_profile_generate_summary (void)
204 struct cgraph_node *node;
205 gimple_stmt_iterator gsi;
206 basic_block bb;
208 hash_table<histogram_hash> hashtable (10);
210 FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node)
211 FOR_EACH_BB_FN (bb, DECL_STRUCT_FUNCTION (node->decl))
213 int time = 0;
214 int size = 0;
215 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
217 gimple stmt = gsi_stmt (gsi);
218 if (gimple_code (stmt) == GIMPLE_CALL
219 && !gimple_call_fndecl (stmt))
221 histogram_value h;
222 h = gimple_histogram_value_of_type
223 (DECL_STRUCT_FUNCTION (node->decl),
224 stmt, HIST_TYPE_INDIR_CALL);
225 /* No need to do sanity check: gimple_ic_transform already
226 takes away bad histograms. */
227 if (h)
229 /* counter 0 is target, counter 1 is number of execution we called target,
230 counter 2 is total number of executions. */
231 if (h->hvalue.counters[2])
233 struct cgraph_edge * e = node->get_edge (stmt);
234 if (e && !e->indirect_unknown_callee)
235 continue;
236 e->indirect_info->common_target_id
237 = h->hvalue.counters [0];
238 e->indirect_info->common_target_probability
239 = GCOV_COMPUTE_SCALE (h->hvalue.counters [1], h->hvalue.counters [2]);
240 if (e->indirect_info->common_target_probability > REG_BR_PROB_BASE)
242 if (dump_file)
243 fprintf (dump_file, "Probability capped to 1\n");
244 e->indirect_info->common_target_probability = REG_BR_PROB_BASE;
247 gimple_remove_histogram_value (DECL_STRUCT_FUNCTION (node->decl),
248 stmt, h);
251 time += estimate_num_insns (stmt, &eni_time_weights);
252 size += estimate_num_insns (stmt, &eni_size_weights);
254 account_time_size (&hashtable, histogram, bb->count, time, size);
256 histogram.qsort (cmp_counts);
259 /* Serialize the ipa info for lto. */
261 static void
262 ipa_profile_write_summary (void)
264 struct lto_simple_output_block *ob
265 = lto_create_simple_output_block (LTO_section_ipa_profile);
266 unsigned int i;
268 streamer_write_uhwi_stream (ob->main_stream, histogram.length ());
269 for (i = 0; i < histogram.length (); i++)
271 streamer_write_gcov_count_stream (ob->main_stream, histogram[i]->count);
272 streamer_write_uhwi_stream (ob->main_stream, histogram[i]->time);
273 streamer_write_uhwi_stream (ob->main_stream, histogram[i]->size);
275 lto_destroy_simple_output_block (ob);
278 /* Deserialize the ipa info for lto. */
280 static void
281 ipa_profile_read_summary (void)
283 struct lto_file_decl_data ** file_data_vec
284 = lto_get_file_decl_data ();
285 struct lto_file_decl_data * file_data;
286 int j = 0;
288 hash_table<histogram_hash> hashtable (10);
290 while ((file_data = file_data_vec[j++]))
292 const char *data;
293 size_t len;
294 struct lto_input_block *ib
295 = lto_create_simple_input_block (file_data,
296 LTO_section_ipa_profile,
297 &data, &len);
298 if (ib)
300 unsigned int num = streamer_read_uhwi (ib);
301 unsigned int n;
302 for (n = 0; n < num; n++)
304 gcov_type count = streamer_read_gcov_count (ib);
305 int time = streamer_read_uhwi (ib);
306 int size = streamer_read_uhwi (ib);
307 account_time_size (&hashtable, histogram,
308 count, time, size);
310 lto_destroy_simple_input_block (file_data,
311 LTO_section_ipa_profile,
312 ib, data, len);
315 histogram.qsort (cmp_counts);
318 /* Data used by ipa_propagate_frequency. */
320 struct ipa_propagate_frequency_data
322 cgraph_node *function_symbol;
323 bool maybe_unlikely_executed;
324 bool maybe_executed_once;
325 bool only_called_at_startup;
326 bool only_called_at_exit;
329 /* Worker for ipa_propagate_frequency_1. */
331 static bool
332 ipa_propagate_frequency_1 (struct cgraph_node *node, void *data)
334 struct ipa_propagate_frequency_data *d;
335 struct cgraph_edge *edge;
337 d = (struct ipa_propagate_frequency_data *)data;
338 for (edge = node->callers;
339 edge && (d->maybe_unlikely_executed || d->maybe_executed_once
340 || d->only_called_at_startup || d->only_called_at_exit);
341 edge = edge->next_caller)
343 if (edge->caller != d->function_symbol)
345 d->only_called_at_startup &= edge->caller->only_called_at_startup;
346 /* It makes sense to put main() together with the static constructors.
347 It will be executed for sure, but rest of functions called from
348 main are definitely not at startup only. */
349 if (MAIN_NAME_P (DECL_NAME (edge->caller->decl)))
350 d->only_called_at_startup = 0;
351 d->only_called_at_exit &= edge->caller->only_called_at_exit;
354 /* When profile feedback is available, do not try to propagate too hard;
355 counts are already good guide on function frequencies and roundoff
356 errors can make us to push function into unlikely section even when
357 it is executed by the train run. Transfer the function only if all
358 callers are unlikely executed. */
359 if (profile_info
360 && opt_for_fn (d->function_symbol->decl, flag_branch_probabilities)
361 /* Thunks are not profiled. This is more or less implementation
362 bug. */
363 && !d->function_symbol->thunk.thunk_p
364 && (edge->caller->frequency != NODE_FREQUENCY_UNLIKELY_EXECUTED
365 || (edge->caller->global.inlined_to
366 && edge->caller->global.inlined_to->frequency
367 != NODE_FREQUENCY_UNLIKELY_EXECUTED)))
368 d->maybe_unlikely_executed = false;
369 if (!edge->frequency)
370 continue;
371 switch (edge->caller->frequency)
373 case NODE_FREQUENCY_UNLIKELY_EXECUTED:
374 break;
375 case NODE_FREQUENCY_EXECUTED_ONCE:
376 if (dump_file && (dump_flags & TDF_DETAILS))
377 fprintf (dump_file, " Called by %s that is executed once\n",
378 edge->caller->name ());
379 d->maybe_unlikely_executed = false;
380 if (inline_edge_summary (edge)->loop_depth)
382 d->maybe_executed_once = false;
383 if (dump_file && (dump_flags & TDF_DETAILS))
384 fprintf (dump_file, " Called in loop\n");
386 break;
387 case NODE_FREQUENCY_HOT:
388 case NODE_FREQUENCY_NORMAL:
389 if (dump_file && (dump_flags & TDF_DETAILS))
390 fprintf (dump_file, " Called by %s that is normal or hot\n",
391 edge->caller->name ());
392 d->maybe_unlikely_executed = false;
393 d->maybe_executed_once = false;
394 break;
397 return edge != NULL;
400 /* Return ture if NODE contains hot calls. */
402 bool
403 contains_hot_call_p (struct cgraph_node *node)
405 struct cgraph_edge *e;
406 for (e = node->callees; e; e = e->next_callee)
407 if (e->maybe_hot_p ())
408 return true;
409 else if (!e->inline_failed
410 && contains_hot_call_p (e->callee))
411 return true;
412 for (e = node->indirect_calls; e; e = e->next_callee)
413 if (e->maybe_hot_p ())
414 return true;
415 return false;
418 /* See if the frequency of NODE can be updated based on frequencies of its
419 callers. */
420 bool
421 ipa_propagate_frequency (struct cgraph_node *node)
423 struct ipa_propagate_frequency_data d = {node, true, true, true, true};
424 bool changed = false;
426 /* We can not propagate anything useful about externally visible functions
427 nor about virtuals. */
428 if (!node->local.local
429 || node->alias
430 || (opt_for_fn (node->decl, flag_devirtualize)
431 && DECL_VIRTUAL_P (node->decl)))
432 return false;
433 gcc_assert (node->analyzed);
434 if (dump_file && (dump_flags & TDF_DETAILS))
435 fprintf (dump_file, "Processing frequency %s\n", node->name ());
437 node->call_for_symbol_and_aliases (ipa_propagate_frequency_1, &d,
438 true);
440 if ((d.only_called_at_startup && !d.only_called_at_exit)
441 && !node->only_called_at_startup)
443 node->only_called_at_startup = true;
444 if (dump_file)
445 fprintf (dump_file, "Node %s promoted to only called at startup.\n",
446 node->name ());
447 changed = true;
449 if ((d.only_called_at_exit && !d.only_called_at_startup)
450 && !node->only_called_at_exit)
452 node->only_called_at_exit = true;
453 if (dump_file)
454 fprintf (dump_file, "Node %s promoted to only called at exit.\n",
455 node->name ());
456 changed = true;
459 /* With profile we can decide on hot/normal based on count. */
460 if (node->count)
462 bool hot = false;
463 if (node->count >= get_hot_bb_threshold ())
464 hot = true;
465 if (!hot)
466 hot |= contains_hot_call_p (node);
467 if (hot)
469 if (node->frequency != NODE_FREQUENCY_HOT)
471 if (dump_file)
472 fprintf (dump_file, "Node %s promoted to hot.\n",
473 node->name ());
474 node->frequency = NODE_FREQUENCY_HOT;
475 return true;
477 return false;
479 else if (node->frequency == NODE_FREQUENCY_HOT)
481 if (dump_file)
482 fprintf (dump_file, "Node %s reduced to normal.\n",
483 node->name ());
484 node->frequency = NODE_FREQUENCY_NORMAL;
485 changed = true;
488 /* These come either from profile or user hints; never update them. */
489 if (node->frequency == NODE_FREQUENCY_HOT
490 || node->frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED)
491 return changed;
492 if (d.maybe_unlikely_executed)
494 node->frequency = NODE_FREQUENCY_UNLIKELY_EXECUTED;
495 if (dump_file)
496 fprintf (dump_file, "Node %s promoted to unlikely executed.\n",
497 node->name ());
498 changed = true;
500 else if (d.maybe_executed_once && node->frequency != NODE_FREQUENCY_EXECUTED_ONCE)
502 node->frequency = NODE_FREQUENCY_EXECUTED_ONCE;
503 if (dump_file)
504 fprintf (dump_file, "Node %s promoted to executed once.\n",
505 node->name ());
506 changed = true;
508 return changed;
511 /* Simple ipa profile pass propagating frequencies across the callgraph. */
513 static unsigned int
514 ipa_profile (void)
516 struct cgraph_node **order;
517 struct cgraph_edge *e;
518 int order_pos;
519 bool something_changed = false;
520 int i;
521 gcov_type overall_time = 0, cutoff = 0, cumulated = 0, overall_size = 0;
522 struct cgraph_node *n,*n2;
523 int nindirect = 0, ncommon = 0, nunknown = 0, nuseless = 0, nconverted = 0;
524 int nmismatch = 0, nimpossible = 0;
525 bool node_map_initialized = false;
527 if (dump_file)
528 dump_histogram (dump_file, histogram);
529 for (i = 0; i < (int)histogram.length (); i++)
531 overall_time += histogram[i]->count * histogram[i]->time;
532 overall_size += histogram[i]->size;
534 if (overall_time)
536 gcov_type threshold;
538 gcc_assert (overall_size);
539 if (dump_file)
541 gcov_type min, cumulated_time = 0, cumulated_size = 0;
543 fprintf (dump_file, "Overall time: %" PRId64"\n",
544 (int64_t)overall_time);
545 min = get_hot_bb_threshold ();
546 for (i = 0; i < (int)histogram.length () && histogram[i]->count >= min;
547 i++)
549 cumulated_time += histogram[i]->count * histogram[i]->time;
550 cumulated_size += histogram[i]->size;
552 fprintf (dump_file, "GCOV min count: %" PRId64
553 " Time:%3.2f%% Size:%3.2f%%\n",
554 (int64_t)min,
555 cumulated_time * 100.0 / overall_time,
556 cumulated_size * 100.0 / overall_size);
558 cutoff = (overall_time * PARAM_VALUE (HOT_BB_COUNT_WS_PERMILLE) + 500) / 1000;
559 threshold = 0;
560 for (i = 0; cumulated < cutoff; i++)
562 cumulated += histogram[i]->count * histogram[i]->time;
563 threshold = histogram[i]->count;
565 if (!threshold)
566 threshold = 1;
567 if (dump_file)
569 gcov_type cumulated_time = 0, cumulated_size = 0;
571 for (i = 0;
572 i < (int)histogram.length () && histogram[i]->count >= threshold;
573 i++)
575 cumulated_time += histogram[i]->count * histogram[i]->time;
576 cumulated_size += histogram[i]->size;
578 fprintf (dump_file, "Determined min count: %" PRId64
579 " Time:%3.2f%% Size:%3.2f%%\n",
580 (int64_t)threshold,
581 cumulated_time * 100.0 / overall_time,
582 cumulated_size * 100.0 / overall_size);
584 if (threshold > get_hot_bb_threshold ()
585 || in_lto_p)
587 if (dump_file)
588 fprintf (dump_file, "Threshold updated.\n");
589 set_hot_bb_threshold (threshold);
592 histogram.release ();
593 histogram_pool.release ();
595 /* Produce speculative calls: we saved common traget from porfiling into
596 e->common_target_id. Now, at link time, we can look up corresponding
597 function node and produce speculative call. */
599 FOR_EACH_DEFINED_FUNCTION (n)
601 bool update = false;
603 if (!opt_for_fn (n->decl, flag_ipa_profile))
604 continue;
606 for (e = n->indirect_calls; e; e = e->next_callee)
608 if (n->count)
609 nindirect++;
610 if (e->indirect_info->common_target_id)
612 if (!node_map_initialized)
613 init_node_map (false);
614 node_map_initialized = true;
615 ncommon++;
616 n2 = find_func_by_profile_id (e->indirect_info->common_target_id);
617 if (n2)
619 if (dump_file)
621 fprintf (dump_file, "Indirect call -> direct call from"
622 " other module %s/%i => %s/%i, prob %3.2f\n",
623 xstrdup_for_dump (n->name ()), n->order,
624 xstrdup_for_dump (n2->name ()), n2->order,
625 e->indirect_info->common_target_probability
626 / (float)REG_BR_PROB_BASE);
628 if (e->indirect_info->common_target_probability
629 < REG_BR_PROB_BASE / 2)
631 nuseless++;
632 if (dump_file)
633 fprintf (dump_file,
634 "Not speculating: probability is too low.\n");
636 else if (!e->maybe_hot_p ())
638 nuseless++;
639 if (dump_file)
640 fprintf (dump_file,
641 "Not speculating: call is cold.\n");
643 else if (n2->get_availability () <= AVAIL_INTERPOSABLE
644 && n2->can_be_discarded_p ())
646 nuseless++;
647 if (dump_file)
648 fprintf (dump_file,
649 "Not speculating: target is overwritable "
650 "and can be discarded.\n");
652 else if (ipa_node_params_sum && ipa_edge_args_vector
653 && !IPA_NODE_REF (n2)->descriptors.is_empty ()
654 && ipa_get_param_count (IPA_NODE_REF (n2))
655 != ipa_get_cs_argument_count (IPA_EDGE_REF (e))
656 && (ipa_get_param_count (IPA_NODE_REF (n2))
657 >= ipa_get_cs_argument_count (IPA_EDGE_REF (e))
658 || !stdarg_p (TREE_TYPE (n2->decl))))
660 nmismatch++;
661 if (dump_file)
662 fprintf (dump_file,
663 "Not speculating: "
664 "parameter count mistmatch\n");
666 else if (e->indirect_info->polymorphic
667 && !opt_for_fn (n->decl, flag_devirtualize)
668 && !possible_polymorphic_call_target_p (e, n2))
670 nimpossible++;
671 if (dump_file)
672 fprintf (dump_file,
673 "Not speculating: "
674 "function is not in the polymorphic "
675 "call target list\n");
677 else
679 /* Target may be overwritable, but profile says that
680 control flow goes to this particular implementation
681 of N2. Speculate on the local alias to allow inlining.
683 if (!n2->can_be_discarded_p ())
685 cgraph_node *alias;
686 alias = dyn_cast<cgraph_node *> (n2->noninterposable_alias ());
687 if (alias)
688 n2 = alias;
690 nconverted++;
691 e->make_speculative
692 (n2,
693 apply_scale (e->count,
694 e->indirect_info->common_target_probability),
695 apply_scale (e->frequency,
696 e->indirect_info->common_target_probability));
697 update = true;
700 else
702 if (dump_file)
703 fprintf (dump_file, "Function with profile-id %i not found.\n",
704 e->indirect_info->common_target_id);
705 nunknown++;
709 if (update)
710 inline_update_overall_summary (n);
712 if (node_map_initialized)
713 del_node_map ();
714 if (dump_file && nindirect)
715 fprintf (dump_file,
716 "%i indirect calls trained.\n"
717 "%i (%3.2f%%) have common target.\n"
718 "%i (%3.2f%%) targets was not found.\n"
719 "%i (%3.2f%%) targets had parameter count mismatch.\n"
720 "%i (%3.2f%%) targets was not in polymorphic call target list.\n"
721 "%i (%3.2f%%) speculations seems useless.\n"
722 "%i (%3.2f%%) speculations produced.\n",
723 nindirect,
724 ncommon, ncommon * 100.0 / nindirect,
725 nunknown, nunknown * 100.0 / nindirect,
726 nmismatch, nmismatch * 100.0 / nindirect,
727 nimpossible, nimpossible * 100.0 / nindirect,
728 nuseless, nuseless * 100.0 / nindirect,
729 nconverted, nconverted * 100.0 / nindirect);
731 order = XCNEWVEC (struct cgraph_node *, symtab->cgraph_count);
732 order_pos = ipa_reverse_postorder (order);
733 for (i = order_pos - 1; i >= 0; i--)
735 if (order[i]->local.local
736 && opt_for_fn (order[i]->decl, flag_ipa_profile)
737 && ipa_propagate_frequency (order[i]))
739 for (e = order[i]->callees; e; e = e->next_callee)
740 if (e->callee->local.local && !e->callee->aux)
742 something_changed = true;
743 e->callee->aux = (void *)1;
746 order[i]->aux = NULL;
749 while (something_changed)
751 something_changed = false;
752 for (i = order_pos - 1; i >= 0; i--)
754 if (order[i]->aux
755 && opt_for_fn (order[i]->decl, flag_ipa_profile)
756 && ipa_propagate_frequency (order[i]))
758 for (e = order[i]->callees; e; e = e->next_callee)
759 if (e->callee->local.local && !e->callee->aux)
761 something_changed = true;
762 e->callee->aux = (void *)1;
765 order[i]->aux = NULL;
768 free (order);
769 return 0;
772 namespace {
774 const pass_data pass_data_ipa_profile =
776 IPA_PASS, /* type */
777 "profile_estimate", /* name */
778 OPTGROUP_NONE, /* optinfo_flags */
779 TV_IPA_PROFILE, /* tv_id */
780 0, /* properties_required */
781 0, /* properties_provided */
782 0, /* properties_destroyed */
783 0, /* todo_flags_start */
784 0, /* todo_flags_finish */
787 class pass_ipa_profile : public ipa_opt_pass_d
789 public:
790 pass_ipa_profile (gcc::context *ctxt)
791 : ipa_opt_pass_d (pass_data_ipa_profile, ctxt,
792 ipa_profile_generate_summary, /* generate_summary */
793 ipa_profile_write_summary, /* write_summary */
794 ipa_profile_read_summary, /* read_summary */
795 NULL, /* write_optimization_summary */
796 NULL, /* read_optimization_summary */
797 NULL, /* stmt_fixup */
798 0, /* function_transform_todo_flags_start */
799 NULL, /* function_transform */
800 NULL) /* variable_transform */
803 /* opt_pass methods: */
804 virtual bool gate (function *) { return flag_ipa_profile || in_lto_p; }
805 virtual unsigned int execute (function *) { return ipa_profile (); }
807 }; // class pass_ipa_profile
809 } // anon namespace
811 ipa_opt_pass_d *
812 make_pass_ipa_profile (gcc::context *ctxt)
814 return new pass_ipa_profile (ctxt);