From 48c08f32a725b9fc746c1026444ed124ca846598 Mon Sep 17 00:00:00 2001 From: Zhang Date: Mon, 6 Nov 2023 11:15:56 +0800 Subject: [PATCH] [Transform]Export LowerSwitch Utility Function --- .../llvm/Transforms/Utils/LowerSwitch.h | 3 ++ llvm/lib/Transforms/Utils/LowerSwitch.cpp | 42 +++++++++---------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/llvm/include/llvm/Transforms/Utils/LowerSwitch.h b/llvm/include/llvm/Transforms/Utils/LowerSwitch.h index 97086987ffcbd..c7a4bc580ee46 100644 --- a/llvm/include/llvm/Transforms/Utils/LowerSwitch.h +++ b/llvm/include/llvm/Transforms/Utils/LowerSwitch.h @@ -15,12 +15,15 @@ #ifndef LLVM_TRANSFORMS_UTILS_LOWERSWITCH_H #define LLVM_TRANSFORMS_UTILS_LOWERSWITCH_H +#include "llvm/Analysis/AssumptionCache.h" +#include "llvm/Analysis/LazyValueInfo.h" #include "llvm/IR/PassManager.h" namespace llvm { struct LowerSwitchPass : public PassInfoMixin { PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); }; +bool LowerSwitch(Function &F, LazyValueInfo *LVI, AssumptionCache *AC); } // namespace llvm #endif // LLVM_TRANSFORMS_UTILS_LOWERSWITCH_H diff --git a/llvm/lib/Transforms/Utils/LowerSwitch.cpp b/llvm/lib/Transforms/Utils/LowerSwitch.cpp index 227de425ff855..2e4cd17022570 100644 --- a/llvm/lib/Transforms/Utils/LowerSwitch.cpp +++ b/llvm/lib/Transforms/Utils/LowerSwitch.cpp @@ -17,8 +17,6 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallVector.h" -#include "llvm/Analysis/AssumptionCache.h" -#include "llvm/Analysis/LazyValueInfo.h" #include "llvm/Analysis/ValueTracking.h" #include "llvm/IR/BasicBlock.h" #include "llvm/IR/CFG.h" @@ -534,6 +532,25 @@ void ProcessSwitchInst(SwitchInst *SI, DeleteList.insert(OldDefault); } +/// Replace all SwitchInst instructions with chained branch instructions. +class LowerSwitchLegacyPass : public FunctionPass { +public: + // Pass identification, replacement for typeid + static char ID; + + LowerSwitchLegacyPass() : FunctionPass(ID) { + initializeLowerSwitchLegacyPassPass(*PassRegistry::getPassRegistry()); + } + + bool runOnFunction(Function &F) override; + + void getAnalysisUsage(AnalysisUsage &AU) const override { + AU.addRequired(); + } +}; + +} // end anonymous namespace +namespace llvm { bool LowerSwitch(Function &F, LazyValueInfo *LVI, AssumptionCache *AC) { bool Changed = false; SmallPtrSet DeleteList; @@ -558,26 +575,7 @@ bool LowerSwitch(Function &F, LazyValueInfo *LVI, AssumptionCache *AC) { return Changed; } - -/// Replace all SwitchInst instructions with chained branch instructions. -class LowerSwitchLegacyPass : public FunctionPass { -public: - // Pass identification, replacement for typeid - static char ID; - - LowerSwitchLegacyPass() : FunctionPass(ID) { - initializeLowerSwitchLegacyPassPass(*PassRegistry::getPassRegistry()); - } - - bool runOnFunction(Function &F) override; - - void getAnalysisUsage(AnalysisUsage &AU) const override { - AU.addRequired(); - } -}; - -} // end anonymous namespace - +} // namespace llvm char LowerSwitchLegacyPass::ID = 0; // Publicly exposed interface to pass...