[PATCH] D68191: Simplify function llvm::removeUnreachableBlocks() to avoid (re-)computation.

Rodrigo Caetano Rocha via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 30 10:10:15 PDT 2019


rcorcs updated this revision to Diff 222428.
rcorcs added a comment.

I have fused two loops. Now, for any execution path, only two loops over DeadBlockSet will be performed, instead of the previous worst-case of three loops.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D68191/new/

https://reviews.llvm.org/D68191

Files:
  llvm/lib/Transforms/Utils/Local.cpp


Index: llvm/lib/Transforms/Utils/Local.cpp
===================================================================
--- llvm/lib/Transforms/Utils/Local.cpp
+++ llvm/lib/Transforms/Utils/Local.cpp
@@ -2228,7 +2228,8 @@
   SmallSetVector<BasicBlock *, 8> DeadBlockSet;
   for (Function::iterator I = ++F.begin(), E = F.end(); I != E; ++I) {
     auto *BB = &*I;
-    if (Reachable.count(BB))
+    //skip reachable basic blocks
+    if (Reachable.find(BB)!=Reachable.end())
       continue;
     DeadBlockSet.insert(BB);
   }
@@ -2249,13 +2250,6 @@
     if (LVI)
       LVI->eraseBlock(BB);
     BB->dropAllReferences();
-  }
-  for (Function::iterator I = ++F.begin(); I != F.end();) {
-    auto *BB = &*I;
-    if (Reachable.count(BB)) {
-      ++I;
-      continue;
-    }
     if (DTU) {
       // Remove the terminator of BB to clear the successor list of BB.
       if (BB->getTerminator())
@@ -2263,9 +2257,6 @@
       new UnreachableInst(BB->getContext(), BB);
       assert(succ_empty(BB) && "The successor list of BB isn't empty before "
                                "applying corresponding DTU updates.");
-      ++I;
-    } else {
-      I = F.getBasicBlockList().erase(I);
     }
   }
 
@@ -2281,7 +2272,12 @@
     }
     if (!Deleted)
       return false;
+  } else {
+    for (auto *BB : DeadBlockSet) {
+      BB->eraseFromParent();
+    }
   }
+
   return true;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68191.222428.patch
Type: text/x-patch
Size: 1379 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190930/557ca650/attachment.bin>


More information about the llvm-commits mailing list