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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions llvm/lib/Transforms/Utils/LowerSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) &&
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?

"Found an unlowered switch!");
}

void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.addRequired<LazyValueInfoWrapperPass>();
}
Expand All @@ -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;
Expand Down