[llvm] r369919 - [SampleFDO] Extract the code calling each section reader to readOneSection.

Wei Mi via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 26 08:54:16 PDT 2019


Author: wmi
Date: Mon Aug 26 08:54:16 2019
New Revision: 369919

URL: http://llvm.org/viewvc/llvm-project?rev=369919&view=rev
Log:
[SampleFDO] Extract the code calling each section reader to readOneSection.

This is a followup of https://reviews.llvm.org/D66513. The code calling each
section reader should be put into a separate function (readOneSection), so
SampleProfileExtBinaryReader can override it. Otherwise, the base class
SampleProfileExtBinaryBaseReader will need to be aware of all different kinds
of section readers. That is not right.

Differential Revision: https://reviews.llvm.org/D66693

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

Modified: llvm/trunk/include/llvm/ProfileData/SampleProfReader.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/SampleProfReader.h?rev=369919&r1=369918&r2=369919&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ProfileData/SampleProfReader.h (original)
+++ llvm/trunk/include/llvm/ProfileData/SampleProfReader.h Mon Aug 26 08:54:16 2019
@@ -481,6 +481,8 @@ protected:
   std::error_code readSecHdrTable();
   virtual std::error_code readHeader() override;
   virtual std::error_code verifySPMagic(uint64_t Magic) override = 0;
+  virtual std::error_code readOneSection(const uint8_t *Start, uint64_t Size,
+                                         SecType Type) = 0;
 
 public:
   SampleProfileReaderExtBinaryBase(std::unique_ptr<MemoryBuffer> B,
@@ -494,6 +496,8 @@ public:
 class SampleProfileReaderExtBinary : public SampleProfileReaderExtBinaryBase {
 private:
   virtual std::error_code verifySPMagic(uint64_t Magic) override;
+  virtual std::error_code readOneSection(const uint8_t *Start, uint64_t Size,
+                                         SecType Type) override;
 
 public:
   SampleProfileReaderExtBinary(std::unique_ptr<MemoryBuffer> B, LLVMContext &C,

Modified: llvm/trunk/lib/ProfileData/SampleProfReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/SampleProfReader.cpp?rev=369919&r1=369918&r2=369919&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/SampleProfReader.cpp (original)
+++ llvm/trunk/lib/ProfileData/SampleProfReader.cpp Mon Aug 26 08:54:16 2019
@@ -467,6 +467,31 @@ std::error_code SampleProfileReaderBinar
   return sampleprof_error::success;
 }
 
+std::error_code
+SampleProfileReaderExtBinary::readOneSection(const uint8_t *Start,
+                                             uint64_t Size, SecType Type) {
+  Data = Start;
+  switch (Type) {
+  case SecProfSummary:
+    if (std::error_code EC = readSummary())
+      return EC;
+    break;
+  case SecNameTable:
+    if (std::error_code EC = readNameTable())
+      return EC;
+    break;
+  case SecLBRProfile:
+    while (Data < Start + Size) {
+      if (std::error_code EC = readFuncProfile())
+        return EC;
+    }
+    break;
+  default:
+    break;
+  }
+  return sampleprof_error::success;
+}
+
 std::error_code SampleProfileReaderExtBinaryBase::read() {
   const uint8_t *BufStart =
       reinterpret_cast<const uint8_t *>(Buffer->getBufferStart());
@@ -475,26 +500,10 @@ std::error_code SampleProfileReaderExtBi
     // Skip empty section.
     if (!Entry.Size)
       continue;
-    Data = BufStart + Entry.Offset;
-    switch (Entry.Type) {
-    case SecProfSummary:
-      if (std::error_code EC = readSummary())
-        return EC;
-      break;
-    case SecNameTable:
-      if (std::error_code EC = readNameTable())
-        return EC;
-      break;
-    case SecLBRProfile:
-      while (Data < BufStart + Entry.Offset + Entry.Size) {
-        if (std::error_code EC = readFuncProfile())
-          return EC;
-      }
-      break;
-    default:
-      continue;
-    }
-    if (Data != BufStart + Entry.Offset + Entry.Size)
+    const uint8_t *SecStart = BufStart + Entry.Offset;
+    if (std::error_code EC = readOneSection(SecStart, Entry.Size, Entry.Type))
+      return EC;
+    if (Data != SecStart + Entry.Size)
       return sampleprof_error::malformed;
   }
 




More information about the llvm-commits mailing list