Skip to content

Commit c33e898

Browse files
committed
Merge branch 'users/chapuni/cov/single/unify' into users/chapuni/cov/merge/mcdcsort-base
2 parents ad6726d + 10517c4 commit c33e898

File tree

2 files changed

+45
-38
lines changed

2 files changed

+45
-38
lines changed

llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,7 @@ class InstantiationGroup {
891891
class CoverageData {
892892
friend class CoverageMapping;
893893

894+
protected:
894895
std::string Filename;
895896
std::vector<CoverageSegment> Segments;
896897
std::vector<ExpansionRecord> Expansions;
@@ -905,6 +906,8 @@ class CoverageData {
905906
CoverageData(bool Single, StringRef Filename)
906907
: Filename(Filename), SingleByteCoverage(Single) {}
907908

909+
CoverageData(CoverageData &&RHS) = default;
910+
908911
/// Get the name of the file this data covers.
909912
StringRef getFilename() const { return Filename; }
910913

llvm/lib/ProfileData/Coverage/CoverageMapping.cpp

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,6 +1343,37 @@ class SegmentBuilder {
13431343
}
13441344
};
13451345

1346+
struct MergeableCoverageData : public CoverageData {
1347+
std::vector<CountedRegion> CodeRegions;
1348+
1349+
MergeableCoverageData(bool Single, StringRef Filename)
1350+
: CoverageData(Single, Filename) {}
1351+
1352+
void addFunctionRegions(
1353+
const FunctionRecord &Function,
1354+
std::function<bool(const CounterMappingRegion &CR)> shouldProcess,
1355+
std::function<bool(const CountedRegion &CR)> shouldExpand) {
1356+
for (const auto &CR : Function.CountedRegions)
1357+
if (shouldProcess(CR)) {
1358+
CodeRegions.push_back(CR);
1359+
if (shouldExpand(CR))
1360+
Expansions.emplace_back(CR, Function);
1361+
}
1362+
// Capture branch regions specific to the function (excluding expansions).
1363+
for (const auto &CR : Function.CountedBranchRegions)
1364+
if (shouldProcess(CR))
1365+
BranchRegions.push_back(CR);
1366+
// Capture MCDC records specific to the function.
1367+
for (const auto &MR : Function.MCDCRecords)
1368+
if (shouldProcess(MR.getDecisionRegion()))
1369+
MCDCRecords.push_back(MR);
1370+
}
1371+
1372+
CoverageData buildSegments() {
1373+
Segments = SegmentBuilder::buildSegments(CodeRegions);
1374+
return CoverageData(std::move(*this));
1375+
}
1376+
};
13461377
} // end anonymous namespace
13471378

13481379
std::vector<StringRef> CoverageMapping::getUniqueSourceFiles() const {
@@ -1394,8 +1425,7 @@ static bool isExpansion(const CountedRegion &R, unsigned FileID) {
13941425

13951426
CoverageData CoverageMapping::getCoverageForFile(StringRef Filename) const {
13961427
assert(SingleByteCoverage);
1397-
CoverageData FileCoverage(*SingleByteCoverage, Filename);
1398-
std::vector<CountedRegion> Regions;
1428+
MergeableCoverageData FileCoverage(*SingleByteCoverage, Filename);
13991429

14001430
// Look up the function records in the given file. Due to hash collisions on
14011431
// the filename, we may get back some records that are not in the file.
@@ -1405,26 +1435,14 @@ CoverageData CoverageMapping::getCoverageForFile(StringRef Filename) const {
14051435
const FunctionRecord &Function = Functions[RecordIndex];
14061436
auto MainFileID = findMainViewFileID(Filename, Function);
14071437
auto FileIDs = gatherFileIDs(Filename, Function);
1408-
for (const auto &CR : Function.CountedRegions)
1409-
if (FileIDs.test(CR.FileID)) {
1410-
Regions.push_back(CR);
1411-
if (MainFileID && isExpansion(CR, *MainFileID))
1412-
FileCoverage.Expansions.emplace_back(CR, Function);
1413-
}
1414-
// Capture branch regions specific to the function (excluding expansions).
1415-
for (const auto &CR : Function.CountedBranchRegions)
1416-
if (FileIDs.test(CR.FileID))
1417-
FileCoverage.BranchRegions.push_back(CR);
1418-
// Capture MCDC records specific to the function.
1419-
for (const auto &MR : Function.MCDCRecords)
1420-
if (FileIDs.test(MR.getDecisionRegion().FileID))
1421-
FileCoverage.MCDCRecords.push_back(MR);
1438+
FileCoverage.addFunctionRegions(
1439+
Function, [&](auto &CR) { return FileIDs.test(CR.FileID); },
1440+
[&](auto &CR) { return (MainFileID && isExpansion(CR, *MainFileID)); });
14221441
}
14231442

14241443
LLVM_DEBUG(dbgs() << "Emitting segments for file: " << Filename << "\n");
1425-
FileCoverage.Segments = SegmentBuilder::buildSegments(Regions);
14261444

1427-
return FileCoverage;
1445+
return FileCoverage.buildSegments();
14281446
}
14291447

14301448
std::vector<InstantiationGroup>
@@ -1459,30 +1477,16 @@ CoverageMapping::getCoverageForFunction(const FunctionRecord &Function) const {
14591477
return CoverageData();
14601478

14611479
assert(SingleByteCoverage);
1462-
CoverageData FunctionCoverage(*SingleByteCoverage,
1463-
Function.Filenames[*MainFileID]);
1464-
std::vector<CountedRegion> Regions;
1465-
for (const auto &CR : Function.CountedRegions)
1466-
if (CR.FileID == *MainFileID) {
1467-
Regions.push_back(CR);
1468-
if (isExpansion(CR, *MainFileID))
1469-
FunctionCoverage.Expansions.emplace_back(CR, Function);
1470-
}
1471-
// Capture branch regions specific to the function (excluding expansions).
1472-
for (const auto &CR : Function.CountedBranchRegions)
1473-
if (CR.FileID == *MainFileID)
1474-
FunctionCoverage.BranchRegions.push_back(CR);
1475-
1476-
// Capture MCDC records specific to the function.
1477-
for (const auto &MR : Function.MCDCRecords)
1478-
if (MR.getDecisionRegion().FileID == *MainFileID)
1479-
FunctionCoverage.MCDCRecords.push_back(MR);
1480+
MergeableCoverageData FunctionCoverage(*SingleByteCoverage,
1481+
Function.Filenames[*MainFileID]);
1482+
FunctionCoverage.addFunctionRegions(
1483+
Function, [&](auto &CR) { return (CR.FileID == *MainFileID); },
1484+
[&](auto &CR) { return isExpansion(CR, *MainFileID); });
14801485

14811486
LLVM_DEBUG(dbgs() << "Emitting segments for function: " << Function.Name
14821487
<< "\n");
1483-
FunctionCoverage.Segments = SegmentBuilder::buildSegments(Regions);
14841488

1485-
return FunctionCoverage;
1489+
return FunctionCoverage.buildSegments();
14861490
}
14871491

14881492
CoverageData CoverageMapping::getCoverageForExpansion(

0 commit comments

Comments
 (0)