diff options
author | Chen Li <meloli87@gmail.com> | 2015-08-11 20:16:17 +0000 |
---|---|---|
committer | Chen Li <meloli87@gmail.com> | 2015-08-11 20:16:17 +0000 |
commit | 0786bc9fe889bf88f05f255edcbcef976264e110 (patch) | |
tree | 3d134a58792a5baf488d175b6c610a2fa61fe278 /llvm/lib/Transforms/Utils/LowerSwitch.cpp | |
parent | 480c840896a3f9487877e67e54fe6c814c34fac3 (diff) | |
download | llvm-0786bc9fe889bf88f05f255edcbcef976264e110.zip llvm-0786bc9fe889bf88f05f255edcbcef976264e110.tar.gz llvm-0786bc9fe889bf88f05f255edcbcef976264e110.tar.bz2 |
[LowerSwitch] Skip dead blocks for processSwitchInst()
Summary: This patch adds check for dead blocks and skip them for processSwitchInst(). This will help reduce compilation time.
Reviewers: reames, hans
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D11953
llvm-svn: 244656
Diffstat (limited to 'llvm/lib/Transforms/Utils/LowerSwitch.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/LowerSwitch.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/Utils/LowerSwitch.cpp b/llvm/lib/Transforms/Utils/LowerSwitch.cpp index 0e47626..9cd85fa 100644 --- a/llvm/lib/Transforms/Utils/LowerSwitch.cpp +++ b/llvm/lib/Transforms/Utils/LowerSwitch.cpp @@ -78,7 +78,7 @@ namespace { typedef std::vector<CaseRange> CaseVector; typedef std::vector<CaseRange>::iterator CaseItr; private: - void processSwitchInst(SwitchInst *SI, SmallVectorImpl<BasicBlock*> &DeleteList); + void processSwitchInst(SwitchInst *SI, SmallPtrSetImpl<BasicBlock*> &DeleteList); BasicBlock *switchConvert(CaseItr Begin, CaseItr End, ConstantInt *LowerBound, ConstantInt *UpperBound, @@ -116,11 +116,16 @@ FunctionPass *llvm::createLowerSwitchPass() { bool LowerSwitch::runOnFunction(Function &F) { bool Changed = false; - SmallVector<BasicBlock*, 8> DeleteList; + SmallPtrSet<BasicBlock*, 8> DeleteList; for (Function::iterator I = F.begin(), E = F.end(); I != E; ) { BasicBlock *Cur = I++; // Advance over block so we don't traverse new blocks + // If the block is a dead Default block that will be deleted later, don't + // waste time processing it. + if (DeleteList.count(Cur)) + continue; + if (SwitchInst *SI = dyn_cast<SwitchInst>(Cur->getTerminator())) { Changed = true; processSwitchInst(SI, DeleteList); @@ -402,7 +407,8 @@ unsigned LowerSwitch::Clusterify(CaseVector& Cases, SwitchInst *SI) { // processSwitchInst - Replace the specified switch instruction with a sequence // of chained if-then insts in a balanced binary search. // -void LowerSwitch::processSwitchInst(SwitchInst *SI, SmallVectorImpl<BasicBlock*> &DeleteList) { +void LowerSwitch::processSwitchInst(SwitchInst *SI, + SmallPtrSetImpl<BasicBlock*> &DeleteList) { BasicBlock *CurBlock = SI->getParent(); BasicBlock *OrigBlock = CurBlock; Function *F = CurBlock->getParent(); @@ -525,5 +531,5 @@ void LowerSwitch::processSwitchInst(SwitchInst *SI, SmallVectorImpl<BasicBlock*> // If the Default block has no more predecessors just add it to DeleteList. if (pred_begin(OldDefault) == pred_end(OldDefault)) - DeleteList.push_back(OldDefault); + DeleteList.insert(OldDefault); } |