Skip to content

Commit f74dec7

Browse files
committed
DecisionRow: Rework to reflect reviews
1 parent 1564424 commit f74dec7

File tree

1 file changed

+28
-35
lines changed

1 file changed

+28
-35
lines changed

llvm/lib/ProfileData/Coverage/CoverageMapping.cpp

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -596,56 +596,49 @@ struct DecisionRow {
596596
: DecisionRegion(&Decision), DecisionStartLoc(Decision.startLoc()),
597597
DecisionEndLoc(Decision.endLoc()) {}
598598

599-
bool insert(const CounterMappingRegion &Branch) {
600-
auto ID = Branch.MCDCParams.ID;
601-
if (ID == 1)
602-
Branches.insert(Branches.begin(), &Branch);
603-
else
604-
Branches.push_back(&Branch);
605-
IDs.insert(ID);
606-
return (Branches.size() == DecisionRegion->MCDCParams.NumConditions);
599+
bool inDecisionRegion(const CounterMappingRegion &R) {
600+
return (R.FileID == DecisionRegion->FileID &&
601+
R.startLoc() >= DecisionStartLoc && R.endLoc() <= DecisionEndLoc);
602+
}
603+
604+
bool inExpansions(const CounterMappingRegion &R) {
605+
return any_of(Expansions, [&](const auto &Expansion) {
606+
return (Expansion->ExpandedFileID == R.FileID);
607+
});
607608
}
608609

609610
enum class UpdateResult {
610611
NotFound = 0,
611612
Updated,
612-
Committed,
613+
Completed,
613614
};
614615

615616
UpdateResult updateBranch(const CounterMappingRegion &Branch) {
616-
if (IDs.contains(Branch.MCDCParams.ID))
617-
return UpdateResult::NotFound;
617+
auto ID = Branch.MCDCParams.ID;
618618

619-
if (Branch.FileID == DecisionRegion->FileID &&
620-
Branch.startLoc() >= DecisionStartLoc &&
621-
Branch.endLoc() <= DecisionEndLoc)
622-
return (insert(Branch) ? UpdateResult::Committed : UpdateResult::Updated);
619+
if (!IDs.contains(ID) &&
620+
(inDecisionRegion(Branch) || inExpansions(Branch))) {
621+
assert(Branches.size() < DecisionRegion->MCDCParams.NumConditions);
623622

624-
for (const auto *R : Expansions) {
625-
if (Branch.FileID == R->ExpandedFileID)
626-
return (insert(Branch) ? UpdateResult::Committed
627-
: UpdateResult::Updated);
628-
}
623+
if (ID == 1)
624+
Branches.insert(Branches.begin(), &Branch);
625+
else
626+
Branches.push_back(&Branch);
629627

630-
return UpdateResult::NotFound;
628+
IDs.insert(ID);
629+
return (Branches.size() == DecisionRegion->MCDCParams.NumConditions
630+
? UpdateResult::Completed
631+
: UpdateResult::Updated);
632+
} else
633+
return UpdateResult::NotFound;
631634
}
632635

633636
bool updateExpansion(const CounterMappingRegion &Expansion) {
634-
if (Expansion.FileID == DecisionRegion->FileID &&
635-
Expansion.startLoc() >= DecisionStartLoc &&
636-
Expansion.endLoc() <= DecisionEndLoc) {
637+
if (inDecisionRegion(Expansion) || inExpansions(Expansion)) {
637638
Expansions.push_back(&Expansion);
638639
return true;
639-
}
640-
641-
for (const auto *R : Expansions) {
642-
if (Expansion.FileID == R->ExpandedFileID) {
643-
Expansions.push_back(&Expansion);
644-
return true;
645-
}
646-
}
647-
648-
return false;
640+
} else
641+
return false;
649642
}
650643
};
651644

@@ -749,7 +742,7 @@ Error CoverageMapping::loadFunctionRecord(
749742
continue;
750743
case DecisionRow::UpdateResult::Updated:
751744
goto branch_found;
752-
case DecisionRow::UpdateResult::Committed:
745+
case DecisionRow::UpdateResult::Completed:
753746
// Evaluating the test vector bitmap for the decision region entails
754747
// calculating precisely what bits are pertinent to this region alone.
755748
// This is calculated based on the recorded offset into the global

0 commit comments

Comments
 (0)