[llvm] [Transform]Export LowerSwitch Utility Function (PR #71348)

via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 5 19:18:15 PST 2023


https://github.com/Naville created https://github.com/llvm/llvm-project/pull/71348

Title.

>From 48c08f32a725b9fc746c1026444ed124ca846598 Mon Sep 17 00:00:00 2001
From: Zhang <admin at mayuyu.io>
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 97086987ffcbdfa..c7a4bc580ee46b8 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<LowerSwitchPass> {
   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 227de425ff85549..2e4cd1702257070 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<LazyValueInfoWrapperPass>();
+  }
+};
+
+} // end anonymous namespace
+namespace llvm {
 bool LowerSwitch(Function &F, LazyValueInfo *LVI, AssumptionCache *AC) {
   bool Changed = false;
   SmallPtrSet<BasicBlock *, 8> 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<LazyValueInfoWrapperPass>();
-  }
-};
-
-} // end anonymous namespace
-
+} // namespace llvm
 char LowerSwitchLegacyPass::ID = 0;
 
 // Publicly exposed interface to pass...



More information about the llvm-commits mailing list