aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/UnreachableBlockElim.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-03-15 16:37:42 +0000
committerChris Lattner <sabre@nondot.org>2010-03-15 16:37:42 +0000
commitfc6e69bcb2c8b9157164adfaa0c86115e7356cd0 (patch)
treeb6055d18acc809ee4c5edf5c0cc66810be914583 /lib/CodeGen/UnreachableBlockElim.cpp
parented7d10e1000ae88c9ec7a0db6002eb8b8543a470 (diff)
don't eliminate address-taken blocks here.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98550 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/UnreachableBlockElim.cpp')
-rw-r--r--lib/CodeGen/UnreachableBlockElim.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/CodeGen/UnreachableBlockElim.cpp b/lib/CodeGen/UnreachableBlockElim.cpp
index 7b338126d4..c0d4494d5b 100644
--- a/lib/CodeGen/UnreachableBlockElim.cpp
+++ b/lib/CodeGen/UnreachableBlockElim.cpp
@@ -58,13 +58,25 @@ FunctionPass *llvm::createUnreachableBlockEliminationPass() {
return new UnreachableBlockElim();
}
+static void MarkReachableFrom(BasicBlock *BB,
+ SmallPtrSet<BasicBlock*, 8> &Reachable) {
+ for (df_ext_iterator<BasicBlock*, SmallPtrSet<BasicBlock*, 8> > I =
+ df_ext_begin(BB, Reachable), E = df_ext_end(BB, Reachable); I != E; ++I)
+ ; // Mark all reachable blocks.
+}
+
bool UnreachableBlockElim::runOnFunction(Function &F) {
SmallPtrSet<BasicBlock*, 8> Reachable;
// Mark all reachable blocks.
- for (df_ext_iterator<Function*, SmallPtrSet<BasicBlock*, 8> > I =
- df_ext_begin(&F, Reachable), E = df_ext_end(&F, Reachable); I != E; ++I)
- /* Mark all reachable blocks */;
+ MarkReachableFrom(&F.getEntryBlock(), Reachable);
+
+ // Mark any address-taken blocks. We don't want codegen to delete these
+ // because the address may already be referenced by another function and the
+ // label may be referenced.
+ for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
+ if (I->hasAddressTaken() && !Reachable.count(I))
+ MarkReachableFrom(I, Reachable);
// Loop over all dead blocks, remembering them and deleting all instructions
// in them.