[llvm] ec8a6c1 - [SimplifyCFGPass] iterativelySimplifyCFG(): support lazy DomTreeUpdater

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 11 15:10:22 PST 2021


Author: Roman Lebedev
Date: 2021-01-12T02:09:47+03:00
New Revision: ec8a6c11db4102ec249ce90084b3f615c5de15e5

URL: https://github.com/llvm/llvm-project/commit/ec8a6c11db4102ec249ce90084b3f615c5de15e5
DIFF: https://github.com/llvm/llvm-project/commit/ec8a6c11db4102ec249ce90084b3f615c5de15e5.diff

LOG: [SimplifyCFGPass] iterativelySimplifyCFG(): support lazy DomTreeUpdater

This boils down to how we deal with early-increment iterator
over function's basic blocks: not only we need to early-increment,
after that we also need to skip all the blocks
that are scheduled for removal, as per DomTreeUpdater.

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp b/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
index 944331932495..0e1ec7194527 100644
--- a/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
+++ b/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
@@ -209,7 +209,17 @@ static bool iterativelySimplifyCFG(Function &F, const TargetTransformInfo &TTI,
 
     // Loop over all of the basic blocks and remove them if they are unneeded.
     for (Function::iterator BBIt = F.begin(); BBIt != F.end(); ) {
-      if (simplifyCFG(&*BBIt++, TTI, DTU, Options, &LoopHeaders)) {
+      BasicBlock &BB = *BBIt++;
+      if (DTU) {
+        assert(
+            !DTU->isBBPendingDeletion(&BB) &&
+            "Should not end up trying to simplify blocks marked for removal.");
+        // Make sure that the advanced iterator does not point at the blocks
+        // that are marked for removal, skip over all such blocks.
+        while (BBIt != F.end() && DTU->isBBPendingDeletion(&*BBIt))
+          ++BBIt;
+      }
+      if (simplifyCFG(&BB, TTI, DTU, Options, &LoopHeaders)) {
         LocalChange = true;
         ++NumSimpl;
       }


        


More information about the llvm-commits mailing list