X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=blobdiff_plain;f=lib%2FProfileData%2FInstrProfReader.cpp;fp=lib%2FProfileData%2FInstrProfReader.cpp;h=7683cad6ede47637ab21c0824c31f484cce49fb6;hp=cfc968739806b6b1fafa2fcd4634cea0f80f9146;hb=7579d3aaed060dd8002e11f9c64f27508ec32f3c;hpb=cd7c95d7e887ecda0b795690623ea9567f0659e7 diff --git a/lib/ProfileData/InstrProfReader.cpp b/lib/ProfileData/InstrProfReader.cpp index cfc96873980..7683cad6ede 100644 --- a/lib/ProfileData/InstrProfReader.cpp +++ b/lib/ProfileData/InstrProfReader.cpp @@ -296,55 +296,28 @@ std::error_code RawInstrProfReader::readRawCounts( } template -std::error_code RawInstrProfReader::readValueProfilingData( - InstrProfRecord &Record) { +std::error_code +RawInstrProfReader::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> 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(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 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 -std::error_code RawInstrProfReader::readNextRecord( - InstrProfRecord &Record) { +std::error_code +RawInstrProfReader::readNextRecord(InstrProfRecord &Record) { if (atEnd()) if (std::error_code EC = readNextHeader(ProfileEnd)) return EC;