Update to patch that Aldy committed directly here.
[official-gcc.git] / gcc / profile.c
blob8e887692c0dcb27e7fff35bd0244f640c8f1115f
1 /* Calculate branch probabilities, and basic block execution counts.
2 Copyright (C) 1990-2015 Free Software Foundation, Inc.
3 Contributed by James E. Wilson, UC Berkeley/Cygnus Support;
4 based on some ideas from Dain Samples of UC Berkeley.
5 Further mangling by Bob Manson, Cygnus Support.
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
12 version.
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 for more details.
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
23 /* Generate basic block profile instrumentation and auxiliary files.
24 Profile generation is optimized, so that not all arcs in the basic
25 block graph need instrumenting. First, the BB graph is closed with
26 one entry (function start), and one exit (function exit). Any
27 ABNORMAL_EDGE cannot be instrumented (because there is no control
28 path to place the code). We close the graph by inserting fake
29 EDGE_FAKE edges to the EXIT_BLOCK, from the sources of abnormal
30 edges that do not go to the exit_block. We ignore such abnormal
31 edges. Naturally these fake edges are never directly traversed,
32 and so *cannot* be directly instrumented. Some other graph
33 massaging is done. To optimize the instrumentation we generate the
34 BB minimal span tree, only edges that are not on the span tree
35 (plus the entry point) need instrumenting. From that information
36 all other edge counts can be deduced. By construction all fake
37 edges must be on the spanning tree. We also attempt to place
38 EDGE_CRITICAL edges on the spanning tree.
40 The auxiliary files generated are <dumpbase>.gcno (at compile time)
41 and <dumpbase>.gcda (at run time). The format is
42 described in full in gcov-io.h. */
44 /* ??? Register allocation should use basic block execution counts to
45 give preference to the most commonly executed blocks. */
47 /* ??? Should calculate branch probabilities before instrumenting code, since
48 then we can use arc counts to help decide which arcs to instrument. */
50 #include "config.h"
51 #include "system.h"
52 #include "coretypes.h"
53 #include "backend.h"
54 #include "cfghooks.h"
55 #include "tree.h"
56 #include "gimple.h"
57 #include "rtl.h"
58 #include "flags.h"
59 #include "regs.h"
60 #include "alias.h"
61 #include "insn-config.h"
62 #include "expmed.h"
63 #include "dojump.h"
64 #include "explow.h"
65 #include "calls.h"
66 #include "emit-rtl.h"
67 #include "varasm.h"
68 #include "stmt.h"
69 #include "expr.h"
70 #include "cfganal.h"
71 #include "diagnostic-core.h"
72 #include "coverage.h"
73 #include "value-prof.h"
74 #include "fold-const.h"
75 #include "internal-fn.h"
76 #include "gimple-iterator.h"
77 #include "tree-cfg.h"
78 #include "cfgloop.h"
79 #include "dumpfile.h"
80 #include "cgraph.h"
82 #include "profile.h"
84 struct bb_profile_info {
85 unsigned int count_valid : 1;
87 /* Number of successor and predecessor edges. */
88 gcov_type succ_count;
89 gcov_type pred_count;
92 #define BB_INFO(b) ((struct bb_profile_info *) (b)->aux)
95 /* Counter summary from the last set of coverage counts read. */
97 const struct gcov_ctr_summary *profile_info;
99 /* Counter working set information computed from the current counter
100 summary. Not initialized unless profile_info summary is non-NULL. */
101 static gcov_working_set_t gcov_working_sets[NUM_GCOV_WORKING_SETS];
103 /* Collect statistics on the performance of this pass for the entire source
104 file. */
106 static int total_num_blocks;
107 static int total_num_edges;
108 static int total_num_edges_ignored;
109 static int total_num_edges_instrumented;
110 static int total_num_blocks_created;
111 static int total_num_passes;
112 static int total_num_times_called;
113 static int total_hist_br_prob[20];
114 static int total_num_branches;
116 /* Helper function to update gcov_working_sets. */
118 void add_working_set (gcov_working_set_t *set) {
119 int i = 0;
120 for (; i < NUM_GCOV_WORKING_SETS; i++)
121 gcov_working_sets[i] = set[i];
124 /* Forward declarations. */
125 static void find_spanning_tree (struct edge_list *);
127 /* Add edge instrumentation code to the entire insn chain.
129 F is the first insn of the chain.
130 NUM_BLOCKS is the number of basic blocks found in F. */
132 static unsigned
133 instrument_edges (struct edge_list *el)
135 unsigned num_instr_edges = 0;
136 int num_edges = NUM_EDGES (el);
137 basic_block bb;
139 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun), NULL, next_bb)
141 edge e;
142 edge_iterator ei;
144 FOR_EACH_EDGE (e, ei, bb->succs)
146 struct edge_profile_info *inf = EDGE_INFO (e);
148 if (!inf->ignore && !inf->on_tree)
150 gcc_assert (!(e->flags & EDGE_ABNORMAL));
151 if (dump_file)
152 fprintf (dump_file, "Edge %d to %d instrumented%s\n",
153 e->src->index, e->dest->index,
154 EDGE_CRITICAL_P (e) ? " (and split)" : "");
155 gimple_gen_edge_profiler (num_instr_edges++, e);
160 total_num_blocks_created += num_edges;
161 if (dump_file)
162 fprintf (dump_file, "%d edges instrumented\n", num_instr_edges);
163 return num_instr_edges;
166 /* Add code to measure histograms for values in list VALUES. */
167 static void
168 instrument_values (histogram_values values)
170 unsigned i;
172 /* Emit code to generate the histograms before the insns. */
174 for (i = 0; i < values.length (); i++)
176 histogram_value hist = values[i];
177 unsigned t = COUNTER_FOR_HIST_TYPE (hist->type);
179 if (!coverage_counter_alloc (t, hist->n_counters))
180 continue;
182 switch (hist->type)
184 case HIST_TYPE_INTERVAL:
185 gimple_gen_interval_profiler (hist, t, 0);
186 break;
188 case HIST_TYPE_POW2:
189 gimple_gen_pow2_profiler (hist, t, 0);
190 break;
192 case HIST_TYPE_SINGLE_VALUE:
193 gimple_gen_one_value_profiler (hist, t, 0);
194 break;
196 case HIST_TYPE_CONST_DELTA:
197 gimple_gen_const_delta_profiler (hist, t, 0);
198 break;
200 case HIST_TYPE_INDIR_CALL:
201 case HIST_TYPE_INDIR_CALL_TOPN:
202 gimple_gen_ic_profiler (hist, t, 0);
203 break;
205 case HIST_TYPE_AVERAGE:
206 gimple_gen_average_profiler (hist, t, 0);
207 break;
209 case HIST_TYPE_IOR:
210 gimple_gen_ior_profiler (hist, t, 0);
211 break;
213 case HIST_TYPE_TIME_PROFILE:
215 basic_block bb =
216 split_edge (single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun)));
217 gimple_stmt_iterator gsi = gsi_start_bb (bb);
219 gimple_gen_time_profiler (t, 0, gsi);
220 break;
223 default:
224 gcc_unreachable ();
230 /* Fill the working set information into the profile_info structure. */
232 void
233 get_working_sets (void)
235 unsigned ws_ix, pctinc, pct;
236 gcov_working_set_t *ws_info;
238 if (!profile_info)
239 return;
241 compute_working_sets (profile_info, gcov_working_sets);
243 if (dump_file)
245 fprintf (dump_file, "Counter working sets:\n");
246 /* Multiply the percentage by 100 to avoid float. */
247 pctinc = 100 * 100 / NUM_GCOV_WORKING_SETS;
248 for (ws_ix = 0, pct = pctinc; ws_ix < NUM_GCOV_WORKING_SETS;
249 ws_ix++, pct += pctinc)
251 if (ws_ix == NUM_GCOV_WORKING_SETS - 1)
252 pct = 9990;
253 ws_info = &gcov_working_sets[ws_ix];
254 /* Print out the percentage using int arithmatic to avoid float. */
255 fprintf (dump_file, "\t\t%u.%02u%%: num counts=%u, min counter="
256 "%" PRId64 "\n",
257 pct / 100, pct - (pct / 100 * 100),
258 ws_info->num_counters,
259 (int64_t)ws_info->min_counter);
264 /* Given a the desired percentage of the full profile (sum_all from the
265 summary), multiplied by 10 to avoid float in PCT_TIMES_10, returns
266 the corresponding working set information. If an exact match for
267 the percentage isn't found, the closest value is used. */
269 gcov_working_set_t *
270 find_working_set (unsigned pct_times_10)
272 unsigned i;
273 if (!profile_info)
274 return NULL;
275 gcc_assert (pct_times_10 <= 1000);
276 if (pct_times_10 >= 999)
277 return &gcov_working_sets[NUM_GCOV_WORKING_SETS - 1];
278 i = pct_times_10 * NUM_GCOV_WORKING_SETS / 1000;
279 if (!i)
280 return &gcov_working_sets[0];
281 return &gcov_working_sets[i - 1];
284 /* Computes hybrid profile for all matching entries in da_file.
286 CFG_CHECKSUM is the precomputed checksum for the CFG. */
288 static gcov_type *
289 get_exec_counts (unsigned cfg_checksum, unsigned lineno_checksum)
291 unsigned num_edges = 0;
292 basic_block bb;
293 gcov_type *counts;
295 /* Count the edges to be (possibly) instrumented. */
296 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun), NULL, next_bb)
298 edge e;
299 edge_iterator ei;
301 FOR_EACH_EDGE (e, ei, bb->succs)
302 if (!EDGE_INFO (e)->ignore && !EDGE_INFO (e)->on_tree)
303 num_edges++;
306 counts = get_coverage_counts (GCOV_COUNTER_ARCS, num_edges, cfg_checksum,
307 lineno_checksum, &profile_info);
308 if (!counts)
309 return NULL;
311 get_working_sets ();
313 if (dump_file && profile_info)
314 fprintf (dump_file, "Merged %u profiles with maximal count %u.\n",
315 profile_info->runs, (unsigned) profile_info->sum_max);
317 return counts;
321 static bool
322 is_edge_inconsistent (vec<edge, va_gc> *edges)
324 edge e;
325 edge_iterator ei;
326 FOR_EACH_EDGE (e, ei, edges)
328 if (!EDGE_INFO (e)->ignore)
330 if (e->count < 0
331 && (!(e->flags & EDGE_FAKE)
332 || !block_ends_with_call_p (e->src)))
334 if (dump_file)
336 fprintf (dump_file,
337 "Edge %i->%i is inconsistent, count%" PRId64,
338 e->src->index, e->dest->index, e->count);
339 dump_bb (dump_file, e->src, 0, TDF_DETAILS);
340 dump_bb (dump_file, e->dest, 0, TDF_DETAILS);
342 return true;
346 return false;
349 static void
350 correct_negative_edge_counts (void)
352 basic_block bb;
353 edge e;
354 edge_iterator ei;
356 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun), NULL, next_bb)
358 FOR_EACH_EDGE (e, ei, bb->succs)
360 if (e->count < 0)
361 e->count = 0;
366 /* Check consistency.
367 Return true if inconsistency is found. */
368 static bool
369 is_inconsistent (void)
371 basic_block bb;
372 bool inconsistent = false;
373 FOR_EACH_BB_FN (bb, cfun)
375 inconsistent |= is_edge_inconsistent (bb->preds);
376 if (!dump_file && inconsistent)
377 return true;
378 inconsistent |= is_edge_inconsistent (bb->succs);
379 if (!dump_file && inconsistent)
380 return true;
381 if (bb->count < 0)
383 if (dump_file)
385 fprintf (dump_file, "BB %i count is negative "
386 "%" PRId64,
387 bb->index,
388 bb->count);
389 dump_bb (dump_file, bb, 0, TDF_DETAILS);
391 inconsistent = true;
393 if (bb->count != sum_edge_counts (bb->preds))
395 if (dump_file)
397 fprintf (dump_file, "BB %i count does not match sum of incoming edges "
398 "%" PRId64" should be %" PRId64,
399 bb->index,
400 bb->count,
401 sum_edge_counts (bb->preds));
402 dump_bb (dump_file, bb, 0, TDF_DETAILS);
404 inconsistent = true;
406 if (bb->count != sum_edge_counts (bb->succs) &&
407 ! (find_edge (bb, EXIT_BLOCK_PTR_FOR_FN (cfun)) != NULL
408 && block_ends_with_call_p (bb)))
410 if (dump_file)
412 fprintf (dump_file, "BB %i count does not match sum of outgoing edges "
413 "%" PRId64" should be %" PRId64,
414 bb->index,
415 bb->count,
416 sum_edge_counts (bb->succs));
417 dump_bb (dump_file, bb, 0, TDF_DETAILS);
419 inconsistent = true;
421 if (!dump_file && inconsistent)
422 return true;
425 return inconsistent;
428 /* Set each basic block count to the sum of its outgoing edge counts */
429 static void
430 set_bb_counts (void)
432 basic_block bb;
433 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun), NULL, next_bb)
435 bb->count = sum_edge_counts (bb->succs);
436 gcc_assert (bb->count >= 0);
440 /* Reads profile data and returns total number of edge counts read */
441 static int
442 read_profile_edge_counts (gcov_type *exec_counts)
444 basic_block bb;
445 int num_edges = 0;
446 int exec_counts_pos = 0;
447 /* For each edge not on the spanning tree, set its execution count from
448 the .da file. */
449 /* The first count in the .da file is the number of times that the function
450 was entered. This is the exec_count for block zero. */
452 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun), NULL, next_bb)
454 edge e;
455 edge_iterator ei;
457 FOR_EACH_EDGE (e, ei, bb->succs)
458 if (!EDGE_INFO (e)->ignore && !EDGE_INFO (e)->on_tree)
460 num_edges++;
461 if (exec_counts)
463 e->count = exec_counts[exec_counts_pos++];
464 if (e->count > profile_info->sum_max)
466 if (flag_profile_correction)
468 static bool informed = 0;
469 if (dump_enabled_p () && !informed)
470 dump_printf_loc (MSG_NOTE, input_location,
471 "corrupted profile info: edge count"
472 " exceeds maximal count\n");
473 informed = 1;
475 else
476 error ("corrupted profile info: edge from %i to %i exceeds maximal count",
477 bb->index, e->dest->index);
480 else
481 e->count = 0;
483 EDGE_INFO (e)->count_valid = 1;
484 BB_INFO (bb)->succ_count--;
485 BB_INFO (e->dest)->pred_count--;
486 if (dump_file)
488 fprintf (dump_file, "\nRead edge from %i to %i, count:",
489 bb->index, e->dest->index);
490 fprintf (dump_file, "%" PRId64,
491 (int64_t) e->count);
496 return num_edges;
499 #define OVERLAP_BASE 10000
501 /* Compare the static estimated profile to the actual profile, and
502 return the "degree of overlap" measure between them.
504 Degree of overlap is a number between 0 and OVERLAP_BASE. It is
505 the sum of each basic block's minimum relative weights between
506 two profiles. And overlap of OVERLAP_BASE means two profiles are
507 identical. */
509 static int
510 compute_frequency_overlap (void)
512 gcov_type count_total = 0, freq_total = 0;
513 int overlap = 0;
514 basic_block bb;
516 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun), NULL, next_bb)
518 count_total += bb->count;
519 freq_total += bb->frequency;
522 if (count_total == 0 || freq_total == 0)
523 return 0;
525 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun), NULL, next_bb)
526 overlap += MIN (bb->count * OVERLAP_BASE / count_total,
527 bb->frequency * OVERLAP_BASE / freq_total);
529 return overlap;
532 /* Compute the branch probabilities for the various branches.
533 Annotate them accordingly.
535 CFG_CHECKSUM is the precomputed checksum for the CFG. */
537 static void
538 compute_branch_probabilities (unsigned cfg_checksum, unsigned lineno_checksum)
540 basic_block bb;
541 int i;
542 int num_edges = 0;
543 int changes;
544 int passes;
545 int hist_br_prob[20];
546 int num_branches;
547 gcov_type *exec_counts = get_exec_counts (cfg_checksum, lineno_checksum);
548 int inconsistent = 0;
550 /* Very simple sanity checks so we catch bugs in our profiling code. */
551 if (!profile_info)
552 return;
554 if (profile_info->sum_all < profile_info->sum_max)
556 error ("corrupted profile info: sum_all is smaller than sum_max");
557 exec_counts = NULL;
560 /* Attach extra info block to each bb. */
561 alloc_aux_for_blocks (sizeof (struct bb_profile_info));
562 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun), NULL, next_bb)
564 edge e;
565 edge_iterator ei;
567 FOR_EACH_EDGE (e, ei, bb->succs)
568 if (!EDGE_INFO (e)->ignore)
569 BB_INFO (bb)->succ_count++;
570 FOR_EACH_EDGE (e, ei, bb->preds)
571 if (!EDGE_INFO (e)->ignore)
572 BB_INFO (bb)->pred_count++;
575 /* Avoid predicting entry on exit nodes. */
576 BB_INFO (EXIT_BLOCK_PTR_FOR_FN (cfun))->succ_count = 2;
577 BB_INFO (ENTRY_BLOCK_PTR_FOR_FN (cfun))->pred_count = 2;
579 num_edges = read_profile_edge_counts (exec_counts);
581 if (dump_file)
582 fprintf (dump_file, "\n%d edge counts read\n", num_edges);
584 /* For every block in the file,
585 - if every exit/entrance edge has a known count, then set the block count
586 - if the block count is known, and every exit/entrance edge but one has
587 a known execution count, then set the count of the remaining edge
589 As edge counts are set, decrement the succ/pred count, but don't delete
590 the edge, that way we can easily tell when all edges are known, or only
591 one edge is unknown. */
593 /* The order that the basic blocks are iterated through is important.
594 Since the code that finds spanning trees starts with block 0, low numbered
595 edges are put on the spanning tree in preference to high numbered edges.
596 Hence, most instrumented edges are at the end. Graph solving works much
597 faster if we propagate numbers from the end to the start.
599 This takes an average of slightly more than 3 passes. */
601 changes = 1;
602 passes = 0;
603 while (changes)
605 passes++;
606 changes = 0;
607 FOR_BB_BETWEEN (bb, EXIT_BLOCK_PTR_FOR_FN (cfun), NULL, prev_bb)
609 struct bb_profile_info *bi = BB_INFO (bb);
610 if (! bi->count_valid)
612 if (bi->succ_count == 0)
614 edge e;
615 edge_iterator ei;
616 gcov_type total = 0;
618 FOR_EACH_EDGE (e, ei, bb->succs)
619 total += e->count;
620 bb->count = total;
621 bi->count_valid = 1;
622 changes = 1;
624 else if (bi->pred_count == 0)
626 edge e;
627 edge_iterator ei;
628 gcov_type total = 0;
630 FOR_EACH_EDGE (e, ei, bb->preds)
631 total += e->count;
632 bb->count = total;
633 bi->count_valid = 1;
634 changes = 1;
637 if (bi->count_valid)
639 if (bi->succ_count == 1)
641 edge e;
642 edge_iterator ei;
643 gcov_type total = 0;
645 /* One of the counts will be invalid, but it is zero,
646 so adding it in also doesn't hurt. */
647 FOR_EACH_EDGE (e, ei, bb->succs)
648 total += e->count;
650 /* Search for the invalid edge, and set its count. */
651 FOR_EACH_EDGE (e, ei, bb->succs)
652 if (! EDGE_INFO (e)->count_valid && ! EDGE_INFO (e)->ignore)
653 break;
655 /* Calculate count for remaining edge by conservation. */
656 total = bb->count - total;
658 gcc_assert (e);
659 EDGE_INFO (e)->count_valid = 1;
660 e->count = total;
661 bi->succ_count--;
663 BB_INFO (e->dest)->pred_count--;
664 changes = 1;
666 if (bi->pred_count == 1)
668 edge e;
669 edge_iterator ei;
670 gcov_type total = 0;
672 /* One of the counts will be invalid, but it is zero,
673 so adding it in also doesn't hurt. */
674 FOR_EACH_EDGE (e, ei, bb->preds)
675 total += e->count;
677 /* Search for the invalid edge, and set its count. */
678 FOR_EACH_EDGE (e, ei, bb->preds)
679 if (!EDGE_INFO (e)->count_valid && !EDGE_INFO (e)->ignore)
680 break;
682 /* Calculate count for remaining edge by conservation. */
683 total = bb->count - total + e->count;
685 gcc_assert (e);
686 EDGE_INFO (e)->count_valid = 1;
687 e->count = total;
688 bi->pred_count--;
690 BB_INFO (e->src)->succ_count--;
691 changes = 1;
696 if (dump_file)
698 int overlap = compute_frequency_overlap ();
699 gimple_dump_cfg (dump_file, dump_flags);
700 fprintf (dump_file, "Static profile overlap: %d.%d%%\n",
701 overlap / (OVERLAP_BASE / 100),
702 overlap % (OVERLAP_BASE / 100));
705 total_num_passes += passes;
706 if (dump_file)
707 fprintf (dump_file, "Graph solving took %d passes.\n\n", passes);
709 /* If the graph has been correctly solved, every block will have a
710 succ and pred count of zero. */
711 FOR_EACH_BB_FN (bb, cfun)
713 gcc_assert (!BB_INFO (bb)->succ_count && !BB_INFO (bb)->pred_count);
716 /* Check for inconsistent basic block counts */
717 inconsistent = is_inconsistent ();
719 if (inconsistent)
721 if (flag_profile_correction)
723 /* Inconsistency detected. Make it flow-consistent. */
724 static int informed = 0;
725 if (dump_enabled_p () && informed == 0)
727 informed = 1;
728 dump_printf_loc (MSG_NOTE, input_location,
729 "correcting inconsistent profile data\n");
731 correct_negative_edge_counts ();
732 /* Set bb counts to the sum of the outgoing edge counts */
733 set_bb_counts ();
734 if (dump_file)
735 fprintf (dump_file, "\nCalling mcf_smooth_cfg\n");
736 mcf_smooth_cfg ();
738 else
739 error ("corrupted profile info: profile data is not flow-consistent");
742 /* For every edge, calculate its branch probability and add a reg_note
743 to the branch insn to indicate this. */
745 for (i = 0; i < 20; i++)
746 hist_br_prob[i] = 0;
747 num_branches = 0;
749 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun), NULL, next_bb)
751 edge e;
752 edge_iterator ei;
754 if (bb->count < 0)
756 error ("corrupted profile info: number of iterations for basic block %d thought to be %i",
757 bb->index, (int)bb->count);
758 bb->count = 0;
760 FOR_EACH_EDGE (e, ei, bb->succs)
762 /* Function may return twice in the cased the called function is
763 setjmp or calls fork, but we can't represent this by extra
764 edge from the entry, since extra edge from the exit is
765 already present. We get negative frequency from the entry
766 point. */
767 if ((e->count < 0
768 && e->dest == EXIT_BLOCK_PTR_FOR_FN (cfun))
769 || (e->count > bb->count
770 && e->dest != EXIT_BLOCK_PTR_FOR_FN (cfun)))
772 if (block_ends_with_call_p (bb))
773 e->count = e->count < 0 ? 0 : bb->count;
775 if (e->count < 0 || e->count > bb->count)
777 error ("corrupted profile info: number of executions for edge %d-%d thought to be %i",
778 e->src->index, e->dest->index,
779 (int)e->count);
780 e->count = bb->count / 2;
783 if (bb->count)
785 FOR_EACH_EDGE (e, ei, bb->succs)
786 e->probability = GCOV_COMPUTE_SCALE (e->count, bb->count);
787 if (bb->index >= NUM_FIXED_BLOCKS
788 && block_ends_with_condjump_p (bb)
789 && EDGE_COUNT (bb->succs) >= 2)
791 int prob;
792 edge e;
793 int index;
795 /* Find the branch edge. It is possible that we do have fake
796 edges here. */
797 FOR_EACH_EDGE (e, ei, bb->succs)
798 if (!(e->flags & (EDGE_FAKE | EDGE_FALLTHRU)))
799 break;
801 prob = e->probability;
802 index = prob * 20 / REG_BR_PROB_BASE;
804 if (index == 20)
805 index = 19;
806 hist_br_prob[index]++;
808 num_branches++;
811 /* As a last resort, distribute the probabilities evenly.
812 Use simple heuristics that if there are normal edges,
813 give all abnormals frequency of 0, otherwise distribute the
814 frequency over abnormals (this is the case of noreturn
815 calls). */
816 else if (profile_status_for_fn (cfun) == PROFILE_ABSENT)
818 int total = 0;
820 FOR_EACH_EDGE (e, ei, bb->succs)
821 if (!(e->flags & (EDGE_COMPLEX | EDGE_FAKE)))
822 total ++;
823 if (total)
825 FOR_EACH_EDGE (e, ei, bb->succs)
826 if (!(e->flags & (EDGE_COMPLEX | EDGE_FAKE)))
827 e->probability = REG_BR_PROB_BASE / total;
828 else
829 e->probability = 0;
831 else
833 total += EDGE_COUNT (bb->succs);
834 FOR_EACH_EDGE (e, ei, bb->succs)
835 e->probability = REG_BR_PROB_BASE / total;
837 if (bb->index >= NUM_FIXED_BLOCKS
838 && block_ends_with_condjump_p (bb)
839 && EDGE_COUNT (bb->succs) >= 2)
840 num_branches++;
843 counts_to_freqs ();
844 profile_status_for_fn (cfun) = PROFILE_READ;
845 compute_function_frequency ();
847 if (dump_file)
849 fprintf (dump_file, "%d branches\n", num_branches);
850 if (num_branches)
851 for (i = 0; i < 10; i++)
852 fprintf (dump_file, "%d%% branches in range %d-%d%%\n",
853 (hist_br_prob[i] + hist_br_prob[19-i]) * 100 / num_branches,
854 5 * i, 5 * i + 5);
856 total_num_branches += num_branches;
857 for (i = 0; i < 20; i++)
858 total_hist_br_prob[i] += hist_br_prob[i];
860 fputc ('\n', dump_file);
861 fputc ('\n', dump_file);
864 free_aux_for_blocks ();
867 /* Load value histograms values whose description is stored in VALUES array
868 from .gcda file.
870 CFG_CHECKSUM is the precomputed checksum for the CFG. */
872 static void
873 compute_value_histograms (histogram_values values, unsigned cfg_checksum,
874 unsigned lineno_checksum)
876 unsigned i, j, t, any;
877 unsigned n_histogram_counters[GCOV_N_VALUE_COUNTERS];
878 gcov_type *histogram_counts[GCOV_N_VALUE_COUNTERS];
879 gcov_type *act_count[GCOV_N_VALUE_COUNTERS];
880 gcov_type *aact_count;
881 struct cgraph_node *node;
883 for (t = 0; t < GCOV_N_VALUE_COUNTERS; t++)
884 n_histogram_counters[t] = 0;
886 for (i = 0; i < values.length (); i++)
888 histogram_value hist = values[i];
889 n_histogram_counters[(int) hist->type] += hist->n_counters;
892 any = 0;
893 for (t = 0; t < GCOV_N_VALUE_COUNTERS; t++)
895 if (!n_histogram_counters[t])
897 histogram_counts[t] = NULL;
898 continue;
901 histogram_counts[t] =
902 get_coverage_counts (COUNTER_FOR_HIST_TYPE (t),
903 n_histogram_counters[t], cfg_checksum,
904 lineno_checksum, NULL);
905 if (histogram_counts[t])
906 any = 1;
907 act_count[t] = histogram_counts[t];
909 if (!any)
910 return;
912 for (i = 0; i < values.length (); i++)
914 histogram_value hist = values[i];
915 gimple stmt = hist->hvalue.stmt;
917 t = (int) hist->type;
919 aact_count = act_count[t];
921 if (act_count[t])
922 act_count[t] += hist->n_counters;
924 gimple_add_histogram_value (cfun, stmt, hist);
925 hist->hvalue.counters = XNEWVEC (gcov_type, hist->n_counters);
926 for (j = 0; j < hist->n_counters; j++)
927 if (aact_count)
928 hist->hvalue.counters[j] = aact_count[j];
929 else
930 hist->hvalue.counters[j] = 0;
932 /* Time profiler counter is not related to any statement,
933 so that we have to read the counter and set the value to
934 the corresponding call graph node. */
935 if (hist->type == HIST_TYPE_TIME_PROFILE)
937 node = cgraph_node::get (hist->fun->decl);
938 node->tp_first_run = hist->hvalue.counters[0];
940 if (dump_file)
941 fprintf (dump_file, "Read tp_first_run: %d\n", node->tp_first_run);
945 for (t = 0; t < GCOV_N_VALUE_COUNTERS; t++)
946 free (histogram_counts[t]);
949 /* When passed NULL as file_name, initialize.
950 When passed something else, output the necessary commands to change
951 line to LINE and offset to FILE_NAME. */
952 static void
953 output_location (char const *file_name, int line,
954 gcov_position_t *offset, basic_block bb)
956 static char const *prev_file_name;
957 static int prev_line;
958 bool name_differs, line_differs;
960 if (!file_name)
962 prev_file_name = NULL;
963 prev_line = -1;
964 return;
967 name_differs = !prev_file_name || filename_cmp (file_name, prev_file_name);
968 line_differs = prev_line != line;
970 if (name_differs || line_differs)
972 if (!*offset)
974 *offset = gcov_write_tag (GCOV_TAG_LINES);
975 gcov_write_unsigned (bb->index);
976 name_differs = line_differs=true;
979 /* If this is a new source file, then output the
980 file's name to the .bb file. */
981 if (name_differs)
983 prev_file_name = file_name;
984 gcov_write_unsigned (0);
985 gcov_write_string (prev_file_name);
987 if (line_differs)
989 gcov_write_unsigned (line);
990 prev_line = line;
995 /* Instrument and/or analyze program behavior based on program the CFG.
997 This function creates a representation of the control flow graph (of
998 the function being compiled) that is suitable for the instrumentation
999 of edges and/or converting measured edge counts to counts on the
1000 complete CFG.
1002 When FLAG_PROFILE_ARCS is nonzero, this function instruments the edges in
1003 the flow graph that are needed to reconstruct the dynamic behavior of the
1004 flow graph. This data is written to the gcno file for gcov.
1006 When FLAG_BRANCH_PROBABILITIES is nonzero, this function reads auxiliary
1007 information from the gcda file containing edge count information from
1008 previous executions of the function being compiled. In this case, the
1009 control flow graph is annotated with actual execution counts by
1010 compute_branch_probabilities().
1012 Main entry point of this file. */
1014 void
1015 branch_prob (void)
1017 basic_block bb;
1018 unsigned i;
1019 unsigned num_edges, ignored_edges;
1020 unsigned num_instrumented;
1021 struct edge_list *el;
1022 histogram_values values = histogram_values ();
1023 unsigned cfg_checksum, lineno_checksum;
1025 total_num_times_called++;
1027 flow_call_edges_add (NULL);
1028 add_noreturn_fake_exit_edges ();
1030 /* We can't handle cyclic regions constructed using abnormal edges.
1031 To avoid these we replace every source of abnormal edge by a fake
1032 edge from entry node and every destination by fake edge to exit.
1033 This keeps graph acyclic and our calculation exact for all normal
1034 edges except for exit and entrance ones.
1036 We also add fake exit edges for each call and asm statement in the
1037 basic, since it may not return. */
1039 FOR_EACH_BB_FN (bb, cfun)
1041 int need_exit_edge = 0, need_entry_edge = 0;
1042 int have_exit_edge = 0, have_entry_edge = 0;
1043 edge e;
1044 edge_iterator ei;
1046 /* Functions returning multiple times are not handled by extra edges.
1047 Instead we simply allow negative counts on edges from exit to the
1048 block past call and corresponding probabilities. We can't go
1049 with the extra edges because that would result in flowgraph that
1050 needs to have fake edges outside the spanning tree. */
1052 FOR_EACH_EDGE (e, ei, bb->succs)
1054 gimple_stmt_iterator gsi;
1055 gimple last = NULL;
1057 /* It may happen that there are compiler generated statements
1058 without a locus at all. Go through the basic block from the
1059 last to the first statement looking for a locus. */
1060 for (gsi = gsi_last_nondebug_bb (bb);
1061 !gsi_end_p (gsi);
1062 gsi_prev_nondebug (&gsi))
1064 last = gsi_stmt (gsi);
1065 if (gimple_has_location (last))
1066 break;
1069 /* Edge with goto locus might get wrong coverage info unless
1070 it is the only edge out of BB.
1071 Don't do that when the locuses match, so
1072 if (blah) goto something;
1073 is not computed twice. */
1074 if (last
1075 && gimple_has_location (last)
1076 && LOCATION_LOCUS (e->goto_locus) != UNKNOWN_LOCATION
1077 && !single_succ_p (bb)
1078 && (LOCATION_FILE (e->goto_locus)
1079 != LOCATION_FILE (gimple_location (last))
1080 || (LOCATION_LINE (e->goto_locus)
1081 != LOCATION_LINE (gimple_location (last)))))
1083 basic_block new_bb = split_edge (e);
1084 edge ne = single_succ_edge (new_bb);
1085 ne->goto_locus = e->goto_locus;
1087 if ((e->flags & (EDGE_ABNORMAL | EDGE_ABNORMAL_CALL))
1088 && e->dest != EXIT_BLOCK_PTR_FOR_FN (cfun))
1089 need_exit_edge = 1;
1090 if (e->dest == EXIT_BLOCK_PTR_FOR_FN (cfun))
1091 have_exit_edge = 1;
1093 FOR_EACH_EDGE (e, ei, bb->preds)
1095 if ((e->flags & (EDGE_ABNORMAL | EDGE_ABNORMAL_CALL))
1096 && e->src != ENTRY_BLOCK_PTR_FOR_FN (cfun))
1097 need_entry_edge = 1;
1098 if (e->src == ENTRY_BLOCK_PTR_FOR_FN (cfun))
1099 have_entry_edge = 1;
1102 if (need_exit_edge && !have_exit_edge)
1104 if (dump_file)
1105 fprintf (dump_file, "Adding fake exit edge to bb %i\n",
1106 bb->index);
1107 make_edge (bb, EXIT_BLOCK_PTR_FOR_FN (cfun), EDGE_FAKE);
1109 if (need_entry_edge && !have_entry_edge)
1111 if (dump_file)
1112 fprintf (dump_file, "Adding fake entry edge to bb %i\n",
1113 bb->index);
1114 make_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun), bb, EDGE_FAKE);
1115 /* Avoid bbs that have both fake entry edge and also some
1116 exit edge. One of those edges wouldn't be added to the
1117 spanning tree, but we can't instrument any of them. */
1118 if (have_exit_edge || need_exit_edge)
1120 gimple_stmt_iterator gsi;
1121 gimple first;
1123 gsi = gsi_start_nondebug_after_labels_bb (bb);
1124 gcc_checking_assert (!gsi_end_p (gsi));
1125 first = gsi_stmt (gsi);
1126 /* Don't split the bbs containing __builtin_setjmp_receiver
1127 or ABNORMAL_DISPATCHER calls. These are very
1128 special and don't expect anything to be inserted before
1129 them. */
1130 if (is_gimple_call (first)
1131 && (gimple_call_builtin_p (first, BUILT_IN_SETJMP_RECEIVER)
1132 || (gimple_call_flags (first) & ECF_RETURNS_TWICE)
1133 || (gimple_call_internal_p (first)
1134 && (gimple_call_internal_fn (first)
1135 == IFN_ABNORMAL_DISPATCHER))))
1136 continue;
1138 if (dump_file)
1139 fprintf (dump_file, "Splitting bb %i after labels\n",
1140 bb->index);
1141 split_block_after_labels (bb);
1146 el = create_edge_list ();
1147 num_edges = NUM_EDGES (el);
1148 alloc_aux_for_edges (sizeof (struct edge_profile_info));
1150 /* The basic blocks are expected to be numbered sequentially. */
1151 compact_blocks ();
1153 ignored_edges = 0;
1154 for (i = 0 ; i < num_edges ; i++)
1156 edge e = INDEX_EDGE (el, i);
1157 e->count = 0;
1159 /* Mark edges we've replaced by fake edges above as ignored. */
1160 if ((e->flags & (EDGE_ABNORMAL | EDGE_ABNORMAL_CALL))
1161 && e->src != ENTRY_BLOCK_PTR_FOR_FN (cfun)
1162 && e->dest != EXIT_BLOCK_PTR_FOR_FN (cfun))
1164 EDGE_INFO (e)->ignore = 1;
1165 ignored_edges++;
1169 /* Create spanning tree from basic block graph, mark each edge that is
1170 on the spanning tree. We insert as many abnormal and critical edges
1171 as possible to minimize number of edge splits necessary. */
1173 find_spanning_tree (el);
1175 /* Fake edges that are not on the tree will not be instrumented, so
1176 mark them ignored. */
1177 for (num_instrumented = i = 0; i < num_edges; i++)
1179 edge e = INDEX_EDGE (el, i);
1180 struct edge_profile_info *inf = EDGE_INFO (e);
1182 if (inf->ignore || inf->on_tree)
1183 /*NOP*/;
1184 else if (e->flags & EDGE_FAKE)
1186 inf->ignore = 1;
1187 ignored_edges++;
1189 else
1190 num_instrumented++;
1193 total_num_blocks += n_basic_blocks_for_fn (cfun);
1194 if (dump_file)
1195 fprintf (dump_file, "%d basic blocks\n", n_basic_blocks_for_fn (cfun));
1197 total_num_edges += num_edges;
1198 if (dump_file)
1199 fprintf (dump_file, "%d edges\n", num_edges);
1201 total_num_edges_ignored += ignored_edges;
1202 if (dump_file)
1203 fprintf (dump_file, "%d ignored edges\n", ignored_edges);
1205 total_num_edges_instrumented += num_instrumented;
1206 if (dump_file)
1207 fprintf (dump_file, "%d instrumentation edges\n", num_instrumented);
1209 /* Compute two different checksums. Note that we want to compute
1210 the checksum in only once place, since it depends on the shape
1211 of the control flow which can change during
1212 various transformations. */
1213 cfg_checksum = coverage_compute_cfg_checksum (cfun);
1214 lineno_checksum = coverage_compute_lineno_checksum ();
1216 /* Write the data from which gcov can reconstruct the basic block
1217 graph and function line numbers (the gcno file). */
1218 if (coverage_begin_function (lineno_checksum, cfg_checksum))
1220 gcov_position_t offset;
1222 /* Basic block flags */
1223 offset = gcov_write_tag (GCOV_TAG_BLOCKS);
1224 for (i = 0; i != (unsigned) (n_basic_blocks_for_fn (cfun)); i++)
1225 gcov_write_unsigned (0);
1226 gcov_write_length (offset);
1228 /* Arcs */
1229 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun),
1230 EXIT_BLOCK_PTR_FOR_FN (cfun), next_bb)
1232 edge e;
1233 edge_iterator ei;
1235 offset = gcov_write_tag (GCOV_TAG_ARCS);
1236 gcov_write_unsigned (bb->index);
1238 FOR_EACH_EDGE (e, ei, bb->succs)
1240 struct edge_profile_info *i = EDGE_INFO (e);
1241 if (!i->ignore)
1243 unsigned flag_bits = 0;
1245 if (i->on_tree)
1246 flag_bits |= GCOV_ARC_ON_TREE;
1247 if (e->flags & EDGE_FAKE)
1248 flag_bits |= GCOV_ARC_FAKE;
1249 if (e->flags & EDGE_FALLTHRU)
1250 flag_bits |= GCOV_ARC_FALLTHROUGH;
1251 /* On trees we don't have fallthru flags, but we can
1252 recompute them from CFG shape. */
1253 if (e->flags & (EDGE_TRUE_VALUE | EDGE_FALSE_VALUE)
1254 && e->src->next_bb == e->dest)
1255 flag_bits |= GCOV_ARC_FALLTHROUGH;
1257 gcov_write_unsigned (e->dest->index);
1258 gcov_write_unsigned (flag_bits);
1262 gcov_write_length (offset);
1265 /* Line numbers. */
1266 /* Initialize the output. */
1267 output_location (NULL, 0, NULL, NULL);
1269 FOR_EACH_BB_FN (bb, cfun)
1271 gimple_stmt_iterator gsi;
1272 gcov_position_t offset = 0;
1274 if (bb == ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb)
1276 expanded_location curr_location =
1277 expand_location (DECL_SOURCE_LOCATION (current_function_decl));
1278 output_location (curr_location.file, curr_location.line,
1279 &offset, bb);
1282 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1284 gimple stmt = gsi_stmt (gsi);
1285 if (gimple_has_location (stmt))
1286 output_location (gimple_filename (stmt), gimple_lineno (stmt),
1287 &offset, bb);
1290 /* Notice GOTO expressions eliminated while constructing the CFG. */
1291 if (single_succ_p (bb)
1292 && LOCATION_LOCUS (single_succ_edge (bb)->goto_locus)
1293 != UNKNOWN_LOCATION)
1295 expanded_location curr_location
1296 = expand_location (single_succ_edge (bb)->goto_locus);
1297 output_location (curr_location.file, curr_location.line,
1298 &offset, bb);
1301 if (offset)
1303 /* A file of NULL indicates the end of run. */
1304 gcov_write_unsigned (0);
1305 gcov_write_string (NULL);
1306 gcov_write_length (offset);
1311 if (flag_profile_values)
1312 gimple_find_values_to_profile (&values);
1314 if (flag_branch_probabilities)
1316 compute_branch_probabilities (cfg_checksum, lineno_checksum);
1317 if (flag_profile_values)
1318 compute_value_histograms (values, cfg_checksum, lineno_checksum);
1321 remove_fake_edges ();
1323 /* For each edge not on the spanning tree, add counting code. */
1324 if (profile_arc_flag
1325 && coverage_counter_alloc (GCOV_COUNTER_ARCS, num_instrumented))
1327 unsigned n_instrumented;
1329 gimple_init_edge_profiler ();
1331 n_instrumented = instrument_edges (el);
1333 gcc_assert (n_instrumented == num_instrumented);
1335 if (flag_profile_values)
1336 instrument_values (values);
1338 /* Commit changes done by instrumentation. */
1339 gsi_commit_edge_inserts ();
1342 free_aux_for_edges ();
1344 values.release ();
1345 free_edge_list (el);
1346 coverage_end_function (lineno_checksum, cfg_checksum);
1349 /* Union find algorithm implementation for the basic blocks using
1350 aux fields. */
1352 static basic_block
1353 find_group (basic_block bb)
1355 basic_block group = bb, bb1;
1357 while ((basic_block) group->aux != group)
1358 group = (basic_block) group->aux;
1360 /* Compress path. */
1361 while ((basic_block) bb->aux != group)
1363 bb1 = (basic_block) bb->aux;
1364 bb->aux = (void *) group;
1365 bb = bb1;
1367 return group;
1370 static void
1371 union_groups (basic_block bb1, basic_block bb2)
1373 basic_block bb1g = find_group (bb1);
1374 basic_block bb2g = find_group (bb2);
1376 /* ??? I don't have a place for the rank field. OK. Lets go w/o it,
1377 this code is unlikely going to be performance problem anyway. */
1378 gcc_assert (bb1g != bb2g);
1380 bb1g->aux = bb2g;
1383 /* This function searches all of the edges in the program flow graph, and puts
1384 as many bad edges as possible onto the spanning tree. Bad edges include
1385 abnormals edges, which can't be instrumented at the moment. Since it is
1386 possible for fake edges to form a cycle, we will have to develop some
1387 better way in the future. Also put critical edges to the tree, since they
1388 are more expensive to instrument. */
1390 static void
1391 find_spanning_tree (struct edge_list *el)
1393 int i;
1394 int num_edges = NUM_EDGES (el);
1395 basic_block bb;
1397 /* We use aux field for standard union-find algorithm. */
1398 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun), NULL, next_bb)
1399 bb->aux = bb;
1401 /* Add fake edge exit to entry we can't instrument. */
1402 union_groups (EXIT_BLOCK_PTR_FOR_FN (cfun), ENTRY_BLOCK_PTR_FOR_FN (cfun));
1404 /* First add all abnormal edges to the tree unless they form a cycle. Also
1405 add all edges to the exit block to avoid inserting profiling code behind
1406 setting return value from function. */
1407 for (i = 0; i < num_edges; i++)
1409 edge e = INDEX_EDGE (el, i);
1410 if (((e->flags & (EDGE_ABNORMAL | EDGE_ABNORMAL_CALL | EDGE_FAKE))
1411 || e->dest == EXIT_BLOCK_PTR_FOR_FN (cfun))
1412 && !EDGE_INFO (e)->ignore
1413 && (find_group (e->src) != find_group (e->dest)))
1415 if (dump_file)
1416 fprintf (dump_file, "Abnormal edge %d to %d put to tree\n",
1417 e->src->index, e->dest->index);
1418 EDGE_INFO (e)->on_tree = 1;
1419 union_groups (e->src, e->dest);
1423 /* Now insert all critical edges to the tree unless they form a cycle. */
1424 for (i = 0; i < num_edges; i++)
1426 edge e = INDEX_EDGE (el, i);
1427 if (EDGE_CRITICAL_P (e) && !EDGE_INFO (e)->ignore
1428 && find_group (e->src) != find_group (e->dest))
1430 if (dump_file)
1431 fprintf (dump_file, "Critical edge %d to %d put to tree\n",
1432 e->src->index, e->dest->index);
1433 EDGE_INFO (e)->on_tree = 1;
1434 union_groups (e->src, e->dest);
1438 /* And now the rest. */
1439 for (i = 0; i < num_edges; i++)
1441 edge e = INDEX_EDGE (el, i);
1442 if (!EDGE_INFO (e)->ignore
1443 && find_group (e->src) != find_group (e->dest))
1445 if (dump_file)
1446 fprintf (dump_file, "Normal edge %d to %d put to tree\n",
1447 e->src->index, e->dest->index);
1448 EDGE_INFO (e)->on_tree = 1;
1449 union_groups (e->src, e->dest);
1453 clear_aux_for_blocks ();
1456 /* Perform file-level initialization for branch-prob processing. */
1458 void
1459 init_branch_prob (void)
1461 int i;
1463 total_num_blocks = 0;
1464 total_num_edges = 0;
1465 total_num_edges_ignored = 0;
1466 total_num_edges_instrumented = 0;
1467 total_num_blocks_created = 0;
1468 total_num_passes = 0;
1469 total_num_times_called = 0;
1470 total_num_branches = 0;
1471 for (i = 0; i < 20; i++)
1472 total_hist_br_prob[i] = 0;
1475 /* Performs file-level cleanup after branch-prob processing
1476 is completed. */
1478 void
1479 end_branch_prob (void)
1481 if (dump_file)
1483 fprintf (dump_file, "\n");
1484 fprintf (dump_file, "Total number of blocks: %d\n",
1485 total_num_blocks);
1486 fprintf (dump_file, "Total number of edges: %d\n", total_num_edges);
1487 fprintf (dump_file, "Total number of ignored edges: %d\n",
1488 total_num_edges_ignored);
1489 fprintf (dump_file, "Total number of instrumented edges: %d\n",
1490 total_num_edges_instrumented);
1491 fprintf (dump_file, "Total number of blocks created: %d\n",
1492 total_num_blocks_created);
1493 fprintf (dump_file, "Total number of graph solution passes: %d\n",
1494 total_num_passes);
1495 if (total_num_times_called != 0)
1496 fprintf (dump_file, "Average number of graph solution passes: %d\n",
1497 (total_num_passes + (total_num_times_called >> 1))
1498 / total_num_times_called);
1499 fprintf (dump_file, "Total number of branches: %d\n",
1500 total_num_branches);
1501 if (total_num_branches)
1503 int i;
1505 for (i = 0; i < 10; i++)
1506 fprintf (dump_file, "%d%% branches in range %d-%d%%\n",
1507 (total_hist_br_prob[i] + total_hist_br_prob[19-i]) * 100
1508 / total_num_branches, 5*i, 5*i+5);