[llvm] r284063 - [Coverage] Factor out logic to create FunctionRecords (NFC)
Vedant Kumar via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 12 15:27:45 PDT 2016
Author: vedantk
Date: Wed Oct 12 17:27:45 2016
New Revision: 284063
URL: http://llvm.org/viewvc/llvm-project?rev=284063&view=rev
Log:
[Coverage] Factor out logic to create FunctionRecords (NFC)
Modified:
llvm/trunk/include/llvm/ProfileData/Coverage/CoverageMapping.h
llvm/trunk/lib/ProfileData/Coverage/CoverageMapping.cpp
Modified: llvm/trunk/include/llvm/ProfileData/Coverage/CoverageMapping.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/Coverage/CoverageMapping.h?rev=284063&r1=284062&r2=284063&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ProfileData/Coverage/CoverageMapping.h (original)
+++ llvm/trunk/include/llvm/ProfileData/Coverage/CoverageMapping.h Wed Oct 12 17:27:45 2016
@@ -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>>
Modified: llvm/trunk/lib/ProfileData/Coverage/CoverageMapping.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/Coverage/CoverageMapping.cpp?rev=284063&r1=284062&r2=284063&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/Coverage/CoverageMapping.cpp (original)
+++ llvm/trunk/lib/ProfileData/Coverage/CoverageMapping.cpp Wed Oct 12 17:27:45 2016
@@ -183,52 +183,57 @@ void FunctionRecordIterator::skipOtherFi
*this = FunctionRecordIterator();
}
-Expected<std::unique_ptr<CoverageMapping>>
-CoverageMapping::load(CoverageMappingReader &CoverageReader,
- IndexedInstrProfReader &ProfileReader) {
- auto Coverage = std::unique_ptr<CoverageMapping>(new CoverageMapping());
+Error CoverageMapping::loadFunctionRecord(
+ const CoverageMappingRecord &Record,
+ IndexedInstrProfReader &ProfileReader) {
+ CounterMappingContext Ctx(Record.Expressions);
std::vector<uint64_t> Counts;
- for (const auto &Record : CoverageReader) {
- CounterMappingContext Ctx(Record.Expressions);
+ if (Error E = ProfileReader.getFunctionCounts(Record.FunctionName,
+ Record.FunctionHash, Counts)) {
+ instrprof_error IPE = InstrProfError::take(std::move(E));
+ if (IPE == instrprof_error::hash_mismatch) {
+ MismatchedFunctionCount++;
+ return Error::success();
+ } else if (IPE != instrprof_error::unknown_function)
+ return make_error<InstrProfError>(IPE);
+ Counts.assign(Record.MappingRegions.size(), 0);
+ }
+ Ctx.setCounts(Counts);
+
+ assert(!Record.MappingRegions.empty() && "Function has no regions");
- Counts.clear();
- 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;
- } else if (IPE != instrprof_error::unknown_function)
- return make_error<InstrProfError>(IPE);
- Counts.assign(Record.MappingRegions.size(), 0);
+ StringRef OrigFuncName = Record.FunctionName;
+ if (Record.Filenames.empty())
+ OrigFuncName = getFuncNameWithoutPrefix(OrigFuncName);
+ else
+ 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));
+ return Error::success();
}
- Ctx.setCounts(Counts);
+ Function.pushRegion(Region, *ExecutionCount);
+ }
+ if (Function.CountedRegions.size() != Record.MappingRegions.size()) {
+ MismatchedFunctionCount++;
+ return Error::success();
+ }
- assert(!Record.MappingRegions.empty() && "Function has no regions");
+ Functions.push_back(std::move(Function));
+ return Error::success();
+}
- StringRef OrigFuncName = Record.FunctionName;
- if (Record.Filenames.empty())
- OrigFuncName = getFuncNameWithoutPrefix(OrigFuncName);
- else
- 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;
- }
- Function.pushRegion(Region, *ExecutionCount);
- }
- if (Function.CountedRegions.size() != Record.MappingRegions.size()) {
- Coverage->MismatchedFunctionCount++;
- continue;
- }
+Expected<std::unique_ptr<CoverageMapping>>
+CoverageMapping::load(CoverageMappingReader &CoverageReader,
+ IndexedInstrProfReader &ProfileReader) {
+ auto Coverage = std::unique_ptr<CoverageMapping>(new CoverageMapping());
- Coverage->Functions.push_back(std::move(Function));
- }
+ for (const auto &Record : CoverageReader)
+ if (Error E = Coverage->loadFunctionRecord(Record, ProfileReader))
+ return std::move(E);
return std::move(Coverage);
}
More information about the llvm-commits
mailing list