[PATCH] D66693: [SampleFDO] Extract the code calling each section reader to addOneSection

Wei Mi via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 23 17:11:28 PDT 2019


wmi created this revision.
wmi added reviewers: davidxl, mtrofin.
Herald added a project: LLVM.

This is a followup of https://reviews.llvm.org/D66513. I just realize I should put the code calling each section reader into a separate function (I name it addOneSection), 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.


Repository:
  rL LLVM

https://reviews.llvm.org/D66693

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


Index: lib/ProfileData/SampleProfReader.cpp
===================================================================
--- lib/ProfileData/SampleProfReader.cpp
+++ lib/ProfileData/SampleProfReader.cpp
@@ -467,6 +467,31 @@
   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 @@
     // 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;
   }
 
Index: include/llvm/ProfileData/SampleProfReader.h
===================================================================
--- include/llvm/ProfileData/SampleProfReader.h
+++ include/llvm/ProfileData/SampleProfReader.h
@@ -481,6 +481,8 @@
   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 @@
 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,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66693.216982.patch
Type: text/x-patch
Size: 2945 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190824/6590d150/attachment-0001.bin>


More information about the llvm-commits mailing list