output.h (__gcc_host_wide_int__): Move to hwint.h.
[gcc.git] / gcc / profile.c
1 /* Calculate branch probabilities, and basic block execution counts.
2 Copyright (C) 1990, 1991, 1992, 1993, 1994, 1996, 1997, 1998, 1999,
3 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011, 2012
4 Free Software Foundation, Inc.
5 Contributed by James E. Wilson, UC Berkeley/Cygnus Support;
6 based on some ideas from Dain Samples of UC Berkeley.
7 Further mangling by Bob Manson, Cygnus Support.
8
9 This file is part of GCC.
10
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
14 version.
15
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
24
25 /* Generate basic block profile instrumentation and auxiliary files.
26 Profile generation is optimized, so that not all arcs in the basic
27 block graph need instrumenting. First, the BB graph is closed with
28 one entry (function start), and one exit (function exit). Any
29 ABNORMAL_EDGE cannot be instrumented (because there is no control
30 path to place the code). We close the graph by inserting fake
31 EDGE_FAKE edges to the EXIT_BLOCK, from the sources of abnormal
32 edges that do not go to the exit_block. We ignore such abnormal
33 edges. Naturally these fake edges are never directly traversed,
34 and so *cannot* be directly instrumented. Some other graph
35 massaging is done. To optimize the instrumentation we generate the
36 BB minimal span tree, only edges that are not on the span tree
37 (plus the entry point) need instrumenting. From that information
38 all other edge counts can be deduced. By construction all fake
39 edges must be on the spanning tree. We also attempt to place
40 EDGE_CRITICAL edges on the spanning tree.
41
42 The auxiliary files generated are <dumpbase>.gcno (at compile time)
43 and <dumpbase>.gcda (at run time). The format is
44 described in full in gcov-io.h. */
45
46 /* ??? Register allocation should use basic block execution counts to
47 give preference to the most commonly executed blocks. */
48
49 /* ??? Should calculate branch probabilities before instrumenting code, since
50 then we can use arc counts to help decide which arcs to instrument. */
51
52 #include "config.h"
53 #include "system.h"
54 #include "coretypes.h"
55 #include "tm.h"
56 #include "rtl.h"
57 #include "flags.h"
58 #include "regs.h"
59 #include "expr.h"
60 #include "function.h"
61 #include "basic-block.h"
62 #include "diagnostic-core.h"
63 #include "coverage.h"
64 #include "value-prof.h"
65 #include "tree.h"
66 #include "cfghooks.h"
67 #include "tree-flow.h"
68 #include "timevar.h"
69 #include "cfgloop.h"
70 #include "tree-pass.h"
71
72 #include "profile.h"
73
74 struct bb_info {
75 unsigned int count_valid : 1;
76
77 /* Number of successor and predecessor edges. */
78 gcov_type succ_count;
79 gcov_type pred_count;
80 };
81
82 #define BB_INFO(b) ((struct bb_info *) (b)->aux)
83
84
85 /* Counter summary from the last set of coverage counts read. */
86
87 const struct gcov_ctr_summary *profile_info;
88
89 /* Collect statistics on the performance of this pass for the entire source
90 file. */
91
92 static int total_num_blocks;
93 static int total_num_edges;
94 static int total_num_edges_ignored;
95 static int total_num_edges_instrumented;
96 static int total_num_blocks_created;
97 static int total_num_passes;
98 static int total_num_times_called;
99 static int total_hist_br_prob[20];
100 static int total_num_branches;
101
102 /* Forward declarations. */
103 static void find_spanning_tree (struct edge_list *);
104
105 /* Add edge instrumentation code to the entire insn chain.
106
107 F is the first insn of the chain.
108 NUM_BLOCKS is the number of basic blocks found in F. */
109
110 static unsigned
111 instrument_edges (struct edge_list *el)
112 {
113 unsigned num_instr_edges = 0;
114 int num_edges = NUM_EDGES (el);
115 basic_block bb;
116
117 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb)
118 {
119 edge e;
120 edge_iterator ei;
121
122 FOR_EACH_EDGE (e, ei, bb->succs)
123 {
124 struct edge_info *inf = EDGE_INFO (e);
125
126 if (!inf->ignore && !inf->on_tree)
127 {
128 gcc_assert (!(e->flags & EDGE_ABNORMAL));
129 if (dump_file)
130 fprintf (dump_file, "Edge %d to %d instrumented%s\n",
131 e->src->index, e->dest->index,
132 EDGE_CRITICAL_P (e) ? " (and split)" : "");
133 gimple_gen_edge_profiler (num_instr_edges++, e);
134 }
135 }
136 }
137
138 total_num_blocks_created += num_edges;
139 if (dump_file)
140 fprintf (dump_file, "%d edges instrumented\n", num_instr_edges);
141 return num_instr_edges;
142 }
143
144 /* Add code to measure histograms for values in list VALUES. */
145 static void
146 instrument_values (histogram_values values)
147 {
148 unsigned i, t;
149
150 /* Emit code to generate the histograms before the insns. */
151
152 for (i = 0; i < VEC_length (histogram_value, values); i++)
153 {
154 histogram_value hist = VEC_index (histogram_value, values, i);
155 switch (hist->type)
156 {
157 case HIST_TYPE_INTERVAL:
158 t = GCOV_COUNTER_V_INTERVAL;
159 break;
160
161 case HIST_TYPE_POW2:
162 t = GCOV_COUNTER_V_POW2;
163 break;
164
165 case HIST_TYPE_SINGLE_VALUE:
166 t = GCOV_COUNTER_V_SINGLE;
167 break;
168
169 case HIST_TYPE_CONST_DELTA:
170 t = GCOV_COUNTER_V_DELTA;
171 break;
172
173 case HIST_TYPE_INDIR_CALL:
174 t = GCOV_COUNTER_V_INDIR;
175 break;
176
177 case HIST_TYPE_AVERAGE:
178 t = GCOV_COUNTER_AVERAGE;
179 break;
180
181 case HIST_TYPE_IOR:
182 t = GCOV_COUNTER_IOR;
183 break;
184
185 default:
186 gcc_unreachable ();
187 }
188 if (!coverage_counter_alloc (t, hist->n_counters))
189 continue;
190
191 switch (hist->type)
192 {
193 case HIST_TYPE_INTERVAL:
194 gimple_gen_interval_profiler (hist, t, 0);
195 break;
196
197 case HIST_TYPE_POW2:
198 gimple_gen_pow2_profiler (hist, t, 0);
199 break;
200
201 case HIST_TYPE_SINGLE_VALUE:
202 gimple_gen_one_value_profiler (hist, t, 0);
203 break;
204
205 case HIST_TYPE_CONST_DELTA:
206 gimple_gen_const_delta_profiler (hist, t, 0);
207 break;
208
209 case HIST_TYPE_INDIR_CALL:
210 gimple_gen_ic_profiler (hist, t, 0);
211 break;
212
213 case HIST_TYPE_AVERAGE:
214 gimple_gen_average_profiler (hist, t, 0);
215 break;
216
217 case HIST_TYPE_IOR:
218 gimple_gen_ior_profiler (hist, t, 0);
219 break;
220
221 default:
222 gcc_unreachable ();
223 }
224 }
225 }
226 \f
227
228 /* Computes hybrid profile for all matching entries in da_file.
229
230 CFG_CHECKSUM is the precomputed checksum for the CFG. */
231
232 static gcov_type *
233 get_exec_counts (unsigned cfg_checksum, unsigned lineno_checksum)
234 {
235 unsigned num_edges = 0;
236 basic_block bb;
237 gcov_type *counts;
238
239 /* Count the edges to be (possibly) instrumented. */
240 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb)
241 {
242 edge e;
243 edge_iterator ei;
244
245 FOR_EACH_EDGE (e, ei, bb->succs)
246 if (!EDGE_INFO (e)->ignore && !EDGE_INFO (e)->on_tree)
247 num_edges++;
248 }
249
250 counts = get_coverage_counts (GCOV_COUNTER_ARCS, num_edges, cfg_checksum,
251 lineno_checksum, &profile_info);
252 if (!counts)
253 return NULL;
254
255 if (dump_file && profile_info)
256 fprintf(dump_file, "Merged %u profiles with maximal count %u.\n",
257 profile_info->runs, (unsigned) profile_info->sum_max);
258
259 return counts;
260 }
261
262
263 static bool
264 is_edge_inconsistent (VEC(edge,gc) *edges)
265 {
266 edge e;
267 edge_iterator ei;
268 FOR_EACH_EDGE (e, ei, edges)
269 {
270 if (!EDGE_INFO (e)->ignore)
271 {
272 if (e->count < 0
273 && (!(e->flags & EDGE_FAKE)
274 || !block_ends_with_call_p (e->src)))
275 {
276 if (dump_file)
277 {
278 fprintf (dump_file,
279 "Edge %i->%i is inconsistent, count"HOST_WIDEST_INT_PRINT_DEC,
280 e->src->index, e->dest->index, e->count);
281 dump_bb (e->src, dump_file, 0);
282 dump_bb (e->dest, dump_file, 0);
283 }
284 return true;
285 }
286 }
287 }
288 return false;
289 }
290
291 static void
292 correct_negative_edge_counts (void)
293 {
294 basic_block bb;
295 edge e;
296 edge_iterator ei;
297
298 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb)
299 {
300 FOR_EACH_EDGE (e, ei, bb->succs)
301 {
302 if (e->count < 0)
303 e->count = 0;
304 }
305 }
306 }
307
308 /* Check consistency.
309 Return true if inconsistency is found. */
310 static bool
311 is_inconsistent (void)
312 {
313 basic_block bb;
314 bool inconsistent = false;
315 FOR_EACH_BB (bb)
316 {
317 inconsistent |= is_edge_inconsistent (bb->preds);
318 if (!dump_file && inconsistent)
319 return true;
320 inconsistent |= is_edge_inconsistent (bb->succs);
321 if (!dump_file && inconsistent)
322 return true;
323 if (bb->count < 0)
324 {
325 if (dump_file)
326 {
327 fprintf (dump_file, "BB %i count is negative "
328 HOST_WIDEST_INT_PRINT_DEC,
329 bb->index,
330 bb->count);
331 dump_bb (bb, dump_file, 0);
332 }
333 inconsistent = true;
334 }
335 if (bb->count != sum_edge_counts (bb->preds))
336 {
337 if (dump_file)
338 {
339 fprintf (dump_file, "BB %i count does not match sum of incoming edges "
340 HOST_WIDEST_INT_PRINT_DEC" should be " HOST_WIDEST_INT_PRINT_DEC,
341 bb->index,
342 bb->count,
343 sum_edge_counts (bb->preds));
344 dump_bb (bb, dump_file, 0);
345 }
346 inconsistent = true;
347 }
348 if (bb->count != sum_edge_counts (bb->succs) &&
349 ! (find_edge (bb, EXIT_BLOCK_PTR) != NULL && block_ends_with_call_p (bb)))
350 {
351 if (dump_file)
352 {
353 fprintf (dump_file, "BB %i count does not match sum of outgoing edges "
354 HOST_WIDEST_INT_PRINT_DEC" should be " HOST_WIDEST_INT_PRINT_DEC,
355 bb->index,
356 bb->count,
357 sum_edge_counts (bb->succs));
358 dump_bb (bb, dump_file, 0);
359 }
360 inconsistent = true;
361 }
362 if (!dump_file && inconsistent)
363 return true;
364 }
365
366 return inconsistent;
367 }
368
369 /* Set each basic block count to the sum of its outgoing edge counts */
370 static void
371 set_bb_counts (void)
372 {
373 basic_block bb;
374 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb)
375 {
376 bb->count = sum_edge_counts (bb->succs);
377 gcc_assert (bb->count >= 0);
378 }
379 }
380
381 /* Reads profile data and returns total number of edge counts read */
382 static int
383 read_profile_edge_counts (gcov_type *exec_counts)
384 {
385 basic_block bb;
386 int num_edges = 0;
387 int exec_counts_pos = 0;
388 /* For each edge not on the spanning tree, set its execution count from
389 the .da file. */
390 /* The first count in the .da file is the number of times that the function
391 was entered. This is the exec_count for block zero. */
392
393 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb)
394 {
395 edge e;
396 edge_iterator ei;
397
398 FOR_EACH_EDGE (e, ei, bb->succs)
399 if (!EDGE_INFO (e)->ignore && !EDGE_INFO (e)->on_tree)
400 {
401 num_edges++;
402 if (exec_counts)
403 {
404 e->count = exec_counts[exec_counts_pos++];
405 if (e->count > profile_info->sum_max)
406 {
407 if (flag_profile_correction)
408 {
409 static bool informed = 0;
410 if (!informed)
411 inform (input_location,
412 "corrupted profile info: edge count exceeds maximal count");
413 informed = 1;
414 }
415 else
416 error ("corrupted profile info: edge from %i to %i exceeds maximal count",
417 bb->index, e->dest->index);
418 }
419 }
420 else
421 e->count = 0;
422
423 EDGE_INFO (e)->count_valid = 1;
424 BB_INFO (bb)->succ_count--;
425 BB_INFO (e->dest)->pred_count--;
426 if (dump_file)
427 {
428 fprintf (dump_file, "\nRead edge from %i to %i, count:",
429 bb->index, e->dest->index);
430 fprintf (dump_file, HOST_WIDEST_INT_PRINT_DEC,
431 (HOST_WIDEST_INT) e->count);
432 }
433 }
434 }
435
436 return num_edges;
437 }
438
439 #define OVERLAP_BASE 10000
440
441 /* Compare the static estimated profile to the actual profile, and
442 return the "degree of overlap" measure between them.
443
444 Degree of overlap is a number between 0 and OVERLAP_BASE. It is
445 the sum of each basic block's minimum relative weights between
446 two profiles. And overlap of OVERLAP_BASE means two profiles are
447 identical. */
448
449 static int
450 compute_frequency_overlap (void)
451 {
452 gcov_type count_total = 0, freq_total = 0;
453 int overlap = 0;
454 basic_block bb;
455
456 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb)
457 {
458 count_total += bb->count;
459 freq_total += bb->frequency;
460 }
461
462 if (count_total == 0 || freq_total == 0)
463 return 0;
464
465 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb)
466 overlap += MIN (bb->count * OVERLAP_BASE / count_total,
467 bb->frequency * OVERLAP_BASE / freq_total);
468
469 return overlap;
470 }
471
472 /* Compute the branch probabilities for the various branches.
473 Annotate them accordingly.
474
475 CFG_CHECKSUM is the precomputed checksum for the CFG. */
476
477 static void
478 compute_branch_probabilities (unsigned cfg_checksum, unsigned lineno_checksum)
479 {
480 basic_block bb;
481 int i;
482 int num_edges = 0;
483 int changes;
484 int passes;
485 int hist_br_prob[20];
486 int num_branches;
487 gcov_type *exec_counts = get_exec_counts (cfg_checksum, lineno_checksum);
488 int inconsistent = 0;
489
490 /* Very simple sanity checks so we catch bugs in our profiling code. */
491 if (!profile_info)
492 return;
493 if (profile_info->run_max * profile_info->runs < profile_info->sum_max)
494 {
495 error ("corrupted profile info: run_max * runs < sum_max");
496 exec_counts = NULL;
497 }
498
499 if (profile_info->sum_all < profile_info->sum_max)
500 {
501 error ("corrupted profile info: sum_all is smaller than sum_max");
502 exec_counts = NULL;
503 }
504
505 /* Attach extra info block to each bb. */
506 alloc_aux_for_blocks (sizeof (struct bb_info));
507 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb)
508 {
509 edge e;
510 edge_iterator ei;
511
512 FOR_EACH_EDGE (e, ei, bb->succs)
513 if (!EDGE_INFO (e)->ignore)
514 BB_INFO (bb)->succ_count++;
515 FOR_EACH_EDGE (e, ei, bb->preds)
516 if (!EDGE_INFO (e)->ignore)
517 BB_INFO (bb)->pred_count++;
518 }
519
520 /* Avoid predicting entry on exit nodes. */
521 BB_INFO (EXIT_BLOCK_PTR)->succ_count = 2;
522 BB_INFO (ENTRY_BLOCK_PTR)->pred_count = 2;
523
524 num_edges = read_profile_edge_counts (exec_counts);
525
526 if (dump_file)
527 fprintf (dump_file, "\n%d edge counts read\n", num_edges);
528
529 /* For every block in the file,
530 - if every exit/entrance edge has a known count, then set the block count
531 - if the block count is known, and every exit/entrance edge but one has
532 a known execution count, then set the count of the remaining edge
533
534 As edge counts are set, decrement the succ/pred count, but don't delete
535 the edge, that way we can easily tell when all edges are known, or only
536 one edge is unknown. */
537
538 /* The order that the basic blocks are iterated through is important.
539 Since the code that finds spanning trees starts with block 0, low numbered
540 edges are put on the spanning tree in preference to high numbered edges.
541 Hence, most instrumented edges are at the end. Graph solving works much
542 faster if we propagate numbers from the end to the start.
543
544 This takes an average of slightly more than 3 passes. */
545
546 changes = 1;
547 passes = 0;
548 while (changes)
549 {
550 passes++;
551 changes = 0;
552 FOR_BB_BETWEEN (bb, EXIT_BLOCK_PTR, NULL, prev_bb)
553 {
554 struct bb_info *bi = BB_INFO (bb);
555 if (! bi->count_valid)
556 {
557 if (bi->succ_count == 0)
558 {
559 edge e;
560 edge_iterator ei;
561 gcov_type total = 0;
562
563 FOR_EACH_EDGE (e, ei, bb->succs)
564 total += e->count;
565 bb->count = total;
566 bi->count_valid = 1;
567 changes = 1;
568 }
569 else if (bi->pred_count == 0)
570 {
571 edge e;
572 edge_iterator ei;
573 gcov_type total = 0;
574
575 FOR_EACH_EDGE (e, ei, bb->preds)
576 total += e->count;
577 bb->count = total;
578 bi->count_valid = 1;
579 changes = 1;
580 }
581 }
582 if (bi->count_valid)
583 {
584 if (bi->succ_count == 1)
585 {
586 edge e;
587 edge_iterator ei;
588 gcov_type total = 0;
589
590 /* One of the counts will be invalid, but it is zero,
591 so adding it in also doesn't hurt. */
592 FOR_EACH_EDGE (e, ei, bb->succs)
593 total += e->count;
594
595 /* Search for the invalid edge, and set its count. */
596 FOR_EACH_EDGE (e, ei, bb->succs)
597 if (! EDGE_INFO (e)->count_valid && ! EDGE_INFO (e)->ignore)
598 break;
599
600 /* Calculate count for remaining edge by conservation. */
601 total = bb->count - total;
602
603 gcc_assert (e);
604 EDGE_INFO (e)->count_valid = 1;
605 e->count = total;
606 bi->succ_count--;
607
608 BB_INFO (e->dest)->pred_count--;
609 changes = 1;
610 }
611 if (bi->pred_count == 1)
612 {
613 edge e;
614 edge_iterator ei;
615 gcov_type total = 0;
616
617 /* One of the counts will be invalid, but it is zero,
618 so adding it in also doesn't hurt. */
619 FOR_EACH_EDGE (e, ei, bb->preds)
620 total += e->count;
621
622 /* Search for the invalid edge, and set its count. */
623 FOR_EACH_EDGE (e, ei, bb->preds)
624 if (!EDGE_INFO (e)->count_valid && !EDGE_INFO (e)->ignore)
625 break;
626
627 /* Calculate count for remaining edge by conservation. */
628 total = bb->count - total + e->count;
629
630 gcc_assert (e);
631 EDGE_INFO (e)->count_valid = 1;
632 e->count = total;
633 bi->pred_count--;
634
635 BB_INFO (e->src)->succ_count--;
636 changes = 1;
637 }
638 }
639 }
640 }
641 if (dump_file)
642 {
643 int overlap = compute_frequency_overlap ();
644 dump_flow_info (dump_file, dump_flags);
645 fprintf (dump_file, "Static profile overlap: %d.%d%%\n",
646 overlap / (OVERLAP_BASE / 100),
647 overlap % (OVERLAP_BASE / 100));
648 }
649
650 total_num_passes += passes;
651 if (dump_file)
652 fprintf (dump_file, "Graph solving took %d passes.\n\n", passes);
653
654 /* If the graph has been correctly solved, every block will have a
655 succ and pred count of zero. */
656 FOR_EACH_BB (bb)
657 {
658 gcc_assert (!BB_INFO (bb)->succ_count && !BB_INFO (bb)->pred_count);
659 }
660
661 /* Check for inconsistent basic block counts */
662 inconsistent = is_inconsistent ();
663
664 if (inconsistent)
665 {
666 if (flag_profile_correction)
667 {
668 /* Inconsistency detected. Make it flow-consistent. */
669 static int informed = 0;
670 if (informed == 0)
671 {
672 informed = 1;
673 inform (input_location, "correcting inconsistent profile data");
674 }
675 correct_negative_edge_counts ();
676 /* Set bb counts to the sum of the outgoing edge counts */
677 set_bb_counts ();
678 if (dump_file)
679 fprintf (dump_file, "\nCalling mcf_smooth_cfg\n");
680 mcf_smooth_cfg ();
681 }
682 else
683 error ("corrupted profile info: profile data is not flow-consistent");
684 }
685
686 /* For every edge, calculate its branch probability and add a reg_note
687 to the branch insn to indicate this. */
688
689 for (i = 0; i < 20; i++)
690 hist_br_prob[i] = 0;
691 num_branches = 0;
692
693 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb)
694 {
695 edge e;
696 edge_iterator ei;
697
698 if (bb->count < 0)
699 {
700 error ("corrupted profile info: number of iterations for basic block %d thought to be %i",
701 bb->index, (int)bb->count);
702 bb->count = 0;
703 }
704 FOR_EACH_EDGE (e, ei, bb->succs)
705 {
706 /* Function may return twice in the cased the called function is
707 setjmp or calls fork, but we can't represent this by extra
708 edge from the entry, since extra edge from the exit is
709 already present. We get negative frequency from the entry
710 point. */
711 if ((e->count < 0
712 && e->dest == EXIT_BLOCK_PTR)
713 || (e->count > bb->count
714 && e->dest != EXIT_BLOCK_PTR))
715 {
716 if (block_ends_with_call_p (bb))
717 e->count = e->count < 0 ? 0 : bb->count;
718 }
719 if (e->count < 0 || e->count > bb->count)
720 {
721 error ("corrupted profile info: number of executions for edge %d-%d thought to be %i",
722 e->src->index, e->dest->index,
723 (int)e->count);
724 e->count = bb->count / 2;
725 }
726 }
727 if (bb->count)
728 {
729 FOR_EACH_EDGE (e, ei, bb->succs)
730 e->probability = (e->count * REG_BR_PROB_BASE + bb->count / 2) / bb->count;
731 if (bb->index >= NUM_FIXED_BLOCKS
732 && block_ends_with_condjump_p (bb)
733 && EDGE_COUNT (bb->succs) >= 2)
734 {
735 int prob;
736 edge e;
737 int index;
738
739 /* Find the branch edge. It is possible that we do have fake
740 edges here. */
741 FOR_EACH_EDGE (e, ei, bb->succs)
742 if (!(e->flags & (EDGE_FAKE | EDGE_FALLTHRU)))
743 break;
744
745 prob = e->probability;
746 index = prob * 20 / REG_BR_PROB_BASE;
747
748 if (index == 20)
749 index = 19;
750 hist_br_prob[index]++;
751
752 num_branches++;
753 }
754 }
755 /* As a last resort, distribute the probabilities evenly.
756 Use simple heuristics that if there are normal edges,
757 give all abnormals frequency of 0, otherwise distribute the
758 frequency over abnormals (this is the case of noreturn
759 calls). */
760 else if (profile_status == PROFILE_ABSENT)
761 {
762 int total = 0;
763
764 FOR_EACH_EDGE (e, ei, bb->succs)
765 if (!(e->flags & (EDGE_COMPLEX | EDGE_FAKE)))
766 total ++;
767 if (total)
768 {
769 FOR_EACH_EDGE (e, ei, bb->succs)
770 if (!(e->flags & (EDGE_COMPLEX | EDGE_FAKE)))
771 e->probability = REG_BR_PROB_BASE / total;
772 else
773 e->probability = 0;
774 }
775 else
776 {
777 total += EDGE_COUNT (bb->succs);
778 FOR_EACH_EDGE (e, ei, bb->succs)
779 e->probability = REG_BR_PROB_BASE / total;
780 }
781 if (bb->index >= NUM_FIXED_BLOCKS
782 && block_ends_with_condjump_p (bb)
783 && EDGE_COUNT (bb->succs) >= 2)
784 num_branches++;
785 }
786 }
787 counts_to_freqs ();
788 profile_status = PROFILE_READ;
789 compute_function_frequency ();
790
791 if (dump_file)
792 {
793 fprintf (dump_file, "%d branches\n", num_branches);
794 if (num_branches)
795 for (i = 0; i < 10; i++)
796 fprintf (dump_file, "%d%% branches in range %d-%d%%\n",
797 (hist_br_prob[i] + hist_br_prob[19-i]) * 100 / num_branches,
798 5 * i, 5 * i + 5);
799
800 total_num_branches += num_branches;
801 for (i = 0; i < 20; i++)
802 total_hist_br_prob[i] += hist_br_prob[i];
803
804 fputc ('\n', dump_file);
805 fputc ('\n', dump_file);
806 }
807
808 free_aux_for_blocks ();
809 }
810
811 /* Load value histograms values whose description is stored in VALUES array
812 from .gcda file.
813
814 CFG_CHECKSUM is the precomputed checksum for the CFG. */
815
816 static void
817 compute_value_histograms (histogram_values values, unsigned cfg_checksum,
818 unsigned lineno_checksum)
819 {
820 unsigned i, j, t, any;
821 unsigned n_histogram_counters[GCOV_N_VALUE_COUNTERS];
822 gcov_type *histogram_counts[GCOV_N_VALUE_COUNTERS];
823 gcov_type *act_count[GCOV_N_VALUE_COUNTERS];
824 gcov_type *aact_count;
825
826 for (t = 0; t < GCOV_N_VALUE_COUNTERS; t++)
827 n_histogram_counters[t] = 0;
828
829 for (i = 0; i < VEC_length (histogram_value, values); i++)
830 {
831 histogram_value hist = VEC_index (histogram_value, values, i);
832 n_histogram_counters[(int) hist->type] += hist->n_counters;
833 }
834
835 any = 0;
836 for (t = 0; t < GCOV_N_VALUE_COUNTERS; t++)
837 {
838 if (!n_histogram_counters[t])
839 {
840 histogram_counts[t] = NULL;
841 continue;
842 }
843
844 histogram_counts[t] =
845 get_coverage_counts (COUNTER_FOR_HIST_TYPE (t),
846 n_histogram_counters[t], cfg_checksum,
847 lineno_checksum, NULL);
848 if (histogram_counts[t])
849 any = 1;
850 act_count[t] = histogram_counts[t];
851 }
852 if (!any)
853 return;
854
855 for (i = 0; i < VEC_length (histogram_value, values); i++)
856 {
857 histogram_value hist = VEC_index (histogram_value, values, i);
858 gimple stmt = hist->hvalue.stmt;
859
860 t = (int) hist->type;
861
862 aact_count = act_count[t];
863 act_count[t] += hist->n_counters;
864
865 gimple_add_histogram_value (cfun, stmt, hist);
866 hist->hvalue.counters = XNEWVEC (gcov_type, hist->n_counters);
867 for (j = 0; j < hist->n_counters; j++)
868 hist->hvalue.counters[j] = aact_count[j];
869 }
870
871 for (t = 0; t < GCOV_N_VALUE_COUNTERS; t++)
872 free (histogram_counts[t]);
873 }
874
875 /* The entry basic block will be moved around so that it has index=1,
876 there is nothing at index 0 and the exit is at n_basic_block. */
877 #define BB_TO_GCOV_INDEX(bb) ((bb)->index - 1)
878 /* When passed NULL as file_name, initialize.
879 When passed something else, output the necessary commands to change
880 line to LINE and offset to FILE_NAME. */
881 static void
882 output_location (char const *file_name, int line,
883 gcov_position_t *offset, basic_block bb)
884 {
885 static char const *prev_file_name;
886 static int prev_line;
887 bool name_differs, line_differs;
888
889 if (!file_name)
890 {
891 prev_file_name = NULL;
892 prev_line = -1;
893 return;
894 }
895
896 name_differs = !prev_file_name || filename_cmp (file_name, prev_file_name);
897 line_differs = prev_line != line;
898
899 if (name_differs || line_differs)
900 {
901 if (!*offset)
902 {
903 *offset = gcov_write_tag (GCOV_TAG_LINES);
904 gcov_write_unsigned (BB_TO_GCOV_INDEX (bb));
905 name_differs = line_differs=true;
906 }
907
908 /* If this is a new source file, then output the
909 file's name to the .bb file. */
910 if (name_differs)
911 {
912 prev_file_name = file_name;
913 gcov_write_unsigned (0);
914 gcov_write_string (prev_file_name);
915 }
916 if (line_differs)
917 {
918 gcov_write_unsigned (line);
919 prev_line = line;
920 }
921 }
922 }
923
924 /* Instrument and/or analyze program behavior based on program flow graph.
925 In either case, this function builds a flow graph for the function being
926 compiled. The flow graph is stored in BB_GRAPH.
927
928 When FLAG_PROFILE_ARCS is nonzero, this function instruments the edges in
929 the flow graph that are needed to reconstruct the dynamic behavior of the
930 flow graph.
931
932 When FLAG_BRANCH_PROBABILITIES is nonzero, this function reads auxiliary
933 information from a data file containing edge count information from previous
934 executions of the function being compiled. In this case, the flow graph is
935 annotated with actual execution counts, which are later propagated into the
936 rtl for optimization purposes.
937
938 Main entry point of this file. */
939
940 void
941 branch_prob (void)
942 {
943 basic_block bb;
944 unsigned i;
945 unsigned num_edges, ignored_edges;
946 unsigned num_instrumented;
947 struct edge_list *el;
948 histogram_values values = NULL;
949 unsigned cfg_checksum, lineno_checksum;
950
951 total_num_times_called++;
952
953 flow_call_edges_add (NULL);
954 add_noreturn_fake_exit_edges ();
955
956 /* We can't handle cyclic regions constructed using abnormal edges.
957 To avoid these we replace every source of abnormal edge by a fake
958 edge from entry node and every destination by fake edge to exit.
959 This keeps graph acyclic and our calculation exact for all normal
960 edges except for exit and entrance ones.
961
962 We also add fake exit edges for each call and asm statement in the
963 basic, since it may not return. */
964
965 FOR_EACH_BB (bb)
966 {
967 int need_exit_edge = 0, need_entry_edge = 0;
968 int have_exit_edge = 0, have_entry_edge = 0;
969 edge e;
970 edge_iterator ei;
971
972 /* Functions returning multiple times are not handled by extra edges.
973 Instead we simply allow negative counts on edges from exit to the
974 block past call and corresponding probabilities. We can't go
975 with the extra edges because that would result in flowgraph that
976 needs to have fake edges outside the spanning tree. */
977
978 FOR_EACH_EDGE (e, ei, bb->succs)
979 {
980 gimple_stmt_iterator gsi;
981 gimple last = NULL;
982
983 /* It may happen that there are compiler generated statements
984 without a locus at all. Go through the basic block from the
985 last to the first statement looking for a locus. */
986 for (gsi = gsi_last_nondebug_bb (bb);
987 !gsi_end_p (gsi);
988 gsi_prev_nondebug (&gsi))
989 {
990 last = gsi_stmt (gsi);
991 if (gimple_has_location (last))
992 break;
993 }
994
995 /* Edge with goto locus might get wrong coverage info unless
996 it is the only edge out of BB.
997 Don't do that when the locuses match, so
998 if (blah) goto something;
999 is not computed twice. */
1000 if (last
1001 && gimple_has_location (last)
1002 && e->goto_locus != UNKNOWN_LOCATION
1003 && !single_succ_p (bb)
1004 && (LOCATION_FILE (e->goto_locus)
1005 != LOCATION_FILE (gimple_location (last))
1006 || (LOCATION_LINE (e->goto_locus)
1007 != LOCATION_LINE (gimple_location (last)))))
1008 {
1009 basic_block new_bb = split_edge (e);
1010 edge ne = single_succ_edge (new_bb);
1011 ne->goto_locus = e->goto_locus;
1012 ne->goto_block = e->goto_block;
1013 }
1014 if ((e->flags & (EDGE_ABNORMAL | EDGE_ABNORMAL_CALL))
1015 && e->dest != EXIT_BLOCK_PTR)
1016 need_exit_edge = 1;
1017 if (e->dest == EXIT_BLOCK_PTR)
1018 have_exit_edge = 1;
1019 }
1020 FOR_EACH_EDGE (e, ei, bb->preds)
1021 {
1022 if ((e->flags & (EDGE_ABNORMAL | EDGE_ABNORMAL_CALL))
1023 && e->src != ENTRY_BLOCK_PTR)
1024 need_entry_edge = 1;
1025 if (e->src == ENTRY_BLOCK_PTR)
1026 have_entry_edge = 1;
1027 }
1028
1029 if (need_exit_edge && !have_exit_edge)
1030 {
1031 if (dump_file)
1032 fprintf (dump_file, "Adding fake exit edge to bb %i\n",
1033 bb->index);
1034 make_edge (bb, EXIT_BLOCK_PTR, EDGE_FAKE);
1035 }
1036 if (need_entry_edge && !have_entry_edge)
1037 {
1038 if (dump_file)
1039 fprintf (dump_file, "Adding fake entry edge to bb %i\n",
1040 bb->index);
1041 make_edge (ENTRY_BLOCK_PTR, bb, EDGE_FAKE);
1042 /* Avoid bbs that have both fake entry edge and also some
1043 exit edge. One of those edges wouldn't be added to the
1044 spanning tree, but we can't instrument any of them. */
1045 if (have_exit_edge || need_exit_edge)
1046 {
1047 gimple_stmt_iterator gsi;
1048 gimple first;
1049 tree fndecl;
1050
1051 gsi = gsi_after_labels (bb);
1052 gcc_checking_assert (!gsi_end_p (gsi));
1053 first = gsi_stmt (gsi);
1054 if (is_gimple_debug (first))
1055 {
1056 gsi_next_nondebug (&gsi);
1057 gcc_checking_assert (!gsi_end_p (gsi));
1058 first = gsi_stmt (gsi);
1059 }
1060 /* Don't split the bbs containing __builtin_setjmp_receiver
1061 or __builtin_setjmp_dispatcher calls. These are very
1062 special and don't expect anything to be inserted before
1063 them. */
1064 if (!is_gimple_call (first)
1065 || (fndecl = gimple_call_fndecl (first)) == NULL
1066 || DECL_BUILT_IN_CLASS (fndecl) != BUILT_IN_NORMAL
1067 || (DECL_FUNCTION_CODE (fndecl) != BUILT_IN_SETJMP_RECEIVER
1068 && (DECL_FUNCTION_CODE (fndecl)
1069 != BUILT_IN_SETJMP_DISPATCHER)))
1070 {
1071 if (dump_file)
1072 fprintf (dump_file, "Splitting bb %i after labels\n",
1073 bb->index);
1074 split_block_after_labels (bb);
1075 }
1076 }
1077 }
1078 }
1079
1080 el = create_edge_list ();
1081 num_edges = NUM_EDGES (el);
1082 alloc_aux_for_edges (sizeof (struct edge_info));
1083
1084 /* The basic blocks are expected to be numbered sequentially. */
1085 compact_blocks ();
1086
1087 ignored_edges = 0;
1088 for (i = 0 ; i < num_edges ; i++)
1089 {
1090 edge e = INDEX_EDGE (el, i);
1091 e->count = 0;
1092
1093 /* Mark edges we've replaced by fake edges above as ignored. */
1094 if ((e->flags & (EDGE_ABNORMAL | EDGE_ABNORMAL_CALL))
1095 && e->src != ENTRY_BLOCK_PTR && e->dest != EXIT_BLOCK_PTR)
1096 {
1097 EDGE_INFO (e)->ignore = 1;
1098 ignored_edges++;
1099 }
1100 }
1101
1102 /* Create spanning tree from basic block graph, mark each edge that is
1103 on the spanning tree. We insert as many abnormal and critical edges
1104 as possible to minimize number of edge splits necessary. */
1105
1106 find_spanning_tree (el);
1107
1108 /* Fake edges that are not on the tree will not be instrumented, so
1109 mark them ignored. */
1110 for (num_instrumented = i = 0; i < num_edges; i++)
1111 {
1112 edge e = INDEX_EDGE (el, i);
1113 struct edge_info *inf = EDGE_INFO (e);
1114
1115 if (inf->ignore || inf->on_tree)
1116 /*NOP*/;
1117 else if (e->flags & EDGE_FAKE)
1118 {
1119 inf->ignore = 1;
1120 ignored_edges++;
1121 }
1122 else
1123 num_instrumented++;
1124 }
1125
1126 total_num_blocks += n_basic_blocks;
1127 if (dump_file)
1128 fprintf (dump_file, "%d basic blocks\n", n_basic_blocks);
1129
1130 total_num_edges += num_edges;
1131 if (dump_file)
1132 fprintf (dump_file, "%d edges\n", num_edges);
1133
1134 total_num_edges_ignored += ignored_edges;
1135 if (dump_file)
1136 fprintf (dump_file, "%d ignored edges\n", ignored_edges);
1137
1138
1139 /* Compute two different checksums. Note that we want to compute
1140 the checksum in only once place, since it depends on the shape
1141 of the control flow which can change during
1142 various transformations. */
1143 cfg_checksum = coverage_compute_cfg_checksum ();
1144 lineno_checksum = coverage_compute_lineno_checksum ();
1145
1146 /* Write the data from which gcov can reconstruct the basic block
1147 graph and function line numbers */
1148
1149 if (coverage_begin_function (lineno_checksum, cfg_checksum))
1150 {
1151 gcov_position_t offset;
1152
1153 /* Basic block flags */
1154 offset = gcov_write_tag (GCOV_TAG_BLOCKS);
1155 for (i = 0; i != (unsigned) (n_basic_blocks); i++)
1156 gcov_write_unsigned (0);
1157 gcov_write_length (offset);
1158
1159 /* Keep all basic block indexes nonnegative in the gcov output.
1160 Index 0 is used for entry block, last index is for exit
1161 block. */
1162 ENTRY_BLOCK_PTR->index = 1;
1163 EXIT_BLOCK_PTR->index = last_basic_block;
1164
1165 /* Arcs */
1166 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, EXIT_BLOCK_PTR, next_bb)
1167 {
1168 edge e;
1169 edge_iterator ei;
1170
1171 offset = gcov_write_tag (GCOV_TAG_ARCS);
1172 gcov_write_unsigned (BB_TO_GCOV_INDEX (bb));
1173
1174 FOR_EACH_EDGE (e, ei, bb->succs)
1175 {
1176 struct edge_info *i = EDGE_INFO (e);
1177 if (!i->ignore)
1178 {
1179 unsigned flag_bits = 0;
1180
1181 if (i->on_tree)
1182 flag_bits |= GCOV_ARC_ON_TREE;
1183 if (e->flags & EDGE_FAKE)
1184 flag_bits |= GCOV_ARC_FAKE;
1185 if (e->flags & EDGE_FALLTHRU)
1186 flag_bits |= GCOV_ARC_FALLTHROUGH;
1187 /* On trees we don't have fallthru flags, but we can
1188 recompute them from CFG shape. */
1189 if (e->flags & (EDGE_TRUE_VALUE | EDGE_FALSE_VALUE)
1190 && e->src->next_bb == e->dest)
1191 flag_bits |= GCOV_ARC_FALLTHROUGH;
1192
1193 gcov_write_unsigned (BB_TO_GCOV_INDEX (e->dest));
1194 gcov_write_unsigned (flag_bits);
1195 }
1196 }
1197
1198 gcov_write_length (offset);
1199 }
1200
1201 ENTRY_BLOCK_PTR->index = ENTRY_BLOCK;
1202 EXIT_BLOCK_PTR->index = EXIT_BLOCK;
1203
1204 /* Line numbers. */
1205 /* Initialize the output. */
1206 output_location (NULL, 0, NULL, NULL);
1207
1208 FOR_EACH_BB (bb)
1209 {
1210 gimple_stmt_iterator gsi;
1211 gcov_position_t offset = 0;
1212
1213 if (bb == ENTRY_BLOCK_PTR->next_bb)
1214 {
1215 expanded_location curr_location =
1216 expand_location (DECL_SOURCE_LOCATION (current_function_decl));
1217 output_location (curr_location.file, curr_location.line,
1218 &offset, bb);
1219 }
1220
1221 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
1222 {
1223 gimple stmt = gsi_stmt (gsi);
1224 if (gimple_has_location (stmt))
1225 output_location (gimple_filename (stmt), gimple_lineno (stmt),
1226 &offset, bb);
1227 }
1228
1229 /* Notice GOTO expressions eliminated while constructing the CFG. */
1230 if (single_succ_p (bb)
1231 && single_succ_edge (bb)->goto_locus != UNKNOWN_LOCATION)
1232 {
1233 expanded_location curr_location
1234 = expand_location (single_succ_edge (bb)->goto_locus);
1235 output_location (curr_location.file, curr_location.line,
1236 &offset, bb);
1237 }
1238
1239 if (offset)
1240 {
1241 /* A file of NULL indicates the end of run. */
1242 gcov_write_unsigned (0);
1243 gcov_write_string (NULL);
1244 gcov_write_length (offset);
1245 }
1246 }
1247 }
1248
1249 #undef BB_TO_GCOV_INDEX
1250
1251 if (flag_profile_values)
1252 gimple_find_values_to_profile (&values);
1253
1254 if (flag_branch_probabilities)
1255 {
1256 compute_branch_probabilities (cfg_checksum, lineno_checksum);
1257 if (flag_profile_values)
1258 compute_value_histograms (values, cfg_checksum, lineno_checksum);
1259 }
1260
1261 remove_fake_edges ();
1262
1263 /* For each edge not on the spanning tree, add counting code. */
1264 if (profile_arc_flag
1265 && coverage_counter_alloc (GCOV_COUNTER_ARCS, num_instrumented))
1266 {
1267 unsigned n_instrumented;
1268
1269 gimple_init_edge_profiler ();
1270
1271 n_instrumented = instrument_edges (el);
1272
1273 gcc_assert (n_instrumented == num_instrumented);
1274
1275 if (flag_profile_values)
1276 instrument_values (values);
1277
1278 /* Commit changes done by instrumentation. */
1279 gsi_commit_edge_inserts ();
1280 }
1281
1282 free_aux_for_edges ();
1283
1284 VEC_free (histogram_value, heap, values);
1285 free_edge_list (el);
1286 coverage_end_function (lineno_checksum, cfg_checksum);
1287 }
1288 \f
1289 /* Union find algorithm implementation for the basic blocks using
1290 aux fields. */
1291
1292 static basic_block
1293 find_group (basic_block bb)
1294 {
1295 basic_block group = bb, bb1;
1296
1297 while ((basic_block) group->aux != group)
1298 group = (basic_block) group->aux;
1299
1300 /* Compress path. */
1301 while ((basic_block) bb->aux != group)
1302 {
1303 bb1 = (basic_block) bb->aux;
1304 bb->aux = (void *) group;
1305 bb = bb1;
1306 }
1307 return group;
1308 }
1309
1310 static void
1311 union_groups (basic_block bb1, basic_block bb2)
1312 {
1313 basic_block bb1g = find_group (bb1);
1314 basic_block bb2g = find_group (bb2);
1315
1316 /* ??? I don't have a place for the rank field. OK. Lets go w/o it,
1317 this code is unlikely going to be performance problem anyway. */
1318 gcc_assert (bb1g != bb2g);
1319
1320 bb1g->aux = bb2g;
1321 }
1322 \f
1323 /* This function searches all of the edges in the program flow graph, and puts
1324 as many bad edges as possible onto the spanning tree. Bad edges include
1325 abnormals edges, which can't be instrumented at the moment. Since it is
1326 possible for fake edges to form a cycle, we will have to develop some
1327 better way in the future. Also put critical edges to the tree, since they
1328 are more expensive to instrument. */
1329
1330 static void
1331 find_spanning_tree (struct edge_list *el)
1332 {
1333 int i;
1334 int num_edges = NUM_EDGES (el);
1335 basic_block bb;
1336
1337 /* We use aux field for standard union-find algorithm. */
1338 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb)
1339 bb->aux = bb;
1340
1341 /* Add fake edge exit to entry we can't instrument. */
1342 union_groups (EXIT_BLOCK_PTR, ENTRY_BLOCK_PTR);
1343
1344 /* First add all abnormal edges to the tree unless they form a cycle. Also
1345 add all edges to EXIT_BLOCK_PTR to avoid inserting profiling code behind
1346 setting return value from function. */
1347 for (i = 0; i < num_edges; i++)
1348 {
1349 edge e = INDEX_EDGE (el, i);
1350 if (((e->flags & (EDGE_ABNORMAL | EDGE_ABNORMAL_CALL | EDGE_FAKE))
1351 || e->dest == EXIT_BLOCK_PTR)
1352 && !EDGE_INFO (e)->ignore
1353 && (find_group (e->src) != find_group (e->dest)))
1354 {
1355 if (dump_file)
1356 fprintf (dump_file, "Abnormal edge %d to %d put to tree\n",
1357 e->src->index, e->dest->index);
1358 EDGE_INFO (e)->on_tree = 1;
1359 union_groups (e->src, e->dest);
1360 }
1361 }
1362
1363 /* Now insert all critical edges to the tree unless they form a cycle. */
1364 for (i = 0; i < num_edges; i++)
1365 {
1366 edge e = INDEX_EDGE (el, i);
1367 if (EDGE_CRITICAL_P (e) && !EDGE_INFO (e)->ignore
1368 && find_group (e->src) != find_group (e->dest))
1369 {
1370 if (dump_file)
1371 fprintf (dump_file, "Critical edge %d to %d put to tree\n",
1372 e->src->index, e->dest->index);
1373 EDGE_INFO (e)->on_tree = 1;
1374 union_groups (e->src, e->dest);
1375 }
1376 }
1377
1378 /* And now the rest. */
1379 for (i = 0; i < num_edges; i++)
1380 {
1381 edge e = INDEX_EDGE (el, i);
1382 if (!EDGE_INFO (e)->ignore
1383 && find_group (e->src) != find_group (e->dest))
1384 {
1385 if (dump_file)
1386 fprintf (dump_file, "Normal edge %d to %d put to tree\n",
1387 e->src->index, e->dest->index);
1388 EDGE_INFO (e)->on_tree = 1;
1389 union_groups (e->src, e->dest);
1390 }
1391 }
1392
1393 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb)
1394 bb->aux = NULL;
1395 }
1396 \f
1397 /* Perform file-level initialization for branch-prob processing. */
1398
1399 void
1400 init_branch_prob (void)
1401 {
1402 int i;
1403
1404 total_num_blocks = 0;
1405 total_num_edges = 0;
1406 total_num_edges_ignored = 0;
1407 total_num_edges_instrumented = 0;
1408 total_num_blocks_created = 0;
1409 total_num_passes = 0;
1410 total_num_times_called = 0;
1411 total_num_branches = 0;
1412 for (i = 0; i < 20; i++)
1413 total_hist_br_prob[i] = 0;
1414 }
1415
1416 /* Performs file-level cleanup after branch-prob processing
1417 is completed. */
1418
1419 void
1420 end_branch_prob (void)
1421 {
1422 if (dump_file)
1423 {
1424 fprintf (dump_file, "\n");
1425 fprintf (dump_file, "Total number of blocks: %d\n",
1426 total_num_blocks);
1427 fprintf (dump_file, "Total number of edges: %d\n", total_num_edges);
1428 fprintf (dump_file, "Total number of ignored edges: %d\n",
1429 total_num_edges_ignored);
1430 fprintf (dump_file, "Total number of instrumented edges: %d\n",
1431 total_num_edges_instrumented);
1432 fprintf (dump_file, "Total number of blocks created: %d\n",
1433 total_num_blocks_created);
1434 fprintf (dump_file, "Total number of graph solution passes: %d\n",
1435 total_num_passes);
1436 if (total_num_times_called != 0)
1437 fprintf (dump_file, "Average number of graph solution passes: %d\n",
1438 (total_num_passes + (total_num_times_called >> 1))
1439 / total_num_times_called);
1440 fprintf (dump_file, "Total number of branches: %d\n",
1441 total_num_branches);
1442 if (total_num_branches)
1443 {
1444 int i;
1445
1446 for (i = 0; i < 10; i++)
1447 fprintf (dump_file, "%d%% branches in range %d-%d%%\n",
1448 (total_hist_br_prob[i] + total_hist_br_prob[19-i]) * 100
1449 / total_num_branches, 5*i, 5*i+5);
1450 }
1451 }
1452 }