[llvm] r268667 - [profile] Remove unneeded field in raw profile reader

Xinliang David Li via llvm-commits llvm-commits at lists.llvm.org
Thu May 5 12:41:19 PDT 2016


Author: davidxl
Date: Thu May  5 14:41:18 2016
New Revision: 268667

URL: http://llvm.org/viewvc/llvm-project?rev=268667&view=rev
Log:
[profile] Remove unneeded field in raw profile reader

Differential Revision: http://reviews.llvm.org/D19956

Modified:
    llvm/trunk/include/llvm/ProfileData/InstrProfReader.h
    llvm/trunk/lib/ProfileData/InstrProfReader.cpp

Modified: llvm/trunk/include/llvm/ProfileData/InstrProfReader.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/InstrProfReader.h?rev=268667&r1=268666&r2=268667&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ProfileData/InstrProfReader.h (original)
+++ llvm/trunk/include/llvm/ProfileData/InstrProfReader.h Thu May  5 14:41:18 2016
@@ -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);

Modified: llvm/trunk/lib/ProfileData/InstrProfReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProfReader.cpp?rev=268667&r1=268666&r2=268667&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/InstrProfReader.cpp (original)
+++ llvm/trunk/lib/ProfileData/InstrProfReader.cpp Thu May  5 14:41:18 2016
@@ -324,7 +324,6 @@ RawInstrProfReader<IntPtrT>::readHeader(
   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<IntPtrT>);
@@ -334,10 +333,9 @@ RawInstrProfReader<IntPtrT>::readHeader(
   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<const char *>(&Header);
-  if (Start + ProfileSize > DataBuffer->getBufferEnd())
+  if (Start + ValueDataOffset > DataBuffer->getBufferEnd())
     return error(instrprof_error::bad_header);
 
   Data = reinterpret_cast<const RawInstrProf::ProfileData<IntPtrT> *>(
@@ -346,7 +344,6 @@ RawInstrProfReader<IntPtrT>::readHeader(
   CountersStart = reinterpret_cast<const uint64_t *>(Start + CountersOffset);
   NamesStart = Start + NamesOffset;
   ValueDataStart = reinterpret_cast<const uint8_t *>(Start + ValueDataOffset);
-  ProfileEnd = Start + ProfileSize;
 
   std::unique_ptr<InstrProfSymtab> NewSymtab = make_unique<InstrProfSymtab>();
   if (auto EC = createSymtab(*NewSymtab.get()))
@@ -411,9 +408,9 @@ RawInstrProfReader<IntPtrT>::readValuePr
     return success();
 
   ErrorOr<std::unique_ptr<ValueProfData>> 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 <class IntPtrT>
 std::error_code
 RawInstrProfReader<IntPtrT>::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.




More information about the llvm-commits mailing list