[llvm] r244656 - [LowerSwitch] Skip dead blocks for processSwitchInst()

Chen Li via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 11 13:16:17 PDT 2015


Author: chenli
Date: Tue Aug 11 15:16:17 2015
New Revision: 244656

URL: http://llvm.org/viewvc/llvm-project?rev=244656&view=rev
Log:
[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

Modified:
    llvm/trunk/lib/Transforms/Utils/LowerSwitch.cpp

Modified: llvm/trunk/lib/Transforms/Utils/LowerSwitch.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/LowerSwitch.cpp?rev=244656&r1=244655&r2=244656&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/LowerSwitch.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/LowerSwitch.cpp Tue Aug 11 15:16:17 2015
@@ -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::createLowerSwitchPas
 
 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(CaseVec
 // 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(Swit
 
   // 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);
 }




More information about the llvm-commits mailing list