[llvm] [LowerSwitch] Implement verifyAnalysis (PR #68294)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 5 02:59:04 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
<details>
<summary>Changes</summary>
This pass is used like an analysis so it's useful to be able to verify
passes that claim to have preserved it.
---
Full diff: https://github.com/llvm/llvm-project/pull/68294.diff
1 Files Affected:
- (modified) llvm/lib/Transforms/Utils/LowerSwitch.cpp (+10)
``````````diff
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;
``````````
</details>
https://github.com/llvm/llvm-project/pull/68294
More information about the llvm-commits
mailing list