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