Skip to content

Commit 425185c

Browse files
committed
Add comments to the upper half.
1 parent f74dec7 commit 425185c

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

llvm/lib/ProfileData/Coverage/CoverageMapping.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,24 +583,37 @@ static unsigned getMaxBitmapSize(const CounterMappingContext &Ctx,
583583
return MaxBitmapID + (SizeInBits / CHAR_BIT);
584584
}
585585

586+
/// This holds the DecisionRegion and MCDCBranch(es) under it.
587+
/// Also traverses Expansion(s).
586588
struct DecisionRow {
589+
/// The subject
587590
const CounterMappingRegion *DecisionRegion;
591+
592+
/// They are reflected from `DecisionRegion` for convenience.
588593
LineColPair DecisionStartLoc;
589594
LineColPair DecisionEndLoc;
590595

596+
/// This is passed to `MCDCRecordProcessor`, so this should be compatible to
597+
/// `ArrayRef<const CounterMappingRegion *>`.
591598
SmallVector<const CounterMappingRegion *, 6> Branches;
599+
600+
/// Each `ID` in `Branches` should be unique.
592601
DenseSet<CounterMappingRegion::MCDCConditionID> IDs;
602+
603+
/// Relevant `Expansion`(s) should be caught to find expanded Branches.
593604
SmallVector<const CounterMappingRegion *> Expansions;
594605

595606
DecisionRow(const CounterMappingRegion &Decision)
596607
: DecisionRegion(&Decision), DecisionStartLoc(Decision.startLoc()),
597608
DecisionEndLoc(Decision.endLoc()) {}
598609

610+
/// Determine whether `R` is included in `DecisionRegion`.
599611
bool inDecisionRegion(const CounterMappingRegion &R) {
600612
return (R.FileID == DecisionRegion->FileID &&
601613
R.startLoc() >= DecisionStartLoc && R.endLoc() <= DecisionEndLoc);
602614
}
603615

616+
/// Determin whether `R` is pointed by any of Expansions.
604617
bool inExpansions(const CounterMappingRegion &R) {
605618
return any_of(Expansions, [&](const auto &Expansion) {
606619
return (Expansion->ExpandedFileID == R.FileID);
@@ -613,26 +626,35 @@ struct DecisionRow {
613626
Completed,
614627
};
615628

629+
/// Add `Branch` into the Decision
616630
UpdateResult updateBranch(const CounterMappingRegion &Branch) {
617631
auto ID = Branch.MCDCParams.ID;
632+
assert(ID > 0 && "MCDCBranch.ID should begin with 1");
618633

619634
if (!IDs.contains(ID) &&
620635
(inDecisionRegion(Branch) || inExpansions(Branch))) {
621636
assert(Branches.size() < DecisionRegion->MCDCParams.NumConditions);
622637

638+
// Put `ID=1` in front of `Branches` for convenience
639+
// even if `Branches` is not topological.
623640
if (ID == 1)
624641
Branches.insert(Branches.begin(), &Branch);
625642
else
626643
Branches.push_back(&Branch);
627644

645+
// Mark `ID` as `assigned`.
628646
IDs.insert(ID);
647+
648+
// `Completed` when `Branches` is full
629649
return (Branches.size() == DecisionRegion->MCDCParams.NumConditions
630650
? UpdateResult::Completed
631651
: UpdateResult::Updated);
632652
} else
633653
return UpdateResult::NotFound;
634654
}
635655

656+
/// Record `Expansion` if it is dominated to the Decision.
657+
/// Each `Expansion` may nest.
636658
bool updateExpansion(const CounterMappingRegion &Expansion) {
637659
if (inDecisionRegion(Expansion) || inExpansions(Expansion)) {
638660
Expansions.push_back(&Expansion);
@@ -702,6 +724,7 @@ Error CoverageMapping::loadFunctionRecord(
702724
FunctionRecord Function(OrigFuncName, Record.Filenames);
703725
for (const auto &Region : Record.MappingRegions) {
704726
if (Region.Kind == CounterMappingRegion::MCDCDecisionRegion) {
727+
// Start recording `Region` as the `Decision`
705728
Decisions.emplace_back(Region);
706729
continue;
707730
}

0 commit comments

Comments
 (0)