Skip to content

Commit 48c08f3

Browse files
committed
[Transform]Export LowerSwitch Utility Function
1 parent b68fe86 commit 48c08f3

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

llvm/include/llvm/Transforms/Utils/LowerSwitch.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@
1515
#ifndef LLVM_TRANSFORMS_UTILS_LOWERSWITCH_H
1616
#define LLVM_TRANSFORMS_UTILS_LOWERSWITCH_H
1717

18+
#include "llvm/Analysis/AssumptionCache.h"
19+
#include "llvm/Analysis/LazyValueInfo.h"
1820
#include "llvm/IR/PassManager.h"
1921

2022
namespace llvm {
2123
struct LowerSwitchPass : public PassInfoMixin<LowerSwitchPass> {
2224
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
2325
};
26+
bool LowerSwitch(Function &F, LazyValueInfo *LVI, AssumptionCache *AC);
2427
} // namespace llvm
2528

2629
#endif // LLVM_TRANSFORMS_UTILS_LOWERSWITCH_H

llvm/lib/Transforms/Utils/LowerSwitch.cpp

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
#include "llvm/ADT/STLExtras.h"
1818
#include "llvm/ADT/SmallPtrSet.h"
1919
#include "llvm/ADT/SmallVector.h"
20-
#include "llvm/Analysis/AssumptionCache.h"
21-
#include "llvm/Analysis/LazyValueInfo.h"
2220
#include "llvm/Analysis/ValueTracking.h"
2321
#include "llvm/IR/BasicBlock.h"
2422
#include "llvm/IR/CFG.h"
@@ -534,6 +532,25 @@ void ProcessSwitchInst(SwitchInst *SI,
534532
DeleteList.insert(OldDefault);
535533
}
536534

535+
/// Replace all SwitchInst instructions with chained branch instructions.
536+
class LowerSwitchLegacyPass : public FunctionPass {
537+
public:
538+
// Pass identification, replacement for typeid
539+
static char ID;
540+
541+
LowerSwitchLegacyPass() : FunctionPass(ID) {
542+
initializeLowerSwitchLegacyPassPass(*PassRegistry::getPassRegistry());
543+
}
544+
545+
bool runOnFunction(Function &F) override;
546+
547+
void getAnalysisUsage(AnalysisUsage &AU) const override {
548+
AU.addRequired<LazyValueInfoWrapperPass>();
549+
}
550+
};
551+
552+
} // end anonymous namespace
553+
namespace llvm {
537554
bool LowerSwitch(Function &F, LazyValueInfo *LVI, AssumptionCache *AC) {
538555
bool Changed = false;
539556
SmallPtrSet<BasicBlock *, 8> DeleteList;
@@ -558,26 +575,7 @@ bool LowerSwitch(Function &F, LazyValueInfo *LVI, AssumptionCache *AC) {
558575

559576
return Changed;
560577
}
561-
562-
/// Replace all SwitchInst instructions with chained branch instructions.
563-
class LowerSwitchLegacyPass : public FunctionPass {
564-
public:
565-
// Pass identification, replacement for typeid
566-
static char ID;
567-
568-
LowerSwitchLegacyPass() : FunctionPass(ID) {
569-
initializeLowerSwitchLegacyPassPass(*PassRegistry::getPassRegistry());
570-
}
571-
572-
bool runOnFunction(Function &F) override;
573-
574-
void getAnalysisUsage(AnalysisUsage &AU) const override {
575-
AU.addRequired<LazyValueInfoWrapperPass>();
576-
}
577-
};
578-
579-
} // end anonymous namespace
580-
578+
} // namespace llvm
581579
char LowerSwitchLegacyPass::ID = 0;
582580

583581
// Publicly exposed interface to pass...

0 commit comments

Comments
 (0)