aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
diff options
context:
space:
mode:
authorNAKAMURA Takumi <geek4civic@gmail.com>2024-06-13 20:09:02 +0900
committerNAKAMURA Takumi <geek4civic@gmail.com>2024-06-14 19:31:56 +0900
commit71f8b441ed6a944ceb4530b49e8588dcbb1e0066 (patch)
treee03f6259e4ef7d0512f7c40238d2288f34ac210f /llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
parent1ceede3318c29af83b219cca137f5e2c563fc871 (diff)
downloadllvm-71f8b441ed6a944ceb4530b49e8588dcbb1e0066.zip
llvm-71f8b441ed6a944ceb4530b49e8588dcbb1e0066.tar.gz
llvm-71f8b441ed6a944ceb4530b49e8588dcbb1e0066.tar.bz2
Reapply: [MC/DC][Coverage] Loosen the limit of NumConds from 6 (#82448)
By storing possible test vectors instead of combinations of conditions, the restriction is dramatically relaxed. This introduces two options to `cc1`: * `-fmcdc-max-conditions=32767` * `-fmcdc-max-test-vectors=2147483646` This change makes coverage mapping, profraw, and profdata incompatible with Clang-18. - Bitmap semantics changed. It is incompatible with previous format. - `BitmapIdx` in `Decision` points to the end of the bitmap. - Bitmap is packed per function. - `llvm-cov` can understand `profdata` generated by `llvm-profdata-18`. RFC: https://discourse.llvm.org/t/rfc-coverage-new-algorithm-and-file-format-for-mc-dc/76798 -- Change(s) since llvmorg-19-init-14288-g7ead2d8c7e91 - Update compiler-rt/test/profile/ContinuousSyncMode/image-with-mcdc.c
Diffstat (limited to 'llvm/lib/ProfileData/Coverage/CoverageMapping.cpp')
-rw-r--r--llvm/lib/ProfileData/Coverage/CoverageMapping.cpp34
1 files changed, 23 insertions, 11 deletions
diff --git a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
index 8c81bbe8..455124e 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
@@ -384,15 +384,18 @@ class MCDCRecordProcessor : NextIDsBuilder, mcdc::TVIdxBuilder {
DenseSet<unsigned> TVIdxs;
#endif
+ bool IsVersion11;
+
public:
MCDCRecordProcessor(const BitVector &Bitmap,
const CounterMappingRegion &Region,
- ArrayRef<const CounterMappingRegion *> Branches)
+ ArrayRef<const CounterMappingRegion *> Branches,
+ bool IsVersion11)
: NextIDsBuilder(Branches), TVIdxBuilder(this->NextIDs), Bitmap(Bitmap),
Region(Region), DecisionParams(Region.getDecisionParams()),
Branches(Branches), NumConditions(DecisionParams.NumConditions),
Folded(NumConditions, false), IndependencePairs(NumConditions),
- ExecVectors(ExecVectorsByCond[false]) {}
+ ExecVectors(ExecVectorsByCond[false]), IsVersion11(IsVersion11) {}
private:
// Walk the binary decision diagram and try assigning both false and true to
@@ -415,7 +418,9 @@ private:
assert(TVIdx < SavedNodes[ID].Width);
assert(TVIdxs.insert(NextTVIdx).second && "Duplicate TVIdx");
- if (!Bitmap[DecisionParams.BitmapIdx * CHAR_BIT + TV.getIndex()])
+ if (!Bitmap[IsVersion11
+ ? DecisionParams.BitmapIdx * CHAR_BIT + TV.getIndex()
+ : DecisionParams.BitmapIdx - NumTestVectors + NextTVIdx])
continue;
// Copy the completed test vector to the vector of testvectors.
@@ -521,9 +526,9 @@ public:
Expected<MCDCRecord> CounterMappingContext::evaluateMCDCRegion(
const CounterMappingRegion &Region,
- ArrayRef<const CounterMappingRegion *> Branches) {
+ ArrayRef<const CounterMappingRegion *> Branches, bool IsVersion11) {
- MCDCRecordProcessor MCDCProcessor(Bitmap, Region, Branches);
+ MCDCRecordProcessor MCDCProcessor(Bitmap, Region, Branches, IsVersion11);
return MCDCProcessor.processMCDCRecord();
}
@@ -610,8 +615,8 @@ static unsigned getMaxCounterID(const CounterMappingContext &Ctx,
}
/// Returns the bit count
-static unsigned getMaxBitmapSize(const CounterMappingContext &Ctx,
- const CoverageMappingRecord &Record) {
+static unsigned getMaxBitmapSize(const CoverageMappingRecord &Record,
+ bool IsVersion11) {
unsigned MaxBitmapIdx = 0;
unsigned NumConditions = 0;
// Scan max(BitmapIdx).
@@ -626,8 +631,12 @@ static unsigned getMaxBitmapSize(const CounterMappingContext &Ctx,
NumConditions = DecisionParams.NumConditions;
}
}
- unsigned SizeInBits = llvm::alignTo(uint64_t(1) << NumConditions, CHAR_BIT);
- return MaxBitmapIdx * CHAR_BIT + SizeInBits;
+
+ if (IsVersion11)
+ MaxBitmapIdx = MaxBitmapIdx * CHAR_BIT +
+ llvm::alignTo(uint64_t(1) << NumConditions, CHAR_BIT);
+
+ return MaxBitmapIdx;
}
namespace {
@@ -815,6 +824,9 @@ Error CoverageMapping::loadFunctionRecord(
}
Ctx.setCounts(Counts);
+ bool IsVersion11 =
+ ProfileReader.getVersion() < IndexedInstrProf::ProfVersion::Version12;
+
BitVector Bitmap;
if (Error E = ProfileReader.getFunctionBitmap(Record.FunctionName,
Record.FunctionHash, Bitmap)) {
@@ -826,7 +838,7 @@ Error CoverageMapping::loadFunctionRecord(
}
if (IPE != instrprof_error::unknown_function)
return make_error<InstrProfError>(IPE);
- Bitmap = BitVector(getMaxBitmapSize(Ctx, Record));
+ Bitmap = BitVector(getMaxBitmapSize(Record, IsVersion11));
}
Ctx.setBitmap(std::move(Bitmap));
@@ -884,7 +896,7 @@ Error CoverageMapping::loadFunctionRecord(
// DecisionRegion, all of the information is now available to process.
// This is where the bulk of the MC/DC progressing takes place.
Expected<MCDCRecord> Record =
- Ctx.evaluateMCDCRegion(*MCDCDecision, MCDCBranches);
+ Ctx.evaluateMCDCRegion(*MCDCDecision, MCDCBranches, IsVersion11);
if (auto E = Record.takeError()) {
consumeError(std::move(E));
return Error::success();