[llvm] r355634 - [CodeGen] Reuse BlockUtils for -unreachableblockelim pass (NFC)
Brian Gesiak via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 7 12:40:55 PST 2019
Author: modocache
Date: Thu Mar 7 12:40:55 2019
New Revision: 355634
URL: http://llvm.org/viewvc/llvm-project?rev=355634&view=rev
Log:
[CodeGen] Reuse BlockUtils for -unreachableblockelim pass (NFC)
Summary:
The logic in the -unreachableblockelim pass does the following:
1. It traverses the function it's given in depth-first order and
creates a set of basic blocks that are unreachable from the
function's entry node.
2. It iterates over each of those unreachable blocks and (1) removes any
successors' references to the dead block, and (2) replaces any uses of
instructions from the dead block with null.
The logic in (2) above is identical to what the `llvm::DeleteDeadBlocks`
function from `BasicBlockUtils.h` does. The only difference is that
`llvm::DeleteDeadBlocks` replaces uses of instructions from dead blocks
not with null, but with undef.
Replace the duplicate logic in the -unreachableblockelim pass with a
call to `llvm::DeleteDeadBlocks`. This results in less code but no
functional change (NFC).
Reviewers: mkazantsev, wmi, davidxl, silvas, davide
Reviewed By: davide
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59064
Modified:
llvm/trunk/lib/CodeGen/UnreachableBlockElim.cpp
Modified: llvm/trunk/lib/CodeGen/UnreachableBlockElim.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/UnreachableBlockElim.cpp?rev=355634&r1=355633&r2=355634&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/UnreachableBlockElim.cpp (original)
+++ llvm/trunk/lib/CodeGen/UnreachableBlockElim.cpp Thu Mar 7 12:40:55 2019
@@ -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 @@ static bool eliminateUnreachableBlock(Fu
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();
}
More information about the llvm-commits
mailing list