diff options
author | Devang Patel <dpatel@apple.com> | 2009-02-05 19:59:42 +0000 |
---|---|---|
committer | Devang Patel <dpatel@apple.com> | 2009-02-05 19:59:42 +0000 |
commit | 39c873e38f3b173b51bd9d3d3b4ec1381b829754 (patch) | |
tree | df241f7c0c3eddc4f7fe45253433fd7f1e9c931d /lib/Transforms/Scalar/CondPropagate.cpp | |
parent | 1851db6b0f9ef1b85d14b24eb9f838748396352f (diff) |
Remove dead blocks in the end.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@63880 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/CondPropagate.cpp')
-rw-r--r-- | lib/Transforms/Scalar/CondPropagate.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/Transforms/Scalar/CondPropagate.cpp b/lib/Transforms/Scalar/CondPropagate.cpp index 1b755171c3..000ef60a0d 100644 --- a/lib/Transforms/Scalar/CondPropagate.cpp +++ b/lib/Transforms/Scalar/CondPropagate.cpp @@ -23,6 +23,7 @@ #include "llvm/Transforms/Utils/Local.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/Statistic.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/Streams.h" using namespace llvm; @@ -44,6 +45,7 @@ namespace { private: bool MadeChange; + SmallVector<BasicBlock *, 4> DeadBlocks; void SimplifyBlock(BasicBlock *BB); void SimplifyPredecessors(BranchInst *BI); void SimplifyPredecessors(SwitchInst *SI); @@ -60,14 +62,22 @@ FunctionPass *llvm::createCondPropagationPass() { bool CondProp::runOnFunction(Function &F) { bool EverMadeChange = false; + DeadBlocks.clear(); // While we are simplifying blocks, keep iterating. do { MadeChange = false; - for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) - SimplifyBlock(BB); + for (Function::iterator BB = F.begin(), E = F.end(); BB != E;) + SimplifyBlock(BB++); EverMadeChange = EverMadeChange || MadeChange; } while (MadeChange); + + if (EverMadeChange) { + while (!DeadBlocks.empty()) { + BasicBlock *BB = DeadBlocks.back(); DeadBlocks.pop_back(); + DeleteDeadBlock(BB); + } + } return EverMadeChange; } @@ -111,8 +121,9 @@ void CondProp::SimplifyBlock(BasicBlock *BB) { // Succ is now dead, but we cannot delete it without potentially // invalidating iterators elsewhere. Just insert an unreachable - // instruction in it. + // instruction in it and delete this block later on. new UnreachableInst(Succ); + DeadBlocks.push_back(Succ); MadeChange = true; } } |