summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWei Mi <wmi@google.com>2019-08-26 15:54:16 +0000
committerWei Mi <wmi@google.com>2019-08-26 15:54:16 +0000
commit077a9c7053dce0e0a45343cb3c0b018eb690be02 (patch)
treeeca2fde9d2b1e704129430527f46273914e851f6
parenta6fed93f0d1077f24e83fcd8abd31443acaf80e6 (diff)
downloadbcm5719-llvm-077a9c7053dce0e0a45343cb3c0b018eb690be02.tar.gz
bcm5719-llvm-077a9c7053dce0e0a45343cb3c0b018eb690be02.zip
[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 llvm-svn: 369919
-rw-r--r--llvm/include/llvm/ProfileData/SampleProfReader.h4
-rw-r--r--llvm/lib/ProfileData/SampleProfReader.cpp49
2 files changed, 33 insertions, 20 deletions
diff --git a/llvm/include/llvm/ProfileData/SampleProfReader.h b/llvm/include/llvm/ProfileData/SampleProfReader.h
index 93acad37315..b6ce620e39d 100644
--- a/llvm/include/llvm/ProfileData/SampleProfReader.h
+++ b/llvm/include/llvm/ProfileData/SampleProfReader.h
@@ -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,
diff --git a/llvm/lib/ProfileData/SampleProfReader.cpp b/llvm/lib/ProfileData/SampleProfReader.cpp
index 9efeb60c195..e309d5b270a 100644
--- a/llvm/lib/ProfileData/SampleProfReader.cpp
+++ b/llvm/lib/ProfileData/SampleProfReader.cpp
@@ -467,6 +467,31 @@ std::error_code SampleProfileReaderBinary::read() {
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 SampleProfileReaderExtBinaryBase::read() {
// 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;
}
OpenPOWER on IntegriCloud