From ac24238002076e36b2d33d18d1bf47a9de59fab4 Mon Sep 17 00:00:00 2001 From: "Ruiling, Song" Date: Wed, 25 Oct 2023 09:24:36 +0800 Subject: [LowerSwitch] Don't let pass manager handle the dependency (#68662) Some passes has limitation that only support simple terminators: branch/unreachable/return. Right now, they ask the pass manager to add LowerSwitch pass to eliminate `switch`. Let's manage such kind of pass dependency by ourselves. Also add the assertion in the related passes. --- llvm/lib/Transforms/Utils/BasicBlockUtils.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'llvm/lib/Transforms/Utils/BasicBlockUtils.cpp') diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp index 389aab3..05ff4ef 100644 --- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp +++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp @@ -2076,3 +2076,13 @@ void llvm::InvertBranch(BranchInst *PBI, IRBuilderBase &Builder) { PBI->setCondition(NewCond); PBI->swapSuccessors(); } + +bool llvm::hasOnlySimpleTerminator(const Function &F) { + for (auto &BB : F) { + auto *Term = BB.getTerminator(); + if (!(isa(Term) || isa(Term) || + isa(Term))) + return false; + } + return true; +} -- cgit v1.1