summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CGObjC.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-06-22 16:32:26 +0000
committerDouglas Gregor <dgregor@apple.com>2011-06-22 16:32:26 +0000
commit1c8cd7c1a5a499a23ab251999bb1acc2420023d6 (patch)
tree511eeb5cfef5f19e7e4cdc8545e8047c4e650fb8 /clang/lib/CodeGen/CGObjC.cpp
parent58df509fc0dc288f6859cd3b61ff980d364baf6d (diff)
downloadbcm5719-llvm-1c8cd7c1a5a499a23ab251999bb1acc2420023d6.tar.gz
bcm5719-llvm-1c8cd7c1a5a499a23ab251999bb1acc2420023d6.zip
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 <rdar://problem/9364932>. llvm-svn: 133621
Diffstat (limited to 'clang/lib/CodeGen/CGObjC.cpp')
-rw-r--r--clang/lib/CodeGen/CGObjC.cpp25
1 files changed, 25 insertions, 0 deletions
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<llvm::PointerType>(CGF.ConvertType(exprType)));
+ CGF.EmitStoreOfScalar(null, lv.getAddress(), lv.isVolatileQualified(),
+ lv.getAlignment(), exprType);
+
+ return TryEmitResult(result, true);
+ }
+
while (true) {
e = e->IgnoreParens();
OpenPOWER on IntegriCloud