diff options
author | NAKAMURA Takumi <geek4civic@gmail.com> | 2024-02-14 23:17:00 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-14 23:17:00 +0900 |
commit | 1a1fcacbce805e3c409d9d41de61413e3fd8aa36 (patch) | |
tree | 4104465800b8d7003e88359d4f6b924163b80b6f /llvm/lib/ProfileData/Coverage | |
parent | 8e24bc096dcd0013d802e59a45803c51796dec0a (diff) | |
download | llvm-1a1fcacbce805e3c409d9d41de61413e3fd8aa36.zip llvm-1a1fcacbce805e3c409d9d41de61413e3fd8aa36.tar.gz llvm-1a1fcacbce805e3c409d9d41de61413e3fd8aa36.tar.bz2 |
[MC/DC] Refactor: Introduce `ConditionIDs` as `std::array<2>` (#81221)
Its 0th element corresponds to `FalseID` and 1st to `TrueID`.
CoverageMappingGen.cpp: `DecisionIDPair` is replaced with `ConditionIDs`
Diffstat (limited to 'llvm/lib/ProfileData/Coverage')
-rw-r--r-- | llvm/lib/ProfileData/Coverage/CoverageMapping.cpp | 50 | ||||
-rw-r--r-- | llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp | 6 | ||||
-rw-r--r-- | llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp | 4 |
3 files changed, 28 insertions, 32 deletions
diff --git a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp index 80b80f7..9adeceb 100644 --- a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp +++ b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp @@ -246,7 +246,7 @@ class MCDCRecordProcessor { unsigned BitmapIdx; /// Mapping of a condition ID to its corresponding branch params. - llvm::DenseMap<unsigned, const mcdc::BranchParameters *> BranchParamsMap; + llvm::DenseMap<unsigned, mcdc::ConditionIDs> CondsMap; /// Vector used to track whether a condition is constant folded. MCDCRecord::BoolVector Folded; @@ -269,38 +269,34 @@ public: Folded(NumConditions, false), IndependencePairs(NumConditions) {} private: - void recordTestVector(MCDCRecord::TestVector &TV, unsigned Index, - MCDCRecord::CondState Result) { - if (!Bitmap[BitmapIdx + Index]) - return; - - // Copy the completed test vector to the vector of testvectors. - ExecVectors.push_back(TV); - - // The final value (T,F) is equal to the last non-dontcare state on the - // path (in a short-circuiting system). - ExecVectors.back().push_back(Result); - } - // Walk the binary decision diagram and try assigning both false and true to // each node. When a terminal node (ID == 0) is reached, fill in the value in // the truth table. void buildTestVector(MCDCRecord::TestVector &TV, unsigned ID, unsigned Index) { - auto [UnusedID, TrueID, FalseID] = *BranchParamsMap[ID]; + assert((Index & (1 << (ID - 1))) == 0); + + for (auto MCDCCond : {MCDCRecord::MCDC_False, MCDCRecord::MCDC_True}) { + static_assert(MCDCRecord::MCDC_False == 0); + static_assert(MCDCRecord::MCDC_True == 1); + Index |= MCDCCond << (ID - 1); + TV[ID - 1] = MCDCCond; + auto NextID = CondsMap[ID][MCDCCond]; + if (NextID > 0) { + buildTestVector(TV, NextID, Index); + continue; + } - TV[ID - 1] = MCDCRecord::MCDC_False; - if (FalseID > 0) - buildTestVector(TV, FalseID, Index); - else - recordTestVector(TV, Index, MCDCRecord::MCDC_False); + if (!Bitmap[BitmapIdx + Index]) + continue; - Index |= 1 << (ID - 1); - TV[ID - 1] = MCDCRecord::MCDC_True; - if (TrueID > 0) - buildTestVector(TV, TrueID, Index); - else - recordTestVector(TV, Index, MCDCRecord::MCDC_True); + // Copy the completed test vector to the vector of testvectors. + ExecVectors.push_back(TV); + + // The final value (T,F) is equal to the last non-dontcare state on the + // path (in a short-circuiting system). + ExecVectors.back().push_back(MCDCCond); + } // Reset back to DontCare. TV[ID - 1] = MCDCRecord::MCDC_DontCare; @@ -374,7 +370,7 @@ public: // from being measured. for (const auto *B : Branches) { const auto &BranchParams = B->getBranchParams(); - BranchParamsMap[BranchParams.ID] = &BranchParams; + CondsMap[BranchParams.ID] = BranchParams.Conds; PosToID[I] = BranchParams.ID - 1; CondLoc[I] = B->startLoc(); Folded[I++] = (B->Count.isZero() && B->FalseCount.isZero()); diff --git a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp index d528d9a..de7be52 100644 --- a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp +++ b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp @@ -313,9 +313,9 @@ Error RawCoverageMappingReader::readMappingRegionsSubArray( return make_error<CoverageMapError>( coveragemap_error::malformed, "MCDCConditionID shouldn't be zero"); - Params = mcdc::BranchParameters{static_cast<unsigned>(ID), - static_cast<unsigned>(TID), - static_cast<unsigned>(FID)}; + Params = mcdc::BranchParameters{ + static_cast<unsigned>(ID), + {static_cast<unsigned>(FID), static_cast<unsigned>(TID)}}; break; case CounterMappingRegion::MCDCDecisionRegion: Kind = CounterMappingRegion::MCDCDecisionRegion; diff --git a/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp b/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp index 3267afd..6125cce 100644 --- a/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp +++ b/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp @@ -257,8 +257,8 @@ void CoverageMappingWriter::write(raw_ostream &OS) { ParamsShouldBeNull = false; assert(BranchParams.ID > 0); encodeULEB128(static_cast<unsigned>(BranchParams.ID), OS); - encodeULEB128(static_cast<unsigned>(BranchParams.TrueID), OS); - encodeULEB128(static_cast<unsigned>(BranchParams.FalseID), OS); + encodeULEB128(static_cast<unsigned>(BranchParams.Conds[true]), OS); + encodeULEB128(static_cast<unsigned>(BranchParams.Conds[false]), OS); } break; case CounterMappingRegion::MCDCDecisionRegion: |