[Coverage] Factor out logic to create FunctionRecords (NFC)

llvm-svn: 284063
This commit is contained in:
Vedant Kumar 2016-10-12 22:27:45 +00:00
parent 85d54d6bcb
commit 68216d7bd3
2 changed files with 51 additions and 41 deletions

View File

@ -75,6 +75,7 @@ class IndexedInstrProfReader;
namespace coverage {
class CoverageMappingReader;
struct CoverageMappingRecord;
class CoverageMapping;
struct CounterExpressions;
@ -424,6 +425,10 @@ class CoverageMapping {
CoverageMapping() : MismatchedFunctionCount(0) {}
/// \brief Add a function record corresponding to \p Record.
Error loadFunctionRecord(const CoverageMappingRecord &Record,
IndexedInstrProfReader &ProfileReader);
public:
/// \brief Load the coverage mapping using the given readers.
static Expected<std::unique_ptr<CoverageMapping>>

View File

@ -183,22 +183,18 @@ void FunctionRecordIterator::skipOtherFiles() {
*this = FunctionRecordIterator();
}
Expected<std::unique_ptr<CoverageMapping>>
CoverageMapping::load(CoverageMappingReader &CoverageReader,
Error CoverageMapping::loadFunctionRecord(
const CoverageMappingRecord &Record,
IndexedInstrProfReader &ProfileReader) {
auto Coverage = std::unique_ptr<CoverageMapping>(new CoverageMapping());
std::vector<uint64_t> Counts;
for (const auto &Record : CoverageReader) {
CounterMappingContext Ctx(Record.Expressions);
Counts.clear();
if (Error E = ProfileReader.getFunctionCounts(
Record.FunctionName, Record.FunctionHash, Counts)) {
std::vector<uint64_t> Counts;
if (Error E = ProfileReader.getFunctionCounts(Record.FunctionName,
Record.FunctionHash, Counts)) {
instrprof_error IPE = InstrProfError::take(std::move(E));
if (IPE == instrprof_error::hash_mismatch) {
Coverage->MismatchedFunctionCount++;
continue;
MismatchedFunctionCount++;
return Error::success();
} else if (IPE != instrprof_error::unknown_function)
return make_error<InstrProfError>(IPE);
Counts.assign(Record.MappingRegions.size(), 0);
@ -211,24 +207,33 @@ CoverageMapping::load(CoverageMappingReader &CoverageReader,
if (Record.Filenames.empty())
OrigFuncName = getFuncNameWithoutPrefix(OrigFuncName);
else
OrigFuncName =
getFuncNameWithoutPrefix(OrigFuncName, Record.Filenames[0]);
OrigFuncName = getFuncNameWithoutPrefix(OrigFuncName, Record.Filenames[0]);
FunctionRecord Function(OrigFuncName, Record.Filenames);
for (const auto &Region : Record.MappingRegions) {
Expected<int64_t> ExecutionCount = Ctx.evaluate(Region.Count);
if (auto E = ExecutionCount.takeError()) {
llvm::consumeError(std::move(E));
break;
return Error::success();
}
Function.pushRegion(Region, *ExecutionCount);
}
if (Function.CountedRegions.size() != Record.MappingRegions.size()) {
Coverage->MismatchedFunctionCount++;
continue;
MismatchedFunctionCount++;
return Error::success();
}
Coverage->Functions.push_back(std::move(Function));
}
Functions.push_back(std::move(Function));
return Error::success();
}
Expected<std::unique_ptr<CoverageMapping>>
CoverageMapping::load(CoverageMappingReader &CoverageReader,
IndexedInstrProfReader &ProfileReader) {
auto Coverage = std::unique_ptr<CoverageMapping>(new CoverageMapping());
for (const auto &Record : CoverageReader)
if (Error E = Coverage->loadFunctionRecord(Record, ProfileReader))
return std::move(E);
return std::move(Coverage);
}