@@ -1343,6 +1343,37 @@ class SegmentBuilder {
1343
1343
}
1344
1344
};
1345
1345
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
+ };
1346
1377
} // end anonymous namespace
1347
1378
1348
1379
std::vector<StringRef> CoverageMapping::getUniqueSourceFiles () const {
@@ -1394,8 +1425,7 @@ static bool isExpansion(const CountedRegion &R, unsigned FileID) {
1394
1425
1395
1426
CoverageData CoverageMapping::getCoverageForFile (StringRef Filename) const {
1396
1427
assert (SingleByteCoverage);
1397
- CoverageData FileCoverage (*SingleByteCoverage, Filename);
1398
- std::vector<CountedRegion> Regions;
1428
+ MergeableCoverageData FileCoverage (*SingleByteCoverage, Filename);
1399
1429
1400
1430
// Look up the function records in the given file. Due to hash collisions on
1401
1431
// the filename, we may get back some records that are not in the file.
@@ -1405,26 +1435,14 @@ CoverageData CoverageMapping::getCoverageForFile(StringRef Filename) const {
1405
1435
const FunctionRecord &Function = Functions[RecordIndex];
1406
1436
auto MainFileID = findMainViewFileID (Filename, Function);
1407
1437
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)); });
1422
1441
}
1423
1442
1424
1443
LLVM_DEBUG (dbgs () << " Emitting segments for file: " << Filename << " \n " );
1425
- FileCoverage.Segments = SegmentBuilder::buildSegments (Regions);
1426
1444
1427
- return FileCoverage;
1445
+ return FileCoverage. buildSegments () ;
1428
1446
}
1429
1447
1430
1448
std::vector<InstantiationGroup>
@@ -1459,30 +1477,16 @@ CoverageMapping::getCoverageForFunction(const FunctionRecord &Function) const {
1459
1477
return CoverageData ();
1460
1478
1461
1479
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); });
1480
1485
1481
1486
LLVM_DEBUG (dbgs () << " Emitting segments for function: " << Function.Name
1482
1487
<< " \n " );
1483
- FunctionCoverage.Segments = SegmentBuilder::buildSegments (Regions);
1484
1488
1485
- return FunctionCoverage;
1489
+ return FunctionCoverage. buildSegments () ;
1486
1490
}
1487
1491
1488
1492
CoverageData CoverageMapping::getCoverageForExpansion (
0 commit comments