summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CGObjC.cpp
diff options
context:
space:
mode:
authorSaleem Abdulrasool <compnerd@compnerd.org>2017-02-11 21:34:18 +0000
committerSaleem Abdulrasool <compnerd@compnerd.org>2017-02-11 21:34:18 +0000
commitc30cec26edd0f4de40d399ea28f87d47cc040680 (patch)
tree5f9f02a545b03213590d8ddf79f9a420e416b08f /clang/lib/CodeGen/CGObjC.cpp
parent96e24877a09ed8e33bc0d63aeed0a8435d32592a (diff)
downloadbcm5719-llvm-c30cec26edd0f4de40d399ea28f87d47cc040680.tar.gz
bcm5719-llvm-c30cec26edd0f4de40d399ea28f87d47cc040680.zip
CodeGen: annotate ObjC ARC functions with ABI constraints
Certain ARC runtime functions have an ABI contract of being forwarding. Annotate the functions with the appropriate `returned` attribute on the arguments. This hoists some of the runtime ABI contract information into the frontend rather than the backend transformations. The test adjustments are to mark the returned function parameter as such. The minor change to the IR output is due to the fact that the returned reference of the object causes it to extend the lifetime of the object by returning an autoreleased return value. The result is that the explicit objc_autorelease call is no longer formed, as autorelease elision is now possible on the return. llvm-svn: 294872
Diffstat (limited to 'clang/lib/CodeGen/CGObjC.cpp')
-rw-r--r--clang/lib/CodeGen/CGObjC.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp
index 1ca56df37ff..304288de6da 100644
--- a/clang/lib/CodeGen/CGObjC.cpp
+++ b/clang/lib/CodeGen/CGObjC.cpp
@@ -1802,6 +1802,22 @@ void CodeGenFunction::EmitARCIntrinsicUse(ArrayRef<llvm::Value*> values) {
}
+static bool IsForwarding(StringRef Name) {
+ return llvm::StringSwitch<bool>(Name)
+ .Cases("objc_autoreleaseReturnValue", // ARCInstKind::AutoreleaseRV
+ "objc_autorelease", // ARCInstKind::Autorelease
+ "objc_retainAutoreleaseReturnValue", // ARCInstKind::FusedRetainAutoreleaseRV
+ "objc_retainAutoreleasedReturnValue", // ARCInstKind::RetainRV
+ "objc_retainAutorelease", // ARCInstKind::FusedRetainAutorelease
+ "objc_retainedObject", // ARCInstKind::NoopCast
+ "objc_retain", // ARCInstKind::Retain
+ "objc_unretainedObject", // ARCInstKind::NoopCast
+ "objc_unretainedPointer", // ARCInstKind::NoopCast
+ "objc_unsafeClaimAutoreleasedReturnValue", // ARCInstKind::ClaimRV
+ true)
+ .Default(false);
+}
+
static llvm::Constant *createARCRuntimeFunction(CodeGenModule &CGM,
llvm::FunctionType *FTy,
StringRef Name) {
@@ -1819,6 +1835,13 @@ static llvm::Constant *createARCRuntimeFunction(CodeGenModule &CGM,
// performance.
F->addFnAttr(llvm::Attribute::NonLazyBind);
}
+
+ if (IsForwarding(Name)) {
+ llvm::AttrBuilder B;
+ B.addAttribute(llvm::Attribute::Returned);
+
+ F->arg_begin()->addAttr(llvm::AttributeSet::get(F->getContext(), 1, B));
+ }
}
return RTF;
OpenPOWER on IntegriCloud