diff options
author | Xinliang David Li <davidxl@google.com> | 2016-01-08 03:49:59 +0000 |
---|---|---|
committer | Xinliang David Li <davidxl@google.com> | 2016-01-08 03:49:59 +0000 |
commit | 51dc04cff25c5f9ab97dfa88fdd81566302fd349 (patch) | |
tree | 9df0beb2024c9f6ea7d69ea44a152797045d7869 /llvm/lib/ProfileData/InstrProfWriter.cpp | |
parent | 652b97bcf7eb2c7d0ac118401581ff131051b65d (diff) | |
download | llvm-51dc04cff25c5f9ab97dfa88fdd81566302fd349.zip llvm-51dc04cff25c5f9ab97dfa88fdd81566302fd349.tar.gz llvm-51dc04cff25c5f9ab97dfa88fdd81566302fd349.tar.bz2 |
[PGO] Fix a bug in InstProfWriter addRecord
For a new record with weight != 1, only edge profiling
counters are scaled, VP data is not properly scaled.
This patch refactors the code and fixes the problem.
Also added sort by count interface (for follow up patch).
llvm-svn: 257143
Diffstat (limited to 'llvm/lib/ProfileData/InstrProfWriter.cpp')
-rw-r--r-- | llvm/lib/ProfileData/InstrProfWriter.cpp | 14 |
1 files changed, 3 insertions, 11 deletions
diff --git a/llvm/lib/ProfileData/InstrProfWriter.cpp b/llvm/lib/ProfileData/InstrProfWriter.cpp index 9bb03e1..07667e1 100644 --- a/llvm/lib/ProfileData/InstrProfWriter.cpp +++ b/llvm/lib/ProfileData/InstrProfWriter.cpp @@ -104,22 +104,14 @@ std::error_code InstrProfWriter::addRecord(InstrProfRecord &&I, ProfileDataMap.insert(std::make_pair(I.Hash, InstrProfRecord())); InstrProfRecord &Dest = Where->second; - instrprof_error Result; + instrprof_error Result = instrprof_error::success; if (NewFunc) { // We've never seen a function with this name and hash, add it. Dest = std::move(I); // Fix up the name to avoid dangling reference. Dest.Name = FunctionData.find(Dest.Name)->getKey(); - Result = instrprof_error::success; - if (Weight > 1) { - for (auto &Count : Dest.Counts) { - bool Overflowed; - Count = SaturatingMultiply(Count, Weight, &Overflowed); - if (Overflowed && Result == instrprof_error::success) { - Result = instrprof_error::counter_overflow; - } - } - } + if (Weight > 1) + Result = Dest.scale(Weight); } else { // We're updating a function we've seen before. Result = Dest.merge(I, Weight); |