[PATCH] D11953: [LowerSwitch] Skip dead blocks for processSwitchInst()

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


chenli updated this revision to Diff 31849.
chenli added a comment.

Update w.r.t. Hans' comments.


http://reviews.llvm.org/D11953

Files:
  lib/Transforms/Utils/LowerSwitch.cpp

Index: lib/Transforms/Utils/LowerSwitch.cpp
===================================================================
--- lib/Transforms/Utils/LowerSwitch.cpp
+++ lib/Transforms/Utils/LowerSwitch.cpp
@@ -78,7 +78,7 @@
     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,17 @@
 
 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 +408,7 @@
 // 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 @@
 
   // 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);
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11953.31849.patch
Type: text/x-patch
Size: 2000 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150811/bb394896/attachment.bin>


More information about the llvm-commits mailing list