-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[LowerSwitch] Implement verifyAnalysis #68294
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
Conversation
This pass is used like an analysis so it's useful to be able to verify passes that claim to have preserved it.
@llvm/pr-subscribers-backend-amdgpu @llvm/pr-subscribers-llvm-transforms ChangesThis pass is used like an analysis so it's useful to be able to verify Full diff: https://github.com/llvm/llvm-project/pull/68294.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/Utils/LowerSwitch.cpp b/llvm/lib/Transforms/Utils/LowerSwitch.cpp
index 227de425ff85549..2b046017d06abda 100644
--- a/llvm/lib/Transforms/Utils/LowerSwitch.cpp
+++ b/llvm/lib/Transforms/Utils/LowerSwitch.cpp
@@ -569,8 +569,17 @@ class LowerSwitchLegacyPass : public FunctionPass {
initializeLowerSwitchLegacyPassPass(*PassRegistry::getPassRegistry());
}
+ // Remember the current function. Only used for verification.
+ Function *F;
+
bool runOnFunction(Function &F) override;
+ void verifyAnalysis() const override {
+ for (auto &BB : *F)
+ assert(!isa<SwitchInst>(BB.getTerminator()) &&
+ "Found an unlowered switch!");
+ }
+
void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.addRequired<LazyValueInfoWrapperPass>();
}
@@ -596,6 +605,7 @@ FunctionPass *llvm::createLowerSwitchPass() {
}
bool LowerSwitchLegacyPass::runOnFunction(Function &F) {
+ this->F = &F;
LazyValueInfo *LVI = &getAnalysis<LazyValueInfoWrapperPass>().getLVI();
auto *ACT = getAnalysisIfAvailable<AssumptionCacheTracker>();
AssumptionCache *AC = ACT ? &ACT->getAssumptionCache(F) : nullptr;
|
bool runOnFunction(Function &F) override; | ||
|
||
void verifyAnalysis() const override { | ||
for (auto &BB : *F) | ||
assert(!isa<SwitchInst>(BB.getTerminator()) && |
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.
Is verifyAnalysis supposed to work in a release build? I think you're in danger of the unused member variable as is
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.
I'm just trying to follow existing patterns. They all seem to use assert
so won't do anything in a normal Release build. I don't think most compilers warn about unused public fields do they?
I think #68662 can help on this? |
This pass is used like an analysis so it's useful to be able to verify
passes that claim to have preserved it.