]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/ipa-profile.c
remove has_execute
[thirdparty/gcc.git] / gcc / ipa-profile.c
CommitLineData
6eaf903b 1/* Basic IPA optimizations based on profile.
3aea1f79 2 Copyright (C) 2003-2014 Free Software Foundation, Inc.
6eaf903b 3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 3, or (at your option) any later
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
19
e27f29dd 20/* ipa-profile pass implements the following analysis propagating profille
21 inter-procedurally.
22
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 complette only with LTO,
26 otherwise it contains information only about the current unit.
27
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.
34
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.
40
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). */
6eaf903b 47#include "config.h"
48#include "system.h"
49#include "coretypes.h"
50#include "tm.h"
41a8aa41 51#include "tree.h"
6eaf903b 52#include "cgraph.h"
53#include "tree-pass.h"
bc61cadb 54#include "tree-ssa-alias.h"
55#include "internal-fn.h"
56#include "gimple-expr.h"
6eaf903b 57#include "gimple.h"
dcf1a1ec 58#include "gimple-iterator.h"
6eaf903b 59#include "flags.h"
60#include "target.h"
61#include "tree-iterator.h"
62#include "ipa-utils.h"
6eaf903b 63#include "profile.h"
64#include "params.h"
65#include "value-prof.h"
66#include "alloc-pool.h"
67#include "tree-inline.h"
68#include "lto-streamer.h"
69#include "data-streamer.h"
70#include "ipa-inline.h"
71
72/* Entry in the histogram. */
73
74struct histogram_entry
75{
76 gcov_type count;
77 int time;
78 int size;
79};
80
81/* Histogram of profile values.
82 The histogram is represented as an ordered vector of entries allocated via
83 histogram_pool. During construction a separate hashtable is kept to lookup
84 duplicate entries. */
85
86vec<histogram_entry *> histogram;
87static alloc_pool histogram_pool;
88
89/* Hashtable support for storing SSA names hashed by their SSA_NAME_VAR. */
90
91struct histogram_hash : typed_noop_remove <histogram_entry>
92{
93 typedef histogram_entry value_type;
94 typedef histogram_entry compare_type;
95 static inline hashval_t hash (const value_type *);
96 static inline int equal (const value_type *, const compare_type *);
97};
98
99inline hashval_t
100histogram_hash::hash (const histogram_entry *val)
101{
102 return val->count;
103}
104
105inline int
106histogram_hash::equal (const histogram_entry *val, const histogram_entry *val2)
107{
108 return val->count == val2->count;
109}
110
111/* Account TIME and SIZE executed COUNT times into HISTOGRAM.
112 HASHTABLE is the on-side hash kept to avoid duplicates. */
113
114static void
c1f445d2 115account_time_size (hash_table<histogram_hash> *hashtable,
6eaf903b 116 vec<histogram_entry *> &histogram,
117 gcov_type count, int time, int size)
118{
119 histogram_entry key = {count, 0, 0};
c1f445d2 120 histogram_entry **val = hashtable->find_slot (&key, INSERT);
6eaf903b 121
122 if (!*val)
123 {
124 *val = (histogram_entry *) pool_alloc (histogram_pool);
125 **val = key;
126 histogram.safe_push (*val);
127 }
128 (*val)->time += time;
129 (*val)->size += size;
130}
131
132int
133cmp_counts (const void *v1, const void *v2)
134{
135 const histogram_entry *h1 = *(const histogram_entry * const *)v1;
136 const histogram_entry *h2 = *(const histogram_entry * const *)v2;
137 if (h1->count < h2->count)
138 return 1;
139 if (h1->count > h2->count)
140 return -1;
141 return 0;
142}
143
144/* Dump HISTOGRAM to FILE. */
145
146static void
147dump_histogram (FILE *file, vec<histogram_entry *> histogram)
148{
149 unsigned int i;
150 gcov_type overall_time = 0, cumulated_time = 0, cumulated_size = 0, overall_size = 0;
151
152 fprintf (dump_file, "Histogram:\n");
153 for (i = 0; i < histogram.length (); i++)
154 {
155 overall_time += histogram[i]->count * histogram[i]->time;
156 overall_size += histogram[i]->size;
157 }
158 if (!overall_time)
159 overall_time = 1;
160 if (!overall_size)
161 overall_size = 1;
162 for (i = 0; i < histogram.length (); i++)
163 {
164 cumulated_time += histogram[i]->count * histogram[i]->time;
165 cumulated_size += histogram[i]->size;
3a4303e7 166 fprintf (file, " %"PRId64": time:%i (%2.2f) size:%i (%2.2f)\n",
167 (int64_t) histogram[i]->count,
6eaf903b 168 histogram[i]->time,
169 cumulated_time * 100.0 / overall_time,
170 histogram[i]->size,
171 cumulated_size * 100.0 / overall_size);
172 }
173}
174
175/* Collect histogram from CFG profiles. */
176
177static void
178ipa_profile_generate_summary (void)
179{
180 struct cgraph_node *node;
181 gimple_stmt_iterator gsi;
6eaf903b 182 basic_block bb;
183
c1f445d2 184 hash_table<histogram_hash> hashtable (10);
6eaf903b 185 histogram_pool = create_alloc_pool ("IPA histogram", sizeof (struct histogram_entry),
186 10);
187
188 FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node)
02774f2d 189 FOR_EACH_BB_FN (bb, DECL_STRUCT_FUNCTION (node->decl))
6eaf903b 190 {
191 int time = 0;
192 int size = 0;
193 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
194 {
195 gimple stmt = gsi_stmt (gsi);
196 if (gimple_code (stmt) == GIMPLE_CALL
197 && !gimple_call_fndecl (stmt))
198 {
199 histogram_value h;
200 h = gimple_histogram_value_of_type
02774f2d 201 (DECL_STRUCT_FUNCTION (node->decl),
6eaf903b 202 stmt, HIST_TYPE_INDIR_CALL);
203 /* No need to do sanity check: gimple_ic_transform already
204 takes away bad histograms. */
205 if (h)
206 {
207 /* counter 0 is target, counter 1 is number of execution we called target,
208 counter 2 is total number of executions. */
209 if (h->hvalue.counters[2])
210 {
211 struct cgraph_edge * e = cgraph_edge (node, stmt);
3d3bc5e0 212 if (e && !e->indirect_unknown_callee)
213 continue;
6eaf903b 214 e->indirect_info->common_target_id
215 = h->hvalue.counters [0];
216 e->indirect_info->common_target_probability
217 = GCOV_COMPUTE_SCALE (h->hvalue.counters [1], h->hvalue.counters [2]);
218 if (e->indirect_info->common_target_probability > REG_BR_PROB_BASE)
219 {
220 if (dump_file)
221 fprintf (dump_file, "Probability capped to 1\n");
222 e->indirect_info->common_target_probability = REG_BR_PROB_BASE;
223 }
224 }
02774f2d 225 gimple_remove_histogram_value (DECL_STRUCT_FUNCTION (node->decl),
6eaf903b 226 stmt, h);
227 }
228 }
229 time += estimate_num_insns (stmt, &eni_time_weights);
230 size += estimate_num_insns (stmt, &eni_size_weights);
231 }
c1f445d2 232 account_time_size (&hashtable, histogram, bb->count, time, size);
6eaf903b 233 }
6eaf903b 234 histogram.qsort (cmp_counts);
235}
236
237/* Serialize the ipa info for lto. */
238
239static void
240ipa_profile_write_summary (void)
241{
242 struct lto_simple_output_block *ob
243 = lto_create_simple_output_block (LTO_section_ipa_profile);
244 unsigned int i;
245
9af5ce0c 246 streamer_write_uhwi_stream (ob->main_stream, histogram.length ());
6eaf903b 247 for (i = 0; i < histogram.length (); i++)
248 {
249 streamer_write_gcov_count_stream (ob->main_stream, histogram[i]->count);
250 streamer_write_uhwi_stream (ob->main_stream, histogram[i]->time);
251 streamer_write_uhwi_stream (ob->main_stream, histogram[i]->size);
252 }
253 lto_destroy_simple_output_block (ob);
254}
255
256/* Deserialize the ipa info for lto. */
257
258static void
259ipa_profile_read_summary (void)
260{
261 struct lto_file_decl_data ** file_data_vec
262 = lto_get_file_decl_data ();
263 struct lto_file_decl_data * file_data;
6eaf903b 264 int j = 0;
265
c1f445d2 266 hash_table<histogram_hash> hashtable (10);
6eaf903b 267 histogram_pool = create_alloc_pool ("IPA histogram", sizeof (struct histogram_entry),
268 10);
269
270 while ((file_data = file_data_vec[j++]))
271 {
272 const char *data;
273 size_t len;
274 struct lto_input_block *ib
275 = lto_create_simple_input_block (file_data,
276 LTO_section_ipa_profile,
277 &data, &len);
278 if (ib)
279 {
280 unsigned int num = streamer_read_uhwi (ib);
281 unsigned int n;
282 for (n = 0; n < num; n++)
283 {
284 gcov_type count = streamer_read_gcov_count (ib);
285 int time = streamer_read_uhwi (ib);
286 int size = streamer_read_uhwi (ib);
c1f445d2 287 account_time_size (&hashtable, histogram,
6eaf903b 288 count, time, size);
289 }
290 lto_destroy_simple_input_block (file_data,
291 LTO_section_ipa_profile,
292 ib, data, len);
293 }
294 }
6eaf903b 295 histogram.qsort (cmp_counts);
296}
297
298/* Data used by ipa_propagate_frequency. */
299
300struct ipa_propagate_frequency_data
301{
302 bool maybe_unlikely_executed;
303 bool maybe_executed_once;
304 bool only_called_at_startup;
305 bool only_called_at_exit;
306};
307
308/* Worker for ipa_propagate_frequency_1. */
309
310static bool
311ipa_propagate_frequency_1 (struct cgraph_node *node, void *data)
312{
313 struct ipa_propagate_frequency_data *d;
314 struct cgraph_edge *edge;
315
316 d = (struct ipa_propagate_frequency_data *)data;
317 for (edge = node->callers;
318 edge && (d->maybe_unlikely_executed || d->maybe_executed_once
319 || d->only_called_at_startup || d->only_called_at_exit);
320 edge = edge->next_caller)
321 {
322 if (edge->caller != node)
323 {
324 d->only_called_at_startup &= edge->caller->only_called_at_startup;
325 /* It makes sense to put main() together with the static constructors.
326 It will be executed for sure, but rest of functions called from
327 main are definitely not at startup only. */
02774f2d 328 if (MAIN_NAME_P (DECL_NAME (edge->caller->decl)))
6eaf903b 329 d->only_called_at_startup = 0;
330 d->only_called_at_exit &= edge->caller->only_called_at_exit;
331 }
e27f29dd 332
333 /* When profile feedback is available, do not try to propagate too hard;
334 counts are already good guide on function frequencies and roundoff
335 errors can make us to push function into unlikely section even when
336 it is executed by the train run. Transfer the function only if all
337 callers are unlikely executed. */
338 if (profile_info && flag_branch_probabilities
339 && (edge->caller->frequency != NODE_FREQUENCY_UNLIKELY_EXECUTED
340 || (edge->caller->global.inlined_to
341 && edge->caller->global.inlined_to->frequency
342 != NODE_FREQUENCY_UNLIKELY_EXECUTED)))
343 d->maybe_unlikely_executed = false;
6eaf903b 344 if (!edge->frequency)
345 continue;
346 switch (edge->caller->frequency)
347 {
348 case NODE_FREQUENCY_UNLIKELY_EXECUTED:
349 break;
350 case NODE_FREQUENCY_EXECUTED_ONCE:
351 if (dump_file && (dump_flags & TDF_DETAILS))
352 fprintf (dump_file, " Called by %s that is executed once\n",
f1c8b4d7 353 edge->caller->name ());
6eaf903b 354 d->maybe_unlikely_executed = false;
355 if (inline_edge_summary (edge)->loop_depth)
356 {
357 d->maybe_executed_once = false;
358 if (dump_file && (dump_flags & TDF_DETAILS))
359 fprintf (dump_file, " Called in loop\n");
360 }
361 break;
362 case NODE_FREQUENCY_HOT:
363 case NODE_FREQUENCY_NORMAL:
364 if (dump_file && (dump_flags & TDF_DETAILS))
365 fprintf (dump_file, " Called by %s that is normal or hot\n",
f1c8b4d7 366 edge->caller->name ());
6eaf903b 367 d->maybe_unlikely_executed = false;
368 d->maybe_executed_once = false;
369 break;
370 }
371 }
372 return edge != NULL;
373}
374
e27f29dd 375/* Return ture if NODE contains hot calls. */
376
377bool
378contains_hot_call_p (struct cgraph_node *node)
379{
380 struct cgraph_edge *e;
381 for (e = node->callees; e; e = e->next_callee)
382 if (cgraph_maybe_hot_edge_p (e))
383 return true;
384 else if (!e->inline_failed
385 && contains_hot_call_p (e->callee))
386 return true;
387 for (e = node->indirect_calls; e; e = e->next_callee)
388 if (cgraph_maybe_hot_edge_p (e))
389 return true;
390 return false;
391}
392
6eaf903b 393/* See if the frequency of NODE can be updated based on frequencies of its
394 callers. */
395bool
396ipa_propagate_frequency (struct cgraph_node *node)
397{
398 struct ipa_propagate_frequency_data d = {true, true, true, true};
399 bool changed = false;
400
401 /* We can not propagate anything useful about externally visible functions
402 nor about virtuals. */
403 if (!node->local.local
02774f2d 404 || node->alias
405 || (flag_devirtualize && DECL_VIRTUAL_P (node->decl)))
6eaf903b 406 return false;
02774f2d 407 gcc_assert (node->analyzed);
6eaf903b 408 if (dump_file && (dump_flags & TDF_DETAILS))
f1c8b4d7 409 fprintf (dump_file, "Processing frequency %s\n", node->name ());
6eaf903b 410
411 cgraph_for_node_and_aliases (node, ipa_propagate_frequency_1, &d, true);
412
413 if ((d.only_called_at_startup && !d.only_called_at_exit)
414 && !node->only_called_at_startup)
415 {
416 node->only_called_at_startup = true;
417 if (dump_file)
418 fprintf (dump_file, "Node %s promoted to only called at startup.\n",
f1c8b4d7 419 node->name ());
6eaf903b 420 changed = true;
421 }
422 if ((d.only_called_at_exit && !d.only_called_at_startup)
423 && !node->only_called_at_exit)
424 {
425 node->only_called_at_exit = true;
426 if (dump_file)
427 fprintf (dump_file, "Node %s promoted to only called at exit.\n",
f1c8b4d7 428 node->name ());
6eaf903b 429 changed = true;
430 }
e27f29dd 431
432 /* With profile we can decide on hot/normal based on count. */
433 if (node->count)
434 {
435 bool hot = false;
436 if (node->count >= get_hot_bb_threshold ())
437 hot = true;
438 if (!hot)
439 hot |= contains_hot_call_p (node);
440 if (hot)
441 {
442 if (node->frequency != NODE_FREQUENCY_HOT)
443 {
444 if (dump_file)
445 fprintf (dump_file, "Node %s promoted to hot.\n",
f1c8b4d7 446 node->name ());
e27f29dd 447 node->frequency = NODE_FREQUENCY_HOT;
448 return true;
449 }
450 return false;
451 }
452 else if (node->frequency == NODE_FREQUENCY_HOT)
453 {
454 if (dump_file)
455 fprintf (dump_file, "Node %s reduced to normal.\n",
f1c8b4d7 456 node->name ());
e27f29dd 457 node->frequency = NODE_FREQUENCY_NORMAL;
458 changed = true;
459 }
460 }
6eaf903b 461 /* These come either from profile or user hints; never update them. */
462 if (node->frequency == NODE_FREQUENCY_HOT
463 || node->frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED)
464 return changed;
465 if (d.maybe_unlikely_executed)
466 {
467 node->frequency = NODE_FREQUENCY_UNLIKELY_EXECUTED;
468 if (dump_file)
469 fprintf (dump_file, "Node %s promoted to unlikely executed.\n",
f1c8b4d7 470 node->name ());
6eaf903b 471 changed = true;
472 }
473 else if (d.maybe_executed_once && node->frequency != NODE_FREQUENCY_EXECUTED_ONCE)
474 {
475 node->frequency = NODE_FREQUENCY_EXECUTED_ONCE;
476 if (dump_file)
477 fprintf (dump_file, "Node %s promoted to executed once.\n",
f1c8b4d7 478 node->name ());
6eaf903b 479 changed = true;
480 }
481 return changed;
482}
483
484/* Simple ipa profile pass propagating frequencies across the callgraph. */
485
486static unsigned int
487ipa_profile (void)
488{
489 struct cgraph_node **order;
490 struct cgraph_edge *e;
491 int order_pos;
492 bool something_changed = false;
493 int i;
494 gcov_type overall_time = 0, cutoff = 0, cumulated = 0, overall_size = 0;
495 struct cgraph_node *n,*n2;
496 int nindirect = 0, ncommon = 0, nunknown = 0, nuseless = 0, nconverted = 0;
497 bool node_map_initialized = false;
498
499 if (dump_file)
500 dump_histogram (dump_file, histogram);
501 for (i = 0; i < (int)histogram.length (); i++)
502 {
503 overall_time += histogram[i]->count * histogram[i]->time;
504 overall_size += histogram[i]->size;
505 }
506 if (overall_time)
507 {
508 gcov_type threshold;
509
510 gcc_assert (overall_size);
511 if (dump_file)
512 {
513 gcov_type min, cumulated_time = 0, cumulated_size = 0;
514
3a4303e7 515 fprintf (dump_file, "Overall time: %"PRId64"\n",
516 (int64_t)overall_time);
6eaf903b 517 min = get_hot_bb_threshold ();
518 for (i = 0; i < (int)histogram.length () && histogram[i]->count >= min;
519 i++)
520 {
521 cumulated_time += histogram[i]->count * histogram[i]->time;
522 cumulated_size += histogram[i]->size;
523 }
3a4303e7 524 fprintf (dump_file, "GCOV min count: %"PRId64
6eaf903b 525 " Time:%3.2f%% Size:%3.2f%%\n",
3a4303e7 526 (int64_t)min,
6eaf903b 527 cumulated_time * 100.0 / overall_time,
528 cumulated_size * 100.0 / overall_size);
529 }
530 cutoff = (overall_time * PARAM_VALUE (HOT_BB_COUNT_WS_PERMILLE) + 500) / 1000;
531 threshold = 0;
532 for (i = 0; cumulated < cutoff; i++)
533 {
534 cumulated += histogram[i]->count * histogram[i]->time;
535 threshold = histogram[i]->count;
536 }
537 if (!threshold)
538 threshold = 1;
539 if (dump_file)
540 {
541 gcov_type cumulated_time = 0, cumulated_size = 0;
542
543 for (i = 0;
544 i < (int)histogram.length () && histogram[i]->count >= threshold;
545 i++)
546 {
547 cumulated_time += histogram[i]->count * histogram[i]->time;
548 cumulated_size += histogram[i]->size;
549 }
3a4303e7 550 fprintf (dump_file, "Determined min count: %"PRId64
6eaf903b 551 " Time:%3.2f%% Size:%3.2f%%\n",
3a4303e7 552 (int64_t)threshold,
6eaf903b 553 cumulated_time * 100.0 / overall_time,
554 cumulated_size * 100.0 / overall_size);
555 }
556 if (threshold > get_hot_bb_threshold ()
557 || in_lto_p)
558 {
559 if (dump_file)
560 fprintf (dump_file, "Threshold updated.\n");
561 set_hot_bb_threshold (threshold);
562 }
563 }
9af5ce0c 564 histogram.release ();
6eaf903b 565 free_alloc_pool (histogram_pool);
566
567 /* Produce speculative calls: we saved common traget from porfiling into
568 e->common_target_id. Now, at link time, we can look up corresponding
569 function node and produce speculative call. */
570
571 FOR_EACH_DEFINED_FUNCTION (n)
572 {
573 bool update = false;
574
575 for (e = n->indirect_calls; e; e = e->next_callee)
576 {
577 if (n->count)
578 nindirect++;
579 if (e->indirect_info->common_target_id)
580 {
581 if (!node_map_initialized)
582 init_node_map (false);
583 node_map_initialized = true;
584 ncommon++;
585 n2 = find_func_by_profile_id (e->indirect_info->common_target_id);
586 if (n2)
587 {
588 if (dump_file)
589 {
590 fprintf (dump_file, "Indirect call -> direct call from"
591 " other module %s/%i => %s/%i, prob %3.2f\n",
f1c8b4d7 592 xstrdup (n->name ()), n->order,
593 xstrdup (n2->name ()), n2->order,
6eaf903b 594 e->indirect_info->common_target_probability
595 / (float)REG_BR_PROB_BASE);
596 }
597 if (e->indirect_info->common_target_probability
598 < REG_BR_PROB_BASE / 2)
599 {
600 nuseless++;
601 if (dump_file)
602 fprintf (dump_file,
603 "Not speculating: probability is too low.\n");
604 }
605 else if (!cgraph_maybe_hot_edge_p (e))
606 {
607 nuseless++;
608 if (dump_file)
609 fprintf (dump_file,
610 "Not speculating: call is cold.\n");
611 }
612 else if (cgraph_function_body_availability (n2)
613 <= AVAIL_OVERWRITABLE
02774f2d 614 && symtab_can_be_discarded (n2))
6eaf903b 615 {
616 nuseless++;
617 if (dump_file)
618 fprintf (dump_file,
619 "Not speculating: target is overwritable "
620 "and can be discarded.\n");
621 }
622 else
623 {
624 /* Target may be overwritable, but profile says that
625 control flow goes to this particular implementation
626 of N2. Speculate on the local alias to allow inlining.
627 */
02774f2d 628 if (!symtab_can_be_discarded (n2))
460140a5 629 {
630 cgraph_node *alias;
631 alias = cgraph (symtab_nonoverwritable_alias
02774f2d 632 (n2));
460140a5 633 if (alias)
634 n2 = alias;
635 }
6eaf903b 636 nconverted++;
637 cgraph_turn_edge_to_speculative
638 (e, n2,
639 apply_scale (e->count,
640 e->indirect_info->common_target_probability),
641 apply_scale (e->frequency,
642 e->indirect_info->common_target_probability));
643 update = true;
644 }
645 }
646 else
647 {
648 if (dump_file)
649 fprintf (dump_file, "Function with profile-id %i not found.\n",
650 e->indirect_info->common_target_id);
651 nunknown++;
652 }
653 }
654 }
655 if (update)
656 inline_update_overall_summary (n);
657 }
658 if (node_map_initialized)
659 del_node_map ();
660 if (dump_file && nindirect)
661 fprintf (dump_file,
662 "%i indirect calls trained.\n"
663 "%i (%3.2f%%) have common target.\n"
664 "%i (%3.2f%%) targets was not found.\n"
665 "%i (%3.2f%%) speculations seems useless.\n"
666 "%i (%3.2f%%) speculations produced.\n",
667 nindirect,
668 ncommon, ncommon * 100.0 / nindirect,
669 nunknown, nunknown * 100.0 / nindirect,
670 nuseless, nuseless * 100.0 / nindirect,
671 nconverted, nconverted * 100.0 / nindirect);
672
673 order = XCNEWVEC (struct cgraph_node *, cgraph_n_nodes);
674 order_pos = ipa_reverse_postorder (order);
675 for (i = order_pos - 1; i >= 0; i--)
676 {
677 if (order[i]->local.local && ipa_propagate_frequency (order[i]))
678 {
679 for (e = order[i]->callees; e; e = e->next_callee)
02774f2d 680 if (e->callee->local.local && !e->callee->aux)
6eaf903b 681 {
682 something_changed = true;
02774f2d 683 e->callee->aux = (void *)1;
6eaf903b 684 }
685 }
02774f2d 686 order[i]->aux = NULL;
6eaf903b 687 }
688
689 while (something_changed)
690 {
691 something_changed = false;
692 for (i = order_pos - 1; i >= 0; i--)
693 {
02774f2d 694 if (order[i]->aux && ipa_propagate_frequency (order[i]))
6eaf903b 695 {
696 for (e = order[i]->callees; e; e = e->next_callee)
02774f2d 697 if (e->callee->local.local && !e->callee->aux)
6eaf903b 698 {
699 something_changed = true;
02774f2d 700 e->callee->aux = (void *)1;
6eaf903b 701 }
702 }
02774f2d 703 order[i]->aux = NULL;
6eaf903b 704 }
705 }
706 free (order);
707 return 0;
708}
709
6eaf903b 710namespace {
711
712const pass_data pass_data_ipa_profile =
713{
714 IPA_PASS, /* type */
715 "profile_estimate", /* name */
716 OPTGROUP_NONE, /* optinfo_flags */
6eaf903b 717 TV_IPA_PROFILE, /* tv_id */
718 0, /* properties_required */
719 0, /* properties_provided */
720 0, /* properties_destroyed */
721 0, /* todo_flags_start */
722 0, /* todo_flags_finish */
723};
724
725class pass_ipa_profile : public ipa_opt_pass_d
726{
727public:
9af5ce0c 728 pass_ipa_profile (gcc::context *ctxt)
729 : ipa_opt_pass_d (pass_data_ipa_profile, ctxt,
730 ipa_profile_generate_summary, /* generate_summary */
731 ipa_profile_write_summary, /* write_summary */
732 ipa_profile_read_summary, /* read_summary */
733 NULL, /* write_optimization_summary */
734 NULL, /* read_optimization_summary */
735 NULL, /* stmt_fixup */
736 0, /* function_transform_todo_flags_start */
737 NULL, /* function_transform */
738 NULL) /* variable_transform */
6eaf903b 739 {}
740
741 /* opt_pass methods: */
31315c24 742 virtual bool gate (function *) { return flag_ipa_profile; }
65b0537f 743 virtual unsigned int execute (function *) { return ipa_profile (); }
6eaf903b 744
745}; // class pass_ipa_profile
746
747} // anon namespace
748
749ipa_opt_pass_d *
750make_pass_ipa_profile (gcc::context *ctxt)
751{
752 return new pass_ipa_profile (ctxt);
753}