diff options
| author | Nathan Slingerland <slingn@gmail.com> | 2015-11-20 19:12:43 +0000 |
|---|---|---|
| committer | Nathan Slingerland <slingn@gmail.com> | 2015-11-20 19:12:43 +0000 |
| commit | a731829788542d4b9591c34478a0c8caf7a11760 (patch) | |
| tree | 98c43cfa6c942c6c25eca0839a6a2645ca4de195 /llvm/lib/ProfileData | |
| parent | 19ff5602da953d81ac79e7c2dc712464b2c4b6b0 (diff) | |
| download | bcm5719-llvm-a731829788542d4b9591c34478a0c8caf7a11760.tar.gz bcm5719-llvm-a731829788542d4b9591c34478a0c8caf7a11760.zip | |
[llvm-profdata] Add merge() to InstrProfRecord
Summary:
This change refactors two aspects of InstrProfRecord:
1) Add a merge() method to InstrProfRecord (previously InstrProfWriter combineInstrProfRecords()) in order to better encapsulate this functionality and to make the InstrProfRecord and SampleRecord APIs more consistent.
2) Make InstrProfRecord mergeValueProfData() a private method since it is only ever called internally by merge().
Reviewers: dnovillo, bogner, davidxl
Subscribers: silvas, vsk, llvm-commits
Differential Revision: http://reviews.llvm.org/D14786
llvm-svn: 253695
Diffstat (limited to 'llvm/lib/ProfileData')
| -rw-r--r-- | llvm/lib/ProfileData/InstrProfWriter.cpp | 54 |
1 files changed, 18 insertions, 36 deletions
diff --git a/llvm/lib/ProfileData/InstrProfWriter.cpp b/llvm/lib/ProfileData/InstrProfWriter.cpp index cb123e29982..465a4ea9e00 100644 --- a/llvm/lib/ProfileData/InstrProfWriter.cpp +++ b/llvm/lib/ProfileData/InstrProfWriter.cpp @@ -87,32 +87,6 @@ public: }; } -static std::error_code combineInstrProfRecords(InstrProfRecord &Dest, - InstrProfRecord &Source, - uint64_t &MaxFunctionCount) { - // If the number of counters doesn't match we either have bad data - // or a hash collision. - if (Dest.Counts.size() != Source.Counts.size()) - return instrprof_error::count_mismatch; - - for (size_t I = 0, E = Source.Counts.size(); I < E; ++I) { - if (Dest.Counts[I] + Source.Counts[I] < Dest.Counts[I]) - return instrprof_error::counter_overflow; - Dest.Counts[I] += Source.Counts[I]; - } - - for (uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind) { - if (std::error_code EC = Dest.mergeValueProfData(Kind, Source)) - return EC; - } - - // We keep track of the max function count as we go for simplicity. - if (Dest.Counts[0] > MaxFunctionCount) - MaxFunctionCount = Dest.Counts[0]; - - return instrprof_error::success; -} - // Internal interface for testing purpose only. void InstrProfWriter::setValueProfDataEndianness( support::endianness Endianness) { @@ -127,19 +101,27 @@ std::error_code InstrProfWriter::addRecord(InstrProfRecord &&I) { updateStringTableReferences(I); auto &ProfileDataMap = FunctionData[I.Name]; - auto Where = ProfileDataMap.find(I.Hash); - if (Where == ProfileDataMap.end()) { + bool NewFunc; + ProfilingData::iterator Where; + std::tie(Where, NewFunc) = + ProfileDataMap.insert(std::make_pair(I.Hash, InstrProfRecord())); + InstrProfRecord &Dest = Where->second; + if (NewFunc) { // We've never seen a function with this name and hash, add it. - ProfileDataMap[I.Hash] = I; - - // We keep track of the max function count as we go for simplicity. - if (I.Counts[0] > MaxFunctionCount) - MaxFunctionCount = I.Counts[0]; - return instrprof_error::success; + Dest = std::move(I); + } else { + // We're updating a function we've seen before. + instrprof_error MergeResult = Dest.merge(I); + if (MergeResult != instrprof_error::success) { + return MergeResult; + } } - // We're updating a function we've seen before. - return combineInstrProfRecords(Where->second, I, MaxFunctionCount); + // We keep track of the max function count as we go for simplicity. + if (Dest.Counts[0] > MaxFunctionCount) + MaxFunctionCount = Dest.Counts[0]; + + return instrprof_error::success; } std::pair<uint64_t, uint64_t> InstrProfWriter::writeImpl(raw_ostream &OS) { |

