aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
diff options
context:
space:
mode:
authorNAKAMURA Takumi <geek4civic@gmail.com>2024-01-23 07:28:10 +0900
committerGitHub <noreply@github.com>2024-01-23 07:28:10 +0900
commitfe0ec2c91cfbf2aad2a61e402f21b771db685b90 (patch)
treed909f7b4ba81f6dfd93e3c66b9dac8fac341ff12 /llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
parenteaef645a5836df56b53800383022a3a384305c6b (diff)
downloadllvm-fe0ec2c91cfbf2aad2a61e402f21b771db685b90.zip
llvm-fe0ec2c91cfbf2aad2a61e402f21b771db685b90.tar.gz
llvm-fe0ec2c91cfbf2aad2a61e402f21b771db685b90.tar.bz2
[Coverage] Const-ize `MCDCRecordProcessor` stuff (#78918)
The life of `MCDCRecordProcessor`'s instance is short. It may accept `const` objects to process. On the other hand, the life of `MCDCBranches` is shorter than `Record`. It may be rewritten with reference, rather than copying.
Diffstat (limited to 'llvm/lib/ProfileData/Coverage/CoverageMapping.cpp')
-rw-r--r--llvm/lib/ProfileData/Coverage/CoverageMapping.cpp32
1 files changed, 17 insertions, 15 deletions
diff --git a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
index d8be7be..9c95cd5 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
@@ -247,14 +247,14 @@ class MCDCRecordProcessor {
/// Each index of the bitmap corresponds to a possible test vector. An index
/// with a bit value of '1' indicates that the corresponding Test Vector
/// identified by that index was executed.
- BitVector &ExecutedTestVectorBitmap;
+ const BitVector &ExecutedTestVectorBitmap;
/// Decision Region to which the ExecutedTestVectorBitmap applies.
- CounterMappingRegion &Region;
+ const CounterMappingRegion &Region;
/// Array of branch regions corresponding each conditions in the boolean
/// expression.
- ArrayRef<CounterMappingRegion> Branches;
+ ArrayRef<const CounterMappingRegion *> Branches;
/// Total number of conditions in the boolean expression.
unsigned NumConditions;
@@ -276,8 +276,9 @@ class MCDCRecordProcessor {
MCDCRecord::TestVectors ExecVectors;
public:
- MCDCRecordProcessor(BitVector &Bitmap, CounterMappingRegion &Region,
- ArrayRef<CounterMappingRegion> Branches)
+ MCDCRecordProcessor(const BitVector &Bitmap,
+ const CounterMappingRegion &Region,
+ ArrayRef<const CounterMappingRegion *> Branches)
: ExecutedTestVectorBitmap(Bitmap), Region(Region), Branches(Branches),
NumConditions(Region.MCDCParams.NumConditions),
Folded(NumConditions, false), IndependencePairs(NumConditions),
@@ -342,7 +343,7 @@ private:
/// Walk the bits in the bitmap. A bit set to '1' indicates that the test
/// vector at the corresponding index was executed during a test run.
- void findExecutedTestVectors(BitVector &ExecutedTestVectorBitmap) {
+ void findExecutedTestVectors(const BitVector &ExecutedTestVectorBitmap) {
for (unsigned Idx = 0; Idx < ExecutedTestVectorBitmap.size(); ++Idx) {
if (ExecutedTestVectorBitmap[Idx] == 0)
continue;
@@ -445,11 +446,11 @@ public:
// visualize where the condition is.
// - Record whether the condition is constant folded so that we exclude it
// from being measured.
- for (const auto &B : Branches) {
- Map[B.MCDCParams.ID] = &B;
- PosToID[I] = B.MCDCParams.ID - 1;
- CondLoc[I] = B.startLoc();
- Folded[I++] = (B.Count.isZero() && B.FalseCount.isZero());
+ for (const auto *B : Branches) {
+ Map[B->MCDCParams.ID] = B;
+ PosToID[I] = B->MCDCParams.ID - 1;
+ CondLoc[I] = B->startLoc();
+ Folded[I++] = (B->Count.isZero() && B->FalseCount.isZero());
}
// Initialize a base test vector as 'DontCare'.
@@ -473,8 +474,9 @@ public:
};
Expected<MCDCRecord> CounterMappingContext::evaluateMCDCRegion(
- CounterMappingRegion Region, BitVector ExecutedTestVectorBitmap,
- ArrayRef<CounterMappingRegion> Branches) {
+ const CounterMappingRegion &Region,
+ const BitVector &ExecutedTestVectorBitmap,
+ ArrayRef<const CounterMappingRegion *> Branches) {
MCDCRecordProcessor MCDCProcessor(ExecutedTestVectorBitmap, Region, Branches);
return MCDCProcessor.processMCDCRecord();
@@ -638,7 +640,7 @@ Error CoverageMapping::loadFunctionRecord(
unsigned NumConds = 0;
const CounterMappingRegion *MCDCDecision;
- std::vector<CounterMappingRegion> MCDCBranches;
+ std::vector<const CounterMappingRegion *> MCDCBranches;
FunctionRecord Function(OrigFuncName, Record.Filenames);
for (const auto &Region : Record.MappingRegions) {
@@ -666,7 +668,7 @@ Error CoverageMapping::loadFunctionRecord(
// correspond to it in a vector, according to the number of conditions
// recorded for the region (tracked by NumConds).
if (NumConds > 0 && Region.Kind == CounterMappingRegion::MCDCBranchRegion) {
- MCDCBranches.push_back(Region);
+ MCDCBranches.push_back(&Region);
// As we move through all of the MCDCBranchRegions that follow the
// MCDCDecisionRegion, decrement NumConds to make sure we account for