Skip to content

Conversation

@Naville
Copy link
Contributor

@Naville Naville commented Nov 6, 2023

This re-exports LowerSwitch Utility Function so transform passes that requires LowerSwitch internally doesnt have to mess with pass pipeline

@llvmbot
Copy link
Member

llvmbot commented Nov 6, 2023

@llvm/pr-subscribers-llvm-transforms

Author: Zhang (Naville)

Changes

Title.


Full diff: https://github.com/llvm/llvm-project/pull/71348.diff

2 Files Affected:

  • (modified) llvm/include/llvm/Transforms/Utils/LowerSwitch.h (+3)
  • (modified) llvm/lib/Transforms/Utils/LowerSwitch.cpp (+20-22)
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...

@Naville
Copy link
Contributor Author

Naville commented Apr 1, 2024

Ping

@Naville Naville closed this Dec 22, 2024
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.

2 participants