[cfe-commits] r108995 - /cfe/trunk/lib/CodeGen/CGTemporaries.cpp
John McCall
rjmccall at apple.com
Tue Jul 20 23:44:29 PDT 2010
Author: rjmccall
Date: Wed Jul 21 01:44:28 2010
New Revision: 108995
URL: http://llvm.org/viewvc/llvm-project?rev=108995&view=rev
Log:
Switch the main possibly-conditional temporary cleanup over to being lazy.
Modified:
cfe/trunk/lib/CodeGen/CGTemporaries.cpp
Modified: cfe/trunk/lib/CodeGen/CGTemporaries.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGTemporaries.cpp?rev=108995&r1=108994&r2=108995&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGTemporaries.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGTemporaries.cpp Wed Jul 21 01:44:28 2010
@@ -15,34 +15,43 @@
using namespace clang;
using namespace CodeGen;
-static void EmitTemporaryCleanup(CodeGenFunction &CGF,
- const CXXTemporary *Temporary,
- llvm::Value *Addr,
- llvm::Value *CondPtr) {
- llvm::BasicBlock *CondEnd = 0;
-
- // If this is a conditional temporary, we need to check the condition
- // boolean and only call the destructor if it's true.
- if (CondPtr) {
- llvm::BasicBlock *CondBlock = CGF.createBasicBlock("temp.cond-dtor.call");
- CondEnd = CGF.createBasicBlock("temp.cond-dtor.cont");
-
- llvm::Value *Cond = CGF.Builder.CreateLoad(CondPtr);
- CGF.Builder.CreateCondBr(Cond, CondBlock, CondEnd);
- CGF.EmitBlock(CondBlock);
- }
+namespace {
+ struct DestroyTemporary : EHScopeStack::LazyCleanup {
+ const CXXTemporary *Temporary;
+ llvm::Value *Addr;
+ llvm::Value *CondPtr;
+
+ DestroyTemporary(const CXXTemporary *Temporary, llvm::Value *Addr,
+ llvm::Value *CondPtr)
+ : Temporary(Temporary), Addr(Addr), CondPtr(CondPtr) {}
- CGF.EmitCXXDestructorCall(Temporary->getDestructor(),
- Dtor_Complete, /*ForVirtualBase=*/false,
- Addr);
-
- if (CondPtr) {
- // Reset the condition to false.
- CGF.Builder.CreateStore(llvm::ConstantInt::getFalse(CGF.getLLVMContext()),
- CondPtr);
- CGF.EmitBlock(CondEnd);
- }
-}
+ void Emit(CodeGenFunction &CGF, bool IsForEH) {
+ llvm::BasicBlock *CondEnd = 0;
+
+ // If this is a conditional temporary, we need to check the condition
+ // boolean and only call the destructor if it's true.
+ if (CondPtr) {
+ llvm::BasicBlock *CondBlock =
+ CGF.createBasicBlock("temp.cond-dtor.call");
+ CondEnd = CGF.createBasicBlock("temp.cond-dtor.cont");
+
+ llvm::Value *Cond = CGF.Builder.CreateLoad(CondPtr);
+ CGF.Builder.CreateCondBr(Cond, CondBlock, CondEnd);
+ CGF.EmitBlock(CondBlock);
+ }
+
+ CGF.EmitCXXDestructorCall(Temporary->getDestructor(),
+ Dtor_Complete, /*ForVirtualBase=*/false,
+ Addr);
+
+ if (CondPtr) {
+ // Reset the condition to false.
+ CGF.Builder.CreateStore(CGF.Builder.getFalse(), CondPtr);
+ CGF.EmitBlock(CondEnd);
+ }
+ }
+ };
+}
/// Emits all the code to cause the given temporary to be cleaned up.
void CodeGenFunction::EmitCXXTemporary(const CXXTemporary *Temporary,
@@ -59,16 +68,11 @@
InitTempAlloca(CondPtr, llvm::ConstantInt::getFalse(VMContext));
// Now set it to true.
- Builder.CreateStore(llvm::ConstantInt::getTrue(VMContext), CondPtr);
+ Builder.CreateStore(Builder.getTrue(), CondPtr);
}
- CleanupBlock Cleanup(*this, NormalCleanup);
- EmitTemporaryCleanup(*this, Temporary, Ptr, CondPtr);
-
- if (Exceptions) {
- Cleanup.beginEHCleanup();
- EmitTemporaryCleanup(*this, Temporary, Ptr, CondPtr);
- }
+ EHStack.pushLazyCleanup<DestroyTemporary>(NormalAndEHCleanup,
+ Temporary, Ptr, CondPtr);
}
RValue
More information about the cfe-commits
mailing list