Skip to content

Commit 3d9f968

Browse files
committed
llvm-cov: Split out sumRegions() from FunctionCoverageSummary::get(). NFC.
1 parent 8230b8a commit 3d9f968

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

llvm/tools/llvm-cov/CoverageSummaryInfo.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,11 @@ sumMCDCPairs(const ArrayRef<MCDCRecord> &Records) {
5959
return {NumPairs, CoveredPairs};
6060
}
6161

62-
FunctionCoverageSummary
63-
FunctionCoverageSummary::get(const CoverageMapping &CM,
64-
const coverage::FunctionRecord &Function) {
62+
static std::pair<RegionCoverageInfo, LineCoverageInfo>
63+
sumRegions(ArrayRef<CountedRegion> CodeRegions, const CoverageData &CD) {
6564
// Compute the region coverage.
6665
size_t NumCodeRegions = 0, CoveredRegions = 0;
67-
for (auto &CR : Function.CountedRegions) {
66+
for (auto &CR : CodeRegions) {
6867
if (CR.Kind != CounterMappingRegion::CodeRegion)
6968
continue;
7069
++NumCodeRegions;
@@ -74,7 +73,6 @@ FunctionCoverageSummary::get(const CoverageMapping &CM,
7473

7574
// Compute the line coverage
7675
size_t NumLines = 0, CoveredLines = 0;
77-
CoverageData CD = CM.getCoverageForFunction(Function);
7876
for (const auto &LCS : getLineCoverageStats(CD)) {
7977
if (!LCS.isMapped())
8078
continue;
@@ -83,6 +81,16 @@ FunctionCoverageSummary::get(const CoverageMapping &CM,
8381
++CoveredLines;
8482
}
8583

84+
return {RegionCoverageInfo(CoveredRegions, NumCodeRegions),
85+
LineCoverageInfo(CoveredLines, NumLines)};
86+
}
87+
88+
FunctionCoverageSummary
89+
FunctionCoverageSummary::get(const CoverageMapping &CM,
90+
const coverage::FunctionRecord &Function) {
91+
CoverageData CD = CM.getCoverageForFunction(Function);
92+
auto [RegionCoverage, LineCoverage] = sumRegions(Function.CountedRegions, CD);
93+
8694
// Compute the branch coverage, including branches from expansions.
8795
size_t NumBranches = 0, CoveredBranches = 0;
8896
sumBranches(NumBranches, CoveredBranches, CD.getBranches());
@@ -92,9 +100,7 @@ FunctionCoverageSummary::get(const CoverageMapping &CM,
92100
std::tie(NumPairs, CoveredPairs) = sumMCDCPairs(CD.getMCDCRecords());
93101

94102
return FunctionCoverageSummary(
95-
Function.Name, Function.ExecutionCount,
96-
RegionCoverageInfo(CoveredRegions, NumCodeRegions),
97-
LineCoverageInfo(CoveredLines, NumLines),
103+
Function.Name, Function.ExecutionCount, RegionCoverage, LineCoverage,
98104
BranchCoverageInfo(CoveredBranches, NumBranches),
99105
MCDCCoverageInfo(CoveredPairs, NumPairs));
100106
}

0 commit comments

Comments
 (0)