-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[MC/DC] Refactor MCDC::State::Decision. NFC. #125408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
To resolve the error, rename mcdc-error-nests.cpp -> mcdc-nested-expr.cpp at first. - `func_condop` A corner case that contains close decisions. - `func_expect` Uses `__builtin_expect`. (#124565) - `func_lnot` Contains logical not(s) `!` among MC/DC binary operators. (#124563) mcdc-single-cond.cpp is for #95336.
Introduce `ID` and `InvalidID`. Then `DecisionByStmt` can have three
states.
* Not assigned if the Stmt(Expr) doesn't exist.
* When `DecisionByStmt[Expr]` exists:
* Invalid and should be ignored if `ID == Invalid`.
* Valid if `ID != Invalid`. Other member will be filled in the
Mapper.
|
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-codegen Author: NAKAMURA Takumi (chapuni) ChangesIntroduce
Full diff: https://github.com/llvm/llvm-project/pull/125408.diff 3 Files Affected:
diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp
index 792373839107f0a..0331ff83e633f75 100644
--- a/clang/lib/CodeGen/CodeGenPGO.cpp
+++ b/clang/lib/CodeGen/CodeGenPGO.cpp
@@ -310,7 +310,7 @@ struct MapRegionCounters : public RecursiveASTVisitor<MapRegionCounters> {
}
// Otherwise, allocate the Decision.
- MCDCState.DecisionByStmt[BinOp].BitmapIdx = 0;
+ MCDCState.DecisionByStmt[BinOp].ID = MCDCState.DecisionByStmt.size();
}
return true;
}
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp
index f09157771d2b5c0..4dbc0c70e34d60b 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -2197,10 +2197,8 @@ struct CounterCoverageMappingBuilder
// Update the state for CodeGenPGO
assert(MCDCState.DecisionByStmt.contains(E));
- MCDCState.DecisionByStmt[E] = {
- MCDCState.BitmapBits, // Top
- std::move(Builder.Indices),
- };
+ MCDCState.DecisionByStmt[E].update(MCDCState.BitmapBits, // Top
+ std::move(Builder.Indices));
auto DecisionParams = mcdc::DecisionParameters{
MCDCState.BitmapBits += NumTVs, // Tail
diff --git a/clang/lib/CodeGen/MCDCState.h b/clang/lib/CodeGen/MCDCState.h
index e0dd28ff90ed124..0b6f5f28235f43a 100644
--- a/clang/lib/CodeGen/MCDCState.h
+++ b/clang/lib/CodeGen/MCDCState.h
@@ -16,6 +16,8 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ProfileData/Coverage/MCDCTypes.h"
+#include <cassert>
+#include <limits>
namespace clang {
class Stmt;
@@ -30,8 +32,20 @@ struct State {
unsigned BitmapBits = 0;
struct Decision {
+ using IndicesTy = llvm::SmallVector<std::array<int, 2>>;
+ static constexpr auto InvalidID = std::numeric_limits<unsigned>::max();
+
unsigned BitmapIdx;
- llvm::SmallVector<std::array<int, 2>> Indices;
+ IndicesTy Indices;
+ unsigned ID = InvalidID;
+
+ bool isValid() const { return ID != InvalidID; }
+
+ void update(unsigned I, IndicesTy &&X) {
+ assert(ID != InvalidID);
+ BitmapIdx = I;
+ Indices = std::move(X);
+ }
};
llvm::DenseMap<const Stmt *, Decision> DecisionByStmt;
|
clang/lib/CodeGen/MCDCState.h
Outdated
| bool isValid() const { return ID != InvalidID; } | ||
|
|
||
| void update(unsigned I, IndicesTy &&X) { | ||
| assert(ID != InvalidID); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just use isValid()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, how expensive is this? Would it make sense for this to be a real error in release builds as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't be the real error. I suppose it the expectation here.
I can update this. IIRC, I implemented isValid later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Introduce
IDandInvalidID. ThenDecisionByStmtcan have three states.DecisionByStmt[Expr]exists:ID == Invalid.ID != Invalid. Other member will be filled in the Mapper.