diff options
author | Owen Anderson <resistor@mac.com> | 2008-05-16 04:34:51 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2008-05-16 04:34:51 +0000 |
commit | 62849be80d0baf159448d0e3f6a9747dfa9a6707 (patch) | |
tree | 91747896c1bf8c5651ac50960f8164c4805b15ca /lib/Transforms/Scalar/ADCE.cpp | |
parent | 3dc73d398c6268e97154bfa80e0f14c83f212043 (diff) |
Remove ADCE's ability to delete loops. This ability is now implemented in a
safer manner by loop deletion.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51182 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/ADCE.cpp')
-rw-r--r-- | lib/Transforms/Scalar/ADCE.cpp | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/lib/Transforms/Scalar/ADCE.cpp b/lib/Transforms/Scalar/ADCE.cpp index c633f93058..11fb1e3324 100644 --- a/lib/Transforms/Scalar/ADCE.cpp +++ b/lib/Transforms/Scalar/ADCE.cpp @@ -191,10 +191,18 @@ bool ADCE::doADCE() { // be eliminated later, along with the instructions inside. // std::set<BasicBlock*> ReachableBBs; - for (df_ext_iterator<BasicBlock*> - BBI = df_ext_begin(&Func->front(), ReachableBBs), - BBE = df_ext_end(&Func->front(), ReachableBBs); BBI != BBE; ++BBI) { - BasicBlock *BB = *BBI; + std::vector<BasicBlock*> Stack; + Stack.push_back(&Func->getEntryBlock()); + + while (!Stack.empty()) { + BasicBlock* BB = Stack.back(); + if (ReachableBBs.count(BB)) { + Stack.pop_back(); + continue; + } else { + ReachableBBs.insert(BB); + } + for (BasicBlock::iterator II = BB->begin(), EI = BB->end(); II != EI; ) { Instruction *I = II++; if (CallInst *CI = dyn_cast<CallInst>(I)) { @@ -217,6 +225,15 @@ bool ADCE::doADCE() { ++NumInstRemoved; } } + + for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); SI != SE; ++SI) { + // Back edges (as opposed to cross edges) indicate loops, so implicitly + // mark them live. + if (std::find(Stack.begin(), Stack.end(), *SI) != Stack.end()) + markInstructionLive(BB->getTerminator()); + if (!ReachableBBs.count(*SI)) + Stack.push_back(*SI); + } } // Check to ensure we have an exit node for this CFG. If we don't, we won't |