@@ -1343,6 +1343,36 @@ class SegmentBuilder {
1343
1343
}
1344
1344
};
1345
1345
1346
+ struct MergeableCoverageData : public CoverageData {
1347
+ std::vector<CountedRegion> CodeRegions;
1348
+
1349
+ MergeableCoverageData (StringRef Filename) : CoverageData(Filename) {}
1350
+
1351
+ void addFunctionRegions (
1352
+ const FunctionRecord &Function,
1353
+ std::function<bool (const CounterMappingRegion &CR)> shouldProcess,
1354
+ std::function<bool(const CountedRegion &CR)> shouldExpand) {
1355
+ for (const auto &CR : Function.CountedRegions )
1356
+ if (shouldProcess (CR)) {
1357
+ CodeRegions.push_back (CR);
1358
+ if (shouldExpand (CR))
1359
+ Expansions.emplace_back (CR, Function);
1360
+ }
1361
+ // Capture branch regions specific to the function (excluding expansions).
1362
+ for (const auto &CR : Function.CountedBranchRegions )
1363
+ if (shouldProcess (CR))
1364
+ BranchRegions.push_back (CR);
1365
+ // Capture MCDC records specific to the function.
1366
+ for (const auto &MR : Function.MCDCRecords )
1367
+ if (shouldProcess (MR.getDecisionRegion ()))
1368
+ MCDCRecords.push_back (MR);
1369
+ }
1370
+
1371
+ CoverageData buildSegments () {
1372
+ Segments = SegmentBuilder::buildSegments (CodeRegions);
1373
+ return CoverageData (std::move (*this ));
1374
+ }
1375
+ };
1346
1376
} // end anonymous namespace
1347
1377
1348
1378
std::vector<StringRef> CoverageMapping::getUniqueSourceFiles () const {
@@ -1393,8 +1423,7 @@ static bool isExpansion(const CountedRegion &R, unsigned FileID) {
1393
1423
}
1394
1424
1395
1425
CoverageData CoverageMapping::getCoverageForFile (StringRef Filename) const {
1396
- CoverageData FileCoverage (Filename);
1397
- std::vector<CountedRegion> Regions;
1426
+ MergeableCoverageData FileCoverage (Filename);
1398
1427
1399
1428
// Look up the function records in the given file. Due to hash collisions on
1400
1429
// the filename, we may get back some records that are not in the file.
@@ -1404,26 +1433,14 @@ CoverageData CoverageMapping::getCoverageForFile(StringRef Filename) const {
1404
1433
const FunctionRecord &Function = Functions[RecordIndex];
1405
1434
auto MainFileID = findMainViewFileID (Filename, Function);
1406
1435
auto FileIDs = gatherFileIDs (Filename, Function);
1407
- for (const auto &CR : Function.CountedRegions )
1408
- if (FileIDs.test (CR.FileID )) {
1409
- Regions.push_back (CR);
1410
- if (MainFileID && isExpansion (CR, *MainFileID))
1411
- FileCoverage.Expansions .emplace_back (CR, Function);
1412
- }
1413
- // Capture branch regions specific to the function (excluding expansions).
1414
- for (const auto &CR : Function.CountedBranchRegions )
1415
- if (FileIDs.test (CR.FileID ))
1416
- FileCoverage.BranchRegions .push_back (CR);
1417
- // Capture MCDC records specific to the function.
1418
- for (const auto &MR : Function.MCDCRecords )
1419
- if (FileIDs.test (MR.getDecisionRegion ().FileID ))
1420
- FileCoverage.MCDCRecords .push_back (MR);
1436
+ FileCoverage.addFunctionRegions (
1437
+ Function, [&](auto &CR) { return FileIDs.test (CR.FileID ); },
1438
+ [&](auto &CR) { return (MainFileID && isExpansion (CR, *MainFileID)); });
1421
1439
}
1422
1440
1423
1441
LLVM_DEBUG (dbgs () << " Emitting segments for file: " << Filename << " \n " );
1424
- FileCoverage.Segments = SegmentBuilder::buildSegments (Regions);
1425
1442
1426
- return FileCoverage;
1443
+ return FileCoverage. buildSegments () ;
1427
1444
}
1428
1445
1429
1446
std::vector<InstantiationGroup>
@@ -1457,29 +1474,15 @@ CoverageMapping::getCoverageForFunction(const FunctionRecord &Function) const {
1457
1474
if (!MainFileID)
1458
1475
return CoverageData ();
1459
1476
1460
- CoverageData FunctionCoverage (Function.Filenames [*MainFileID]);
1461
- std::vector<CountedRegion> Regions;
1462
- for (const auto &CR : Function.CountedRegions )
1463
- if (CR.FileID == *MainFileID) {
1464
- Regions.push_back (CR);
1465
- if (isExpansion (CR, *MainFileID))
1466
- FunctionCoverage.Expansions .emplace_back (CR, Function);
1467
- }
1468
- // Capture branch regions specific to the function (excluding expansions).
1469
- for (const auto &CR : Function.CountedBranchRegions )
1470
- if (CR.FileID == *MainFileID)
1471
- FunctionCoverage.BranchRegions .push_back (CR);
1472
-
1473
- // Capture MCDC records specific to the function.
1474
- for (const auto &MR : Function.MCDCRecords )
1475
- if (MR.getDecisionRegion ().FileID == *MainFileID)
1476
- FunctionCoverage.MCDCRecords .push_back (MR);
1477
+ MergeableCoverageData FunctionCoverage (Function.Filenames [*MainFileID]);
1478
+ FunctionCoverage.addFunctionRegions (
1479
+ Function, [&](auto &CR) { return (CR.FileID == *MainFileID); },
1480
+ [&](auto &CR) { return isExpansion (CR, *MainFileID); });
1477
1481
1478
1482
LLVM_DEBUG (dbgs () << " Emitting segments for function: " << Function.Name
1479
1483
<< " \n " );
1480
- FunctionCoverage.Segments = SegmentBuilder::buildSegments (Regions);
1481
1484
1482
- return FunctionCoverage;
1485
+ return FunctionCoverage. buildSegments () ;
1483
1486
}
1484
1487
1485
1488
CoverageData CoverageMapping::getCoverageForExpansion (
0 commit comments