diff options
| author | Rong Xu <xur@google.com> | 2018-03-27 18:55:56 +0000 |
|---|---|---|
| committer | Rong Xu <xur@google.com> | 2018-03-27 18:55:56 +0000 |
| commit | 662f38b16f0ef69e0e55a0662d2fe68413e1e465 (patch) | |
| tree | abce8a91e793db490ed0d0d4e295480eb83fa1f0 /llvm/lib/Transforms | |
| parent | 0a0c871f601aae4a26694eea06f37becba78d1e4 (diff) | |
| download | bcm5719-llvm-662f38b16f0ef69e0e55a0662d2fe68413e1e465.tar.gz bcm5719-llvm-662f38b16f0ef69e0e55a0662d2fe68413e1e465.zip | |
[PGO] Fix branch probability remarks assert
Fixed counter/weight overflow that leads to an assertion. Also fixed the help
string for pgo-emit-branch-prob option.
Differential Revision: https://reviews.llvm.org/D44809
llvm-svn: 328653
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp index 8bc5671040f..f38eb5b3c06 100644 --- a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp +++ b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp @@ -224,8 +224,8 @@ static cl::opt<bool> EmitBranchProbability("pgo-emit-branch-prob", cl::init(false), cl::Hidden, cl::desc("When this option is on, the annotated " "branch probability will be emitted as " - " optimization remarks: -Rpass-analysis=" - "pgo-instr-use")); + "optimization remarks: -{Rpass|" + "pass-remarks}=pgo-instrumentation")); // Command line option to turn on CFG dot dump after profile annotation. // Defined in Analysis/BlockFrequencyInfo.cpp: -pgo-view-counts @@ -1595,13 +1595,15 @@ void llvm::setProfMetadata(Module *M, Instruction *TI, if (BrCondStr.empty()) return; - unsigned WSum = - std::accumulate(Weights.begin(), Weights.end(), 0, - [](unsigned w1, unsigned w2) { return w1 + w2; }); + uint64_t WSum = + std::accumulate(Weights.begin(), Weights.end(), (uint64_t)0, + [](uint64_t w1, uint64_t w2) { return w1 + w2; }); uint64_t TotalCount = - std::accumulate(EdgeCounts.begin(), EdgeCounts.end(), 0, + std::accumulate(EdgeCounts.begin(), EdgeCounts.end(), (uint64_t)0, [](uint64_t c1, uint64_t c2) { return c1 + c2; }); - BranchProbability BP(Weights[0], WSum); + Scale = calculateCountScale(WSum); + BranchProbability BP(scaleBranchCount(Weights[0], Scale), + scaleBranchCount(WSum, Scale)); std::string BranchProbStr; raw_string_ostream OS(BranchProbStr); OS << BP; |

