[PATCH] D59064: [CodeGen] Reuse BlockUtils for -unreachableblockelim pass (NFC)

Brian Gesiak via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 7 12:44:14 PST 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL355634: [CodeGen] Reuse BlockUtils for -unreachableblockelim pass (NFC) (authored by modocache, committed by ).

Repository:
  rL LLVM

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

https://reviews.llvm.org/D59064

Files:
  llvm/trunk/lib/CodeGen/UnreachableBlockElim.cpp


Index: llvm/trunk/lib/CodeGen/UnreachableBlockElim.cpp
===================================================================
--- llvm/trunk/lib/CodeGen/UnreachableBlockElim.cpp
+++ llvm/trunk/lib/CodeGen/UnreachableBlockElim.cpp
@@ -37,6 +37,7 @@
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/Type.h"
 #include "llvm/Pass.h"
+#include "llvm/Transforms/Utils/BasicBlockUtils.h"
 using namespace llvm;
 
 static bool eliminateUnreachableBlock(Function &F) {
@@ -46,26 +47,16 @@
   for (BasicBlock *BB : depth_first_ext(&F, Reachable))
     (void)BB/* Mark all reachable blocks */;
 
-  // Loop over all dead blocks, remembering them and deleting all instructions
-  // in them.
+  // Collect all dead blocks.
   std::vector<BasicBlock*> DeadBlocks;
   for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
     if (!Reachable.count(&*I)) {
       BasicBlock *BB = &*I;
       DeadBlocks.push_back(BB);
-      while (PHINode *PN = dyn_cast<PHINode>(BB->begin())) {
-        PN->replaceAllUsesWith(Constant::getNullValue(PN->getType()));
-        BB->getInstList().pop_front();
-      }
-      for (succ_iterator SI = succ_begin(BB), E = succ_end(BB); SI != E; ++SI)
-        (*SI)->removePredecessor(BB);
-      BB->dropAllReferences();
     }
 
-  // Actually remove the blocks now.
-  for (unsigned i = 0, e = DeadBlocks.size(); i != e; ++i) {
-    DeadBlocks[i]->eraseFromParent();
-  }
+  // Delete the dead blocks.
+  DeleteDeadBlocks(DeadBlocks);
 
   return !DeadBlocks.empty();
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59064.189770.patch
Type: text/x-patch
Size: 1503 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190307/4fa588ba/attachment.bin>


More information about the llvm-commits mailing list