[llvm-commits] [llvm] r51182 - /llvm/trunk/lib/Transforms/Scalar/ADCE.cpp
Owen Anderson
resistor at mac.com
Thu May 15 21:34:51 PDT 2008
Author: resistor
Date: Thu May 15 23:34:51 2008
New Revision: 51182
URL: http://llvm.org/viewvc/llvm-project?rev=51182&view=rev
Log:
Remove ADCE's ability to delete loops. This ability is now implemented in a
safer manner by loop deletion.
Modified:
llvm/trunk/lib/Transforms/Scalar/ADCE.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/ADCE.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/ADCE.cpp?rev=51182&r1=51181&r2=51182&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/ADCE.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/ADCE.cpp Thu May 15 23:34:51 2008
@@ -191,10 +191,18 @@
// 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 @@
++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
More information about the llvm-commits
mailing list