[cfe-commits] r108975 - /cfe/trunk/lib/CodeGen/CGException.cpp
John McCall
rjmccall at apple.com
Tue Jul 20 17:52:03 PDT 2010
Author: rjmccall
Date: Tue Jul 20 19:52:03 2010
New Revision: 108975
URL: http://llvm.org/viewvc/llvm-project?rev=108975&view=rev
Log:
Convert the end-catch call for finally blocks to a lazy cleanup. This kills off
the last of the shared-code cleanups.
Modified:
cfe/trunk/lib/CodeGen/CGException.cpp
Modified: cfe/trunk/lib/CodeGen/CGException.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGException.cpp?rev=108975&r1=108974&r2=108975&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGException.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGException.cpp Tue Jul 20 19:52:03 2010
@@ -1337,6 +1337,28 @@
EmitBlock(ContBB);
}
+namespace {
+ struct CallEndCatchForFinally : EHScopeStack::LazyCleanup {
+ llvm::Value *ForEHVar;
+ llvm::Value *EndCatchFn;
+ CallEndCatchForFinally(llvm::Value *ForEHVar, llvm::Value *EndCatchFn)
+ : ForEHVar(ForEHVar), EndCatchFn(EndCatchFn) {}
+
+ void Emit(CodeGenFunction &CGF, bool IsForEH) {
+ llvm::BasicBlock *EndCatchBB = CGF.createBasicBlock("finally.endcatch");
+ llvm::BasicBlock *CleanupContBB =
+ CGF.createBasicBlock("finally.cleanup.cont");
+
+ llvm::Value *ShouldEndCatch =
+ CGF.Builder.CreateLoad(ForEHVar, "finally.endcatch");
+ CGF.Builder.CreateCondBr(ShouldEndCatch, EndCatchBB, CleanupContBB);
+ CGF.EmitBlock(EndCatchBB);
+ CGF.EmitCallOrInvoke(EndCatchFn, 0, 0); // catch-all, so might throw
+ CGF.EmitBlock(CleanupContBB);
+ }
+ };
+}
+
/// Enters a finally block for an implementation using zero-cost
/// exceptions. This is mostly general, but hard-codes some
/// language/ABI-specific behavior in the catch-all sections.
@@ -1392,19 +1414,9 @@
CodeGenFunction::CleanupBlock Cleanup(*this, NormalCleanup);
// Enter a cleanup to call the end-catch function if one was provided.
- if (EndCatchFn) {
- CodeGenFunction::CleanupBlock FinallyExitCleanup(CGF, NormalAndEHCleanup);
-
- llvm::BasicBlock *EndCatchBB = createBasicBlock("finally.endcatch");
- llvm::BasicBlock *CleanupContBB = createBasicBlock("finally.cleanup.cont");
-
- llvm::Value *ShouldEndCatch =
- Builder.CreateLoad(ForEHVar, "finally.endcatch");
- Builder.CreateCondBr(ShouldEndCatch, EndCatchBB, CleanupContBB);
- EmitBlock(EndCatchBB);
- EmitCallOrInvoke(EndCatchFn, 0, 0); // catch-all, so might throw
- EmitBlock(CleanupContBB);
- }
+ if (EndCatchFn)
+ EHStack.pushLazyCleanup<CallEndCatchForFinally>(NormalAndEHCleanup,
+ ForEHVar, EndCatchFn);
// Emit the finally block.
EmitStmt(Body);
More information about the cfe-commits
mailing list