[PATCH] D19956: [profile] Remove unnecessary field in raw profile reader

David Li via llvm-commits llvm-commits at lists.llvm.org
Thu May 5 00:11:07 PDT 2016


davidxl created this revision.
davidxl added a reviewer: vsk.
davidxl added a subscriber: llvm-commits.

This is a preparation patch that allows us to get rid of the ValueDataSize field in the raw header. By removing that field, the value profile writer code can be greatly simplified without the need to be split into two phases : data gathering and writing, which will also reduce the memory usage in profile runtime (no need to buffer all value data before writing out).

http://reviews.llvm.org/D19956

Files:
  include/llvm/ProfileData/InstrProfReader.h
  lib/ProfileData/InstrProfReader.cpp

Index: lib/ProfileData/InstrProfReader.cpp
===================================================================
--- lib/ProfileData/InstrProfReader.cpp
+++ lib/ProfileData/InstrProfReader.cpp
@@ -324,7 +324,6 @@
   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,19 +333,17 @@
   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> *>(
       Start + DataOffset);
   DataEnd = Data + DataSize;
   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 @@
     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 @@
 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((const char *)ValueDataStart))
       return EC;
 
   // Read name ad set it in Record.
Index: include/llvm/ProfileData/InstrProfReader.h
===================================================================
--- include/llvm/ProfileData/InstrProfReader.h
+++ include/llvm/ProfileData/InstrProfReader.h
@@ -170,8 +170,9 @@
   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;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19956.56240.patch
Type: text/x-patch
Size: 2985 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160505/ec40444f/attachment.bin>


More information about the llvm-commits mailing list