[llvm] r251546 - [PGO] RawProf Reader code cleanup
Xinliang David Li via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 28 12:34:04 PDT 2015
Author: davidxl
Date: Wed Oct 28 14:34:04 2015
New Revision: 251546
URL: http://llvm.org/viewvc/llvm-project?rev=251546&view=rev
Log:
[PGO] RawProf Reader code cleanup
Add a couple of helper methods to make the primary
raw profile reader interface's implementation more
readable. It also hides more format details. This
patch has no functional change.
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=251546&r1=251545&r2=251546&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ProfileData/InstrProfReader.h (original)
+++ llvm/trunk/include/llvm/ProfileData/InstrProfReader.h Wed Oct 28 14:34:04 2015
@@ -156,6 +156,13 @@ private:
IntT swap(IntT Int) const {
return ShouldSwapBytes ? sys::getSwappedBytes(Int) : Int;
}
+
+ std::error_code readName(InstrProfRecord &Record);
+ std::error_code readFuncHash(InstrProfRecord &Record);
+ std::error_code readRawCounts(InstrProfRecord &Record);
+ bool atEnd() const { return Data == DataEnd; }
+ void advanceData() { Data++; }
+
const uint64_t *getCounter(IntPtrT CounterPtr) const {
ptrdiff_t Offset = (swap(CounterPtr) - CountersDelta) / sizeof(uint64_t);
return CountersStart + Offset;
Modified: llvm/trunk/lib/ProfileData/InstrProfReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProfReader.cpp?rev=251546&r1=251545&r2=251546&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/InstrProfReader.cpp (original)
+++ llvm/trunk/lib/ProfileData/InstrProfReader.cpp Wed Oct 28 14:34:04 2015
@@ -220,30 +220,38 @@ std::error_code RawInstrProfReader<IntPt
}
template <class IntPtrT>
-std::error_code
-RawInstrProfReader<IntPtrT>::readNextRecord(InstrProfRecord &Record) {
- if (Data == DataEnd)
- if (std::error_code EC = readNextHeader(ProfileEnd))
- return EC;
+std::error_code RawInstrProfReader<IntPtrT>::readName(InstrProfRecord &Record) {
+ Record.Name = StringRef(getName(Data->NamePtr), swap(Data->NameSize));
+ if (Record.Name.data() < NamesStart ||
+ Record.Name.data() + Record.Name.size() > DataBuffer->getBufferEnd())
+ return error(instrprof_error::malformed);
+
+ return success();
+}
- // Get the raw data.
- StringRef RawName(getName(Data->NamePtr), swap(Data->NameSize));
+template <class IntPtrT>
+std::error_code RawInstrProfReader<IntPtrT>::readFuncHash(
+ InstrProfRecord &Record) {
+ Record.Hash = swap(Data->FuncHash);
+ return success();
+}
+
+template <class IntPtrT>
+std::error_code RawInstrProfReader<IntPtrT>::readRawCounts(
+ InstrProfRecord &Record) {
uint32_t NumCounters = swap(Data->NumCounters);
+ IntPtrT CounterPtr = Data->CounterPtr;
if (NumCounters == 0)
return error(instrprof_error::malformed);
- auto RawCounts = makeArrayRef(getCounter(Data->CounterPtr), NumCounters);
- // Check bounds.
+ auto RawCounts = makeArrayRef(getCounter(CounterPtr), NumCounters);
auto *NamesStartAsCounter = reinterpret_cast<const uint64_t *>(NamesStart);
- if (RawName.data() < NamesStart ||
- RawName.data() + RawName.size() > DataBuffer->getBufferEnd() ||
- RawCounts.data() < CountersStart ||
+
+ // Check bounds.
+ if (RawCounts.data() < CountersStart ||
RawCounts.data() + RawCounts.size() > NamesStartAsCounter)
return error(instrprof_error::malformed);
- // Store the data in Record, byte-swapping as necessary.
- Record.Hash = swap(Data->FuncHash);
- Record.Name = RawName;
if (ShouldSwapBytes) {
Record.Counts.clear();
Record.Counts.reserve(RawCounts.size());
@@ -252,8 +260,26 @@ RawInstrProfReader<IntPtrT>::readNextRec
} else
Record.Counts = RawCounts;
+ return success();
+}
+
+template <class IntPtrT>
+std::error_code RawInstrProfReader<IntPtrT>::readNextRecord(
+ InstrProfRecord &Record) {
+ if (atEnd())
+ if (std::error_code EC = readNextHeader(ProfileEnd)) return EC;
+
+ // Read name ad set it in Record.
+ if (std::error_code EC = readName(Record)) return EC;
+
+ // Read FuncHash and set it in Record.
+ if (std::error_code EC = readFuncHash(Record)) return EC;
+
+ // Read raw counts and set Record.
+ if (std::error_code EC = readRawCounts(Record)) return EC;
+
// Iterate.
- ++Data;
+ advanceData();
return success();
}
More information about the llvm-commits
mailing list