diff options
author | Hans Wennborg <hans@chromium.org> | 2024-06-14 10:32:39 +0200 |
---|---|---|
committer | Hans Wennborg <hans@chromium.org> | 2024-06-14 10:47:41 +0200 |
commit | b422fa6b62160f5eeb038d816d05e039182dde56 (patch) | |
tree | 1facf1d549693b6e685af22a7eebbe8b4db9daa4 /clang/lib/CodeGen/CoverageMappingGen.cpp | |
parent | 880d37038c7bbff53ef02c9d6b01cbbc87875243 (diff) | |
download | llvm-b422fa6b62160f5eeb038d816d05e039182dde56.zip llvm-b422fa6b62160f5eeb038d816d05e039182dde56.tar.gz llvm-b422fa6b62160f5eeb038d816d05e039182dde56.tar.bz2 |
Revert "[MC/DC][Coverage] Loosen the limit of NumConds from 6 (#82448)"
This broke the lit tests on Mac:
https://green.lab.llvm.org/job/llvm.org/job/clang-stage1-RA/1096/
> 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
This reverts commit 7ead2d8c7e9114b3f23666209a1654939987cb30.
Diffstat (limited to 'clang/lib/CodeGen/CoverageMappingGen.cpp')
-rw-r--r-- | clang/lib/CodeGen/CoverageMappingGen.cpp | 77 |
1 files changed, 5 insertions, 72 deletions
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp index ba483d8..6ce2d32 100644 --- a/clang/lib/CodeGen/CoverageMappingGen.cpp +++ b/clang/lib/CodeGen/CoverageMappingGen.cpp @@ -195,10 +195,6 @@ public: return std::holds_alternative<mcdc::BranchParameters>(MCDCParams); } - const auto &getMCDCBranchParams() const { - return mcdc::getParams<const mcdc::BranchParameters>(MCDCParams); - } - bool isMCDCDecision() const { return std::holds_alternative<mcdc::DecisionParameters>(MCDCParams); } @@ -208,8 +204,6 @@ public: } const mcdc::Parameters &getMCDCParams() const { return MCDCParams; } - - void resetMCDCParams() { MCDCParams = mcdc::Parameters(); } }; /// Spelling locations for the start and end of a source region. @@ -754,7 +748,6 @@ private: llvm::SmallVector<mcdc::ConditionIDs> DecisionStack; MCDC::State &MCDCState; - const Stmt *DecisionStmt = nullptr; mcdc::ConditionID NextID = 0; bool NotMapped = false; @@ -784,8 +777,7 @@ public: /// Set the given condition's ID. void setCondID(const Expr *Cond, mcdc::ConditionID ID) { - MCDCState.BranchByStmt[CodeGenFunction::stripCond(Cond)] = {ID, - DecisionStmt}; + MCDCState.BranchByStmt[CodeGenFunction::stripCond(Cond)].ID = ID; } /// Return the ID of a given condition. @@ -816,11 +808,6 @@ public: if (NotMapped) return; - if (NextID == 0) { - DecisionStmt = E; - assert(MCDCState.DecisionByStmt.contains(E)); - } - const mcdc::ConditionIDs &ParentDecision = DecisionStack.back(); // If the operator itself has an assigned ID, this means it represents a @@ -2135,41 +2122,13 @@ struct CounterCoverageMappingBuilder subtractCounters(ParentCount, TrueCount)); } - void createOrCancelDecision(const BinaryOperator *E, unsigned Since) { + void createDecision(const BinaryOperator *E) { unsigned NumConds = MCDCBuilder.getTotalConditionsAndReset(E); if (NumConds == 0) return; - // Extract [ID, Conds] to construct the graph. - llvm::SmallVector<mcdc::ConditionIDs> CondIDs(NumConds); - for (const auto &SR : ArrayRef(SourceRegions).slice(Since)) { - if (SR.isMCDCBranch()) { - auto [ID, Conds] = SR.getMCDCBranchParams(); - CondIDs[ID] = Conds; - } - } - - // Construct the graph and calculate `Indices`. - mcdc::TVIdxBuilder Builder(CondIDs); - unsigned NumTVs = Builder.NumTestVectors; - unsigned MaxTVs = CVM.getCodeGenModule().getCodeGenOpts().MCDCMaxTVs; - assert(MaxTVs < mcdc::TVIdxBuilder::HardMaxTVs); - - if (NumTVs > MaxTVs) { - // NumTVs exceeds MaxTVs -- warn and cancel the Decision. - cancelDecision(E, Since, NumTVs, MaxTVs); - return; - } - - // Update the state for CodeGenPGO - assert(MCDCState.DecisionByStmt.contains(E)); - MCDCState.DecisionByStmt[E] = { - MCDCState.BitmapBits, // Top - std::move(Builder.Indices), - }; - auto DecisionParams = mcdc::DecisionParameters{ - MCDCState.BitmapBits += NumTVs, // Tail + MCDCState.DecisionByStmt[E].BitmapIdx, NumConds, }; @@ -2177,28 +2136,6 @@ struct CounterCoverageMappingBuilder createDecisionRegion(E, DecisionParams); } - // Warn and cancel the Decision. - void cancelDecision(const BinaryOperator *E, unsigned Since, int NumTVs, - int MaxTVs) { - auto &Diag = CVM.getCodeGenModule().getDiags(); - unsigned DiagID = - Diag.getCustomDiagID(DiagnosticsEngine::Warning, - "unsupported MC/DC boolean expression; " - "number of test vectors (%0) exceeds max (%1). " - "Expression will not be covered"); - Diag.Report(E->getBeginLoc(), DiagID) << NumTVs << MaxTVs; - - // Restore MCDCBranch to Branch. - for (auto &SR : MutableArrayRef(SourceRegions).slice(Since)) { - assert(!SR.isMCDCDecision() && "Decision shouldn't be seen here"); - if (SR.isMCDCBranch()) - SR.resetMCDCParams(); - } - - // Tell CodeGenPGO not to instrument. - MCDCState.DecisionByStmt.erase(E); - } - /// Check if E belongs to system headers. bool isExprInSystemHeader(const BinaryOperator *E) const { return (!SystemHeadersCoverage && @@ -2215,8 +2152,6 @@ struct CounterCoverageMappingBuilder bool IsRootNode = MCDCBuilder.isIdle(); - unsigned SourceRegionsSince = SourceRegions.size(); - // Keep track of Binary Operator and assign MCDC condition IDs. MCDCBuilder.pushAndAssignIDs(E); @@ -2255,7 +2190,7 @@ struct CounterCoverageMappingBuilder // Create MCDC Decision Region if at top-level (root). if (IsRootNode) - createOrCancelDecision(E, SourceRegionsSince); + createDecision(E); } // Determine whether the right side of OR operation need to be visited. @@ -2276,8 +2211,6 @@ struct CounterCoverageMappingBuilder bool IsRootNode = MCDCBuilder.isIdle(); - unsigned SourceRegionsSince = SourceRegions.size(); - // Keep track of Binary Operator and assign MCDC condition IDs. MCDCBuilder.pushAndAssignIDs(E); @@ -2320,7 +2253,7 @@ struct CounterCoverageMappingBuilder // Create MCDC Decision Region if at top-level (root). if (IsRootNode) - createOrCancelDecision(E, SourceRegionsSince); + createDecision(E); } void VisitLambdaExpr(const LambdaExpr *LE) { |