summaryrefslogtreecommitdiffstats
path: root/llvm/lib/ProfileData/CoverageMappingReader.cpp
diff options
context:
space:
mode:
authorXinliang David Li <davidxl@google.com>2016-01-13 04:36:15 +0000
committerXinliang David Li <davidxl@google.com>2016-01-13 04:36:15 +0000
commit81f18a58f1ccf52dd9225e82b7e90169f2ffb864 (patch)
tree520c559e07a1503aaa8abffad458ed28e3c00148 /llvm/lib/ProfileData/CoverageMappingReader.cpp
parent25d84580f4875364bfa5c6505039c80f0df0eb26 (diff)
downloadbcm5719-llvm-81f18a58f1ccf52dd9225e82b7e90169f2ffb864.tar.gz
bcm5719-llvm-81f18a58f1ccf52dd9225e82b7e90169f2ffb864.zip
[Coverage] Refactor coverage mapping reader code
(Resubmit after fixing a typo that breaks test on big endian machines) In this refactoring, member functions are introduced to access CovMap header/func record members and hide layout details. This will enable further code restructuring to support reading multiple versions of coverage mapping data with shared/templatized code. (When coveremap format version changes, backward compatibtility should be preserved). llvm-svn: 257571
Diffstat (limited to 'llvm/lib/ProfileData/CoverageMappingReader.cpp')
-rw-r--r--llvm/lib/ProfileData/CoverageMappingReader.cpp30
1 files changed, 13 insertions, 17 deletions
diff --git a/llvm/lib/ProfileData/CoverageMappingReader.cpp b/llvm/lib/ProfileData/CoverageMappingReader.cpp
index af6c616fa03..89e1cf42c57 100644
--- a/llvm/lib/ProfileData/CoverageMappingReader.cpp
+++ b/llvm/lib/ProfileData/CoverageMappingReader.cpp
@@ -319,13 +319,10 @@ static std::error_code readCoverageMappingData(
if (Buf + sizeof(CovMapHeader) > End)
return coveragemap_error::malformed;
auto CovHeader = reinterpret_cast<const coverage::CovMapHeader *>(Buf);
- uint32_t NRecords =
- endian::byte_swap<uint32_t, Endian>(CovHeader->NRecords);
- uint32_t FilenamesSize =
- endian::byte_swap<uint32_t, Endian>(CovHeader->FilenamesSize);
- uint32_t CoverageSize =
- endian::byte_swap<uint32_t, Endian>(CovHeader->CoverageSize);
- uint32_t Version = endian::byte_swap<uint32_t, Endian>(CovHeader->Version);
+ uint32_t NRecords = CovHeader->getNRecords<Endian>();
+ uint32_t FilenamesSize = CovHeader->getFilenamesSize<Endian>();
+ uint32_t CoverageSize = CovHeader->getCoverageSize<Endian>();
+ uint32_t Version = CovHeader->getVersion<Endian>();
Buf = reinterpret_cast<const char *>(++CovHeader);
if (Version > coverage::CoverageMappingCurrentVersion)
@@ -360,11 +357,8 @@ static std::error_code readCoverageMappingData(
reinterpret_cast<const coverage::CovMapFunctionRecord<T> *>(FunBuf);
while ((const char *)CFR < FunEnd) {
// Read the function information
- T NamePtr = endian::byte_swap<T, Endian>(CFR->NamePtr);
- uint32_t NameSize = endian::byte_swap<uint32_t, Endian>(CFR->NameSize);
- uint32_t DataSize = endian::byte_swap<uint32_t, Endian>(CFR->DataSize);
- uint64_t FuncHash = endian::byte_swap<uint64_t, Endian>(CFR->FuncHash);
- CFR++;
+ uint32_t DataSize = CFR->template getDataSize<Endian>();
+ uint64_t FuncHash = CFR->template getFuncHash<Endian>();
// Now use that to read the coverage data.
if (CovBuf + DataSize > CovEnd)
@@ -375,16 +369,18 @@ static std::error_code readCoverageMappingData(
// Ignore this record if we already have a record that points to the same
// function name. This is useful to ignore the redundant records for the
// functions with ODR linkage.
- if (!UniqueFunctionMappingData.insert(NamePtr).second)
+ T NameRef = CFR->template getFuncNameRef<Endian>();
+ if (!UniqueFunctionMappingData.insert(NameRef).second)
continue;
- // Finally, grab the name and create a record.
- StringRef FuncName = ProfileNames.getFuncName(NamePtr, NameSize);
- if (NameSize && FuncName.empty())
- return coveragemap_error::malformed;
+ StringRef FuncName;
+ if (std::error_code EC =
+ CFR->template getFuncName<Endian>(ProfileNames, FuncName))
+ return EC;
Records.push_back(BinaryCoverageReader::ProfileMappingRecord(
CoverageMappingVersion(Version), FuncName, FuncHash, Mapping,
FilenamesBegin, Filenames.size() - FilenamesBegin));
+ CFR++;
}
}
OpenPOWER on IntegriCloud