[llvm] [Transform]Export LowerSwitch Utility Function (PR #71348)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 5 19:18:42 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Zhang (Naville)
<details>
<summary>Changes</summary>
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
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...
``````````
</details>
https://github.com/llvm/llvm-project/pull/71348
More information about the llvm-commits
mailing list