[llvm-commits] CVS: llvm/lib/CodeGen/UnreachableBlockElim.cpp
Chris Lattner
lattner at cs.uiuc.edu
Tue Jul 6 01:37:01 PDT 2004
Changes in directory llvm/lib/CodeGen:
UnreachableBlockElim.cpp updated: 1.1 -> 1.2
---
Log message:
Fix a bug in the unreachable block elim pass. Dropping all references on a
basic block clear()'s all of the operands lists, including phis. This
caused removePredecessor to get confused later. Because of this, we just
nuke (without prejudice) PHI nodes in unreachable blocks.
---
Diffs of the changes: (+11 -4)
Index: llvm/lib/CodeGen/UnreachableBlockElim.cpp
diff -u llvm/lib/CodeGen/UnreachableBlockElim.cpp:1.1 llvm/lib/CodeGen/UnreachableBlockElim.cpp:1.2
--- llvm/lib/CodeGen/UnreachableBlockElim.cpp:1.1 Fri Jul 2 00:46:10 2004
+++ llvm/lib/CodeGen/UnreachableBlockElim.cpp Tue Jul 6 01:36:11 2004
@@ -21,6 +21,8 @@
//===----------------------------------------------------------------------===//
#include "llvm/CodeGen/Passes.h"
+#include "llvm/iPHINode.h"
+#include "llvm/Constant.h"
#include "llvm/Function.h"
#include "llvm/Pass.h"
#include "llvm/Support/CFG.h"
@@ -52,10 +54,15 @@
std::vector<BasicBlock*> DeadBlocks;
for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
if (!Reachable.count(I)) {
- DeadBlocks.push_back(I);
- for (succ_iterator SI = succ_begin(&*I), E = succ_end(&*I); SI != E; ++SI)
- (*SI)->removePredecessor(I);
- I->dropAllReferences();
+ 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();
}
if (DeadBlocks.empty()) return false;
More information about the llvm-commits
mailing list