diff options
author | Xinliang David Li <davidxl@google.com> | 2015-12-04 01:02:10 +0000 |
---|---|---|
committer | Xinliang David Li <davidxl@google.com> | 2015-12-04 01:02:10 +0000 |
commit | 01cb9bd7b330682c783272271fa5d21eaf08e300 (patch) | |
tree | 8e760a988d87c1523ce3e0a4e02c1b3b9b919a9f /llvm/lib/ProfileData/InstrProfReader.cpp | |
parent | 7fc3cb5919f8c7f634b6ef846fbf8071811a9ab1 (diff) | |
download | llvm-01cb9bd7b330682c783272271fa5d21eaf08e300.zip llvm-01cb9bd7b330682c783272271fa5d21eaf08e300.tar.gz llvm-01cb9bd7b330682c783272271fa5d21eaf08e300.tar.bz2 |
[PGO] Unify VP data format between raw and indexed profile (Reader)
With the latest refactoring and code sharing patches landed,
it is possible to unify the value profile implementation between
raw and indexed profile. This is the patch in raw profile reader
that uses the common interface.
Differential Revision: http://reviews.llvm.org/D15056
llvm-svn: 254677
Diffstat (limited to 'llvm/lib/ProfileData/InstrProfReader.cpp')
-rw-r--r-- | llvm/lib/ProfileData/InstrProfReader.cpp | 49 |
1 files changed, 11 insertions, 38 deletions
diff --git a/llvm/lib/ProfileData/InstrProfReader.cpp b/llvm/lib/ProfileData/InstrProfReader.cpp index cfc9687..7683cad 100644 --- a/llvm/lib/ProfileData/InstrProfReader.cpp +++ b/llvm/lib/ProfileData/InstrProfReader.cpp @@ -296,55 +296,28 @@ std::error_code RawInstrProfReader<IntPtrT>::readRawCounts( } template <class IntPtrT> -std::error_code RawInstrProfReader<IntPtrT>::readValueProfilingData( - InstrProfRecord &Record) { +std::error_code +RawInstrProfReader<IntPtrT>::readValueProfilingData(InstrProfRecord &Record) { Record.clearValueData(); if (!Data->Values || (ValueDataDelta == 0)) return success(); - // Read value data. - uint64_t NumVSites = 0; - for (uint32_t Kind = IPVK_First; Kind <= ValueKindLast; ++Kind) - NumVSites += swap(Data->NumValueSites[Kind]); - NumVSites += getNumPaddingBytes(NumVSites); + ErrorOr<std::unique_ptr<ValueProfData>> VDataPtrOrErr = + ValueProfData::getValueProfData(getValueDataCounts(Data->Values), + (const unsigned char *)ProfileEnd, + getDataEndianness()); - auto VDataCounts = makeArrayRef(getValueDataCounts(Data->Values), NumVSites); - // Check bounds. - if (VDataCounts.data() < ValueDataStart || - VDataCounts.data() + VDataCounts.size() > - reinterpret_cast<const uint8_t *>(ProfileEnd)) - return error(instrprof_error::malformed); + if (VDataPtrOrErr.getError()) + return VDataPtrOrErr.getError(); - const InstrProfValueData *VDataPtr = - getValueData(swap(Data->Values) + NumVSites); - for (uint32_t Kind = IPVK_First; Kind <= ValueKindLast; ++Kind) { - NumVSites = swap(Data->NumValueSites[Kind]); - Record.reserveSites(Kind, NumVSites); - for (uint32_t VSite = 0; VSite < NumVSites; ++VSite) { - - uint32_t VDataCount = VDataCounts[VSite]; - if ((const char *)(VDataPtr + VDataCount) > ProfileEnd) - return error(instrprof_error::malformed); - - std::vector<InstrProfValueData> CurrentValues; - CurrentValues.reserve(VDataCount); - for (uint32_t VIndex = 0; VIndex < VDataCount; ++VIndex) { - uint64_t TargetValue = swap(VDataPtr->Value); - uint64_t Count = swap(VDataPtr->Count); - CurrentValues.push_back({TargetValue, Count}); - ++VDataPtr; - } - Record.addValueData(Kind, VSite, CurrentValues.data(), - VDataCount, &FunctionPtrToNameMap); - } - } + VDataPtrOrErr.get()->deserializeTo(Record, &FunctionPtrToNameMap); return success(); } template <class IntPtrT> -std::error_code RawInstrProfReader<IntPtrT>::readNextRecord( - InstrProfRecord &Record) { +std::error_code +RawInstrProfReader<IntPtrT>::readNextRecord(InstrProfRecord &Record) { if (atEnd()) if (std::error_code EC = readNextHeader(ProfileEnd)) return EC; |