|
| 1 | +//===- bolt/Passes/ContinuityStats.h ----------------------------*- C++ -*-===// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | +// |
| 9 | +// This pass checks how well the BOLT input profile satisfies the following |
| 10 | +// "CFG continuity" property of a perfect profile: |
| 11 | +// |
| 12 | +// Each positive-execution-count block in the function’s CFG |
| 13 | +// should be *reachable* from a positive-execution-count function |
| 14 | +// entry block through a positive-execution-count path. |
| 15 | +// |
| 16 | +// More specifically, for each of the hottest 1000 functions, the pass |
| 17 | +// calculates the function’s fraction of basic block execution counts |
| 18 | +// that is *unreachable*. It then reports the 95th percentile of the |
| 19 | +// distribution of the 1000 unreachable fractions in a single BOLT-INFO line. |
| 20 | +// The smaller the reported value is, the better the BOLT profile |
| 21 | +// satisfies the CFG continuity property. |
| 22 | + |
| 23 | +// The default value of 1000 above can be changed via the hidden BOLT option |
| 24 | +// `-num-functions-for-continuity-check=[N]`. |
| 25 | +// If more detailed stats are needed, `-v=1` can be used: the hottest N |
| 26 | +// functions will be grouped into 5 equally-sized buckets, from the hottest |
| 27 | +// to the coldest; for each bucket, various summary statistics of the |
| 28 | +// distribution of the unreachable fractions and the raw unreachable execution |
| 29 | +// counts will be reported. |
| 30 | +// |
| 31 | +//===----------------------------------------------------------------------===// |
| 32 | + |
| 33 | +#ifndef BOLT_PASSES_CONTINUITYSTATS_H |
| 34 | +#define BOLT_PASSES_CONTINUITYSTATS_H |
| 35 | + |
| 36 | +#include "bolt/Passes/BinaryPasses.h" |
| 37 | +#include <vector> |
| 38 | + |
| 39 | +namespace llvm { |
| 40 | + |
| 41 | +class raw_ostream; |
| 42 | + |
| 43 | +namespace bolt { |
| 44 | +class BinaryContext; |
| 45 | + |
| 46 | +/// Compute and report to the user the function CFG continuity quality |
| 47 | +class PrintContinuityStats : public BinaryFunctionPass { |
| 48 | +public: |
| 49 | + explicit PrintContinuityStats(const cl::opt<bool> &PrintPass) |
| 50 | + : BinaryFunctionPass(PrintPass) {} |
| 51 | + |
| 52 | + bool shouldOptimize(const BinaryFunction &BF) const override; |
| 53 | + const char *getName() const override { return "continuity-stats"; } |
| 54 | + bool shouldPrint(const BinaryFunction &) const override { return false; } |
| 55 | + Error runOnFunctions(BinaryContext &BC) override; |
| 56 | +}; |
| 57 | + |
| 58 | +} // namespace bolt |
| 59 | +} // namespace llvm |
| 60 | + |
| 61 | +#endif // BOLT_PASSES_CONTINUITYSTATS_H |
0 commit comments