diff options
author | Anders Carlsson <andersca@mac.com> | 2009-02-08 00:50:42 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-02-08 00:50:42 +0000 |
commit | 87eaf17cc88516277e4389dfa15df93ecfdce559 (patch) | |
tree | b69fafea26baf8cee141969efeb72e722d0bae43 /lib/CodeGen/CodeGenFunction.cpp | |
parent | e2dedf8f61b8f306f704781456b482eb61871e8e (diff) |
More cleanup stack work.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64059 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CodeGenFunction.cpp')
-rw-r--r-- | lib/CodeGen/CodeGenFunction.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp index 0e0140c9ad..e5dc97c3d0 100644 --- a/lib/CodeGen/CodeGenFunction.cpp +++ b/lib/CodeGen/CodeGenFunction.cpp @@ -560,3 +560,44 @@ void CodeGenFunction::EmitCleanupBlock() } } +void CodeGenFunction::AddBranchFixup(llvm::BranchInst *BI) +{ + assert(!CleanupEntries.empty() && + "Trying to add branch fixup without cleanup block!"); + + // FIXME: We could be more clever here and check if there's already a + // branch fixup for this destination and recycle it. + CleanupEntries.back().BranchFixups.push_back(BI); +} + +void CodeGenFunction::EmitBranchThroughCleanup(llvm::BasicBlock *Dest) +{ + llvm::BranchInst* BI = Builder.CreateBr(Dest); + + // The stack is empty, no need to do any cleanup. + if (CleanupEntries.empty()) + return; + + if (!Dest->getParent()) { + // We are trying to branch to a block that hasn't been inserted yet. + AddBranchFixup(BI); + return; + } + + BlockScopeMap::iterator I = BlockScopes.find(Dest); + if (I == BlockScopes.end()) { + // We are trying to jump to a block that is outside of any cleanup scope. + AddBranchFixup(BI); + return; + } + + assert(I->second < CleanupEntries.size() && + "Trying to branch into cleanup region"); + + if (I->second == CleanupEntries.size() - 1) { + // We have a branch to a block in the same scope. + return; + } + + AddBranchFixup(BI); +} |