[PATCH] D99110: [Coverage] Load records immediately
Choongwoo Han via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 22 16:16:13 PDT 2021
tunz updated this revision to Diff 332467.
tunz marked an inline comment as done.
tunz added a comment.
Addressing comments
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D99110/new/
https://reviews.llvm.org/D99110
Files:
llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
Index: llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
===================================================================
--- llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
+++ llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
@@ -281,11 +281,9 @@
return Error::success();
}
-Expected<std::unique_ptr<CoverageMapping>> CoverageMapping::load(
+Error CoverageMapping::loadFromReaders(
ArrayRef<std::unique_ptr<CoverageMappingReader>> CoverageReaders,
- IndexedInstrProfReader &ProfileReader) {
- auto Coverage = std::unique_ptr<CoverageMapping>(new CoverageMapping());
-
+ IndexedInstrProfReader &ProfileReader, CoverageMapping *Coverage) {
for (const auto &CoverageReader : CoverageReaders) {
for (auto RecordOrErr : *CoverageReader) {
if (Error E = RecordOrErr.takeError())
@@ -295,7 +293,15 @@
return std::move(E);
}
}
+ return Error::success();
+}
+Expected<std::unique_ptr<CoverageMapping>> CoverageMapping::load(
+ ArrayRef<std::unique_ptr<CoverageMappingReader>> CoverageReaders,
+ IndexedInstrProfReader &ProfileReader) {
+ auto Coverage = std::unique_ptr<CoverageMapping>(new CoverageMapping());
+ if (Error E = loadFromReaders(CoverageReaders, ProfileReader, Coverage.get()))
+ return std::move(E);
return std::move(Coverage);
}
@@ -316,9 +322,9 @@
if (Error E = ProfileReaderOrErr.takeError())
return std::move(E);
auto ProfileReader = std::move(ProfileReaderOrErr.get());
+ auto Coverage = std::unique_ptr<CoverageMapping>(new CoverageMapping());
+ bool DataFound = false;
- SmallVector<std::unique_ptr<CoverageMappingReader>, 4> Readers;
- SmallVector<std::unique_ptr<MemoryBuffer>, 4> Buffers;
for (const auto &File : llvm::enumerate(ObjectFilenames)) {
auto CovMappingBufOrErr = MemoryBuffer::getFileOrSTDIN(File.value());
if (std::error_code EC = CovMappingBufOrErr.getError())
@@ -326,6 +332,7 @@
StringRef Arch = Arches.empty() ? StringRef() : Arches[File.index()];
MemoryBufferRef CovMappingBufRef =
CovMappingBufOrErr.get()->getMemBufferRef();
+ SmallVector<std::unique_ptr<MemoryBuffer>, 4> Buffers;
auto CoverageReadersOrErr =
BinaryCoverageReader::create(CovMappingBufRef, Arch, Buffers);
if (Error E = CoverageReadersOrErr.takeError()) {
@@ -335,15 +342,19 @@
// E == success (originally a no_data_found error).
continue;
}
+
+ SmallVector<std::unique_ptr<CoverageMappingReader>, 4> Readers;
for (auto &Reader : CoverageReadersOrErr.get())
Readers.push_back(std::move(Reader));
- Buffers.push_back(std::move(CovMappingBufOrErr.get()));
+ DataFound |= !Readers.empty();
+ if (Error E = loadFromReaders(Readers, *ProfileReader, Coverage.get()))
+ return std::move(E);
}
// If no readers were created, either no objects were provided or none of them
// had coverage data. Return an error in the latter case.
- if (Readers.empty() && !ObjectFilenames.empty())
+ if (!DataFound && !ObjectFilenames.empty())
return make_error<CoverageMapError>(coveragemap_error::no_data_found);
- return load(Readers, *ProfileReader);
+ return std::move(Coverage);
}
namespace {
Index: llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
===================================================================
--- llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
+++ llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
@@ -573,6 +573,11 @@
CoverageMapping() = default;
+ // Load coverage records from readers.
+ static Error loadFromReaders(
+ ArrayRef<std::unique_ptr<CoverageMappingReader>> CoverageReaders,
+ IndexedInstrProfReader &ProfileReader, CoverageMapping *Coverage);
+
/// Add a function record corresponding to \p Record.
Error loadFunctionRecord(const CoverageMappingRecord &Record,
IndexedInstrProfReader &ProfileReader);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99110.332467.patch
Type: text/x-patch
Size: 3921 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210322/6b4eecc4/attachment.bin>
More information about the llvm-commits
mailing list