summaryrefslogtreecommitdiffstats
path: root/llvm/lib/ProfileData
diff options
context:
space:
mode:
authorXinliang David Li <davidxl@google.com>2015-10-28 19:34:04 +0000
committerXinliang David Li <davidxl@google.com>2015-10-28 19:34:04 +0000
commitcf4a128c6e560a60c6ea6a8f77a48650e24eb768 (patch)
tree6e81e2aa8eca5559d198725b9a2de24530c4c095 /llvm/lib/ProfileData
parentfe44b10735036aa0b60a690897445938e65e2a62 (diff)
downloadbcm5719-llvm-cf4a128c6e560a60c6ea6a8f77a48650e24eb768.tar.gz
bcm5719-llvm-cf4a128c6e560a60c6ea6a8f77a48650e24eb768.zip
[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. llvm-svn: 251546
Diffstat (limited to 'llvm/lib/ProfileData')
-rw-r--r--llvm/lib/ProfileData/InstrProfReader.cpp58
1 files changed, 42 insertions, 16 deletions
diff --git a/llvm/lib/ProfileData/InstrProfReader.cpp b/llvm/lib/ProfileData/InstrProfReader.cpp
index 838ec0f29ca..a80fc5619ce 100644
--- a/llvm/lib/ProfileData/InstrProfReader.cpp
+++ b/llvm/lib/ProfileData/InstrProfReader.cpp
@@ -220,30 +220,38 @@ std::error_code RawInstrProfReader<IntPtrT>::readHeader(
}
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);
- // Get the raw data.
- StringRef RawName(getName(Data->NamePtr), swap(Data->NameSize));
+ return success();
+}
+
+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>::readNextRecord(InstrProfRecord &Record) {
} 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();
}
OpenPOWER on IntegriCloud