From 1c8cd7c1a5a499a23ab251999bb1acc2420023d6 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Wed, 22 Jun 2011 16:32:26 +0000 Subject: Implement the C++0x move optimization for Automatic Reference Counting objects, so that we steal the retain count of a temporary __strong pointer (zeroing out that temporary), eliding a retain/release pair. Addresses . llvm-svn: 133621 --- clang/lib/CodeGen/CGObjC.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'clang/lib/CodeGen/CGObjC.cpp') diff --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp index a43f4511096..1849dee1232 100644 --- a/clang/lib/CodeGen/CGObjC.cpp +++ b/clang/lib/CodeGen/CGObjC.cpp @@ -2268,6 +2268,31 @@ tryEmitARCRetainScalarExpr(CodeGenFunction &CGF, const Expr *e) { // ultimate opaque expression. const llvm::Type *resultType = 0; + // If we're loading retained from a __strong xvalue, we can avoid + // an extra retain/release pair by zeroing out the source of this + // "move" operation. + if (e->isXValue() && + e->getType().getObjCLifetime() == Qualifiers::OCL_Strong) { + // Emit the lvalue + LValue lv = CGF.EmitLValue(e); + + // Load the object pointer and cast it to the appropriate type. + QualType exprType = e->getType(); + llvm::Value *result = CGF.EmitLoadOfLValue(lv, exprType).getScalarVal(); + + if (resultType) + result = CGF.Builder.CreateBitCast(result, resultType); + + // Set the source pointer to NULL. + llvm::Value *null + = llvm::ConstantPointerNull::get( + cast(CGF.ConvertType(exprType))); + CGF.EmitStoreOfScalar(null, lv.getAddress(), lv.isVolatileQualified(), + lv.getAlignment(), exprType); + + return TryEmitResult(result, true); + } + while (true) { e = e->IgnoreParens(); -- cgit v1.2.3