Skip to content

[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

Closed
wants to merge 1 commit into from
Closed

[LowerSwitch] Implement verifyAnalysis #68294

wants to merge 1 commit into from

Conversation

jayfoad
Copy link
Contributor

@jayfoad jayfoad commented Oct 5, 2023

This pass is used like an analysis so it's useful to be able to verify
passes that claim to have preserved it.

This pass is used like an analysis so it's useful to be able to verify
passes that claim to have preserved it.
@llvmbot
Copy link
Member

llvmbot commented Oct 5, 2023

@llvm/pr-subscribers-backend-amdgpu

@llvm/pr-subscribers-llvm-transforms

Changes

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 --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()) &&
Copy link
Contributor

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

Copy link
Contributor Author

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?

@ruiling
Copy link
Contributor

ruiling commented Oct 10, 2023

I think #68662 can help on this?

@jayfoad
Copy link
Contributor Author

jayfoad commented Oct 10, 2023

I think #68662 can help on this?

If we go with #68662 then LowerSwitch is no longer used like an analysis, so there would be no need to verify that it is preserved.

@jayfoad
Copy link
Contributor Author

jayfoad commented Oct 25, 2023

I think #68662 can help on this?

If we go with #68662 then LowerSwitch is no longer used like an analysis, so there would be no need to verify that it is preserved.

We went with #68662.

@jayfoad jayfoad closed this Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants