From: Chen Li Date: Tue, 11 Aug 2015 20:16:17 +0000 (+0000) Subject: [LowerSwitch] Skip dead blocks for processSwitchInst() X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=5ea58973df21506fcc1c396bc866e02542d9c9ec;p=oota-llvm.git [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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@244656 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Utils/LowerSwitch.cpp b/lib/Transforms/Utils/LowerSwitch.cpp index 0e47626ce53..9cd85fa45c6 100644 --- a/lib/Transforms/Utils/LowerSwitch.cpp +++ b/lib/Transforms/Utils/LowerSwitch.cpp @@ -78,7 +78,7 @@ namespace { typedef std::vector CaseVector; typedef std::vector::iterator CaseItr; private: - void processSwitchInst(SwitchInst *SI, SmallVectorImpl &DeleteList); + void processSwitchInst(SwitchInst *SI, SmallPtrSetImpl &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 DeleteList; + SmallPtrSet 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(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 &DeleteList) { +void LowerSwitch::processSwitchInst(SwitchInst *SI, + SmallPtrSetImpl &DeleteList) { BasicBlock *CurBlock = SI->getParent(); BasicBlock *OrigBlock = CurBlock; Function *F = CurBlock->getParent(); @@ -525,5 +531,5 @@ void LowerSwitch::processSwitchInst(SwitchInst *SI, SmallVectorImpl // 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); }