From 8fa402e863325a5f71533b91eab8fb71bce763b2 Mon Sep 17 00:00:00 2001 From: Xinliang David Li Date: Thu, 5 May 2016 19:41:18 +0000 Subject: [PATCH] [profile] Remove unneeded field in raw profile reader Differential Revision: http://reviews.llvm.org/D19956 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@268667 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ProfileData/InstrProfReader.h | 7 ++++++- lib/ProfileData/InstrProfReader.cpp | 14 ++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/include/llvm/ProfileData/InstrProfReader.h b/include/llvm/ProfileData/InstrProfReader.h index 303d9af90f5..a5d06264536 100644 --- a/include/llvm/ProfileData/InstrProfReader.h +++ b/include/llvm/ProfileData/InstrProfReader.h @@ -170,8 +170,9 @@ private: const uint64_t *CountersStart; const char *NamesStart; uint64_t NamesSize; + // After value profile is all read, this pointer points to + // the header of next profile data (if exists) const uint8_t *ValueDataStart; - const char *ProfileEnd; uint32_t ValueKindLast; uint32_t CurValueDataSize; @@ -224,6 +225,10 @@ private: Data++; ValueDataStart += CurValueDataSize; } + const char *getNextHeaderPos() const { + assert(atEnd()); + return (const char *)ValueDataStart; + } const uint64_t *getCounter(IntPtrT CounterPtr) const { ptrdiff_t Offset = (swap(CounterPtr) - CountersDelta) / sizeof(uint64_t); diff --git a/lib/ProfileData/InstrProfReader.cpp b/lib/ProfileData/InstrProfReader.cpp index b3b89d74dfb..03f20e877e5 100644 --- a/lib/ProfileData/InstrProfReader.cpp +++ b/lib/ProfileData/InstrProfReader.cpp @@ -324,7 +324,6 @@ RawInstrProfReader::readHeader(const RawInstrProf::Header &Header) { auto DataSize = swap(Header.DataSize); auto CountersSize = swap(Header.CountersSize); NamesSize = swap(Header.NamesSize); - auto ValueDataSize = swap(Header.ValueDataSize); ValueKindLast = swap(Header.ValueKindLast); auto DataSizeInBytes = DataSize * sizeof(RawInstrProf::ProfileData); @@ -334,10 +333,9 @@ RawInstrProfReader::readHeader(const RawInstrProf::Header &Header) { ptrdiff_t CountersOffset = DataOffset + DataSizeInBytes; ptrdiff_t NamesOffset = CountersOffset + sizeof(uint64_t) * CountersSize; ptrdiff_t ValueDataOffset = NamesOffset + NamesSize + PaddingSize; - size_t ProfileSize = ValueDataOffset + ValueDataSize; auto *Start = reinterpret_cast(&Header); - if (Start + ProfileSize > DataBuffer->getBufferEnd()) + if (Start + ValueDataOffset > DataBuffer->getBufferEnd()) return error(instrprof_error::bad_header); Data = reinterpret_cast *>( @@ -346,7 +344,6 @@ RawInstrProfReader::readHeader(const RawInstrProf::Header &Header) { CountersStart = reinterpret_cast(Start + CountersOffset); NamesStart = Start + NamesOffset; ValueDataStart = reinterpret_cast(Start + ValueDataOffset); - ProfileEnd = Start + ProfileSize; std::unique_ptr NewSymtab = make_unique(); if (auto EC = createSymtab(*NewSymtab.get())) @@ -411,9 +408,9 @@ RawInstrProfReader::readValueProfilingData(InstrProfRecord &Record) { return success(); ErrorOr> VDataPtrOrErr = - ValueProfData::getValueProfData(ValueDataStart, - (const unsigned char *)ProfileEnd, - getDataEndianness()); + ValueProfData::getValueProfData( + ValueDataStart, (const unsigned char *)DataBuffer->getBufferEnd(), + getDataEndianness()); if (VDataPtrOrErr.getError()) return VDataPtrOrErr.getError(); @@ -430,7 +427,8 @@ template std::error_code RawInstrProfReader::readNextRecord(InstrProfRecord &Record) { if (atEnd()) - if (std::error_code EC = readNextHeader(ProfileEnd)) + // At this point, ValueDataStart field points to the next header. + if (std::error_code EC = readNextHeader(getNextHeaderPos())) return EC; // Read name ad set it in Record. -- 2.50.1