https://github.com/citymarina updated
https://github.com/llvm/llvm-project/pull/138696
>From e83258e216f89992a7c46eaf3478c7b31e1113dc Mon Sep 17 00:00:00 2001
From: Marina Taylor
Date: Wed, 19 Mar 2025 18:25:09 +
Subject: [PATCH] [ObjC] Support objc_claimAutoreleasedReturnValue.
This adds basic support for objc_claimAutoreleasedReturnValue,
which is mostly equivalent to objc_retainAutoreleasedReturnValue,
with the difference that it doesn't require the marker nop to be
emitted between it and the call it was attached to.
To achieve that, this also teaches the AArch64 attachedcall bundle
lowering to pick whether the marker should be emitted or not
based on whether the attachedcall target is claimARV or retainARV.
Co-authored-by: Ahmed Bougacha
---
llvm/include/llvm/Analysis/ObjCARCUtil.h | 15 ++
llvm/include/llvm/IR/Intrinsics.td| 9 --
llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp | 8 +++---
llvm/lib/IR/Verifier.cpp | 2 ++
.../Target/AArch64/AArch64ISelLowering.cpp| 6 ++--
.../AArch64/GISel/AArch64CallLowering.cpp | 4 +--
llvm/test/CodeGen/AArch64/call-rv-marker.ll | 28 +++
7 files changed, 60 insertions(+), 12 deletions(-)
diff --git a/llvm/include/llvm/Analysis/ObjCARCUtil.h
b/llvm/include/llvm/Analysis/ObjCARCUtil.h
index 62e13eb2a5722..7dc0c50809f06 100644
--- a/llvm/include/llvm/Analysis/ObjCARCUtil.h
+++ b/llvm/include/llvm/Analysis/ObjCARCUtil.h
@@ -48,6 +48,21 @@ inline std::optional
getAttachedARCFunction(const CallBase *CB) {
return cast(B->Inputs[0]);
}
+/// This function determines whether the clang_arc_attachedcall should be
+/// emitted with or without the marker.
+/// Concretely, this is the difference between:
+/// objc_retainAutoreleasedReturnValue
+/// and
+/// objc_claimAutoreleasedReturnValue
+/// retainRV (and unsafeClaimRV) requires a marker, but claimRV does not.
+inline bool attachedCallOpBundleNeedsMarker(const CallBase *CB) {
+ // FIXME: do this on ARCRuntimeEntryPoints, and do the todo above ARCInstKind
+ if (std::optional Fn = getAttachedARCFunction(CB))
+if ((*Fn)->getName() == "objc_claimAutoreleasedReturnValue")
+ return false;
+ return true;
+}
+
/// Check whether the function is retainRV/unsafeClaimRV.
inline bool isRetainOrClaimRV(ARCInstKind Kind) {
return Kind == ARCInstKind::RetainRV || Kind == ARCInstKind::UnsafeClaimRV;
diff --git a/llvm/include/llvm/IR/Intrinsics.td
b/llvm/include/llvm/IR/Intrinsics.td
index a174ccbf61002..53c6e6619764c 100644
--- a/llvm/include/llvm/IR/Intrinsics.td
+++ b/llvm/include/llvm/IR/Intrinsics.td
@@ -777,10 +777,12 @@ def int_objc_loadWeakRetained :
Intrinsic<[llvm_ptr_ty],
def int_objc_moveWeak : Intrinsic<[],
[llvm_ptr_ty,
llvm_ptr_ty]>;
+
def int_objc_release: Intrinsic<[], [llvm_ptr_ty]>;
def int_objc_retain : Intrinsic<[llvm_ptr_ty],
[llvm_ptr_ty],
[Returned>]>;
+
def int_objc_retainAutorelease : Intrinsic<[llvm_ptr_ty],
[llvm_ptr_ty],
[Returned>]>;
@@ -789,6 +791,11 @@ def int_objc_retainAutoreleaseReturnValue :
Intrinsic<[llvm_ptr_ty],
[Returned>]>;
def int_objc_retainAutoreleasedReturnValue : Intrinsic<[llvm_ptr_ty],
[llvm_ptr_ty]>;
+def int_objc_unsafeClaimAutoreleasedReturnValue : Intrinsic<[llvm_ptr_ty],
+[llvm_ptr_ty]>;
+def int_objc_claimAutoreleasedReturnValue : Intrinsic<[llvm_ptr_ty],
+[llvm_ptr_ty]>;
+
def int_objc_retainBlock: Intrinsic<[llvm_ptr_ty],
[llvm_ptr_ty]>;
def int_objc_storeStrong: Intrinsic<[],
@@ -802,8 +809,6 @@ def int_objc_clang_arc_use : Intrinsic<[],
def int_objc_clang_arc_noop_use : DefaultAttrsIntrinsic<[],
[llvm_vararg_ty],
[IntrInaccessibleMemOnly]>;
-def int_objc_unsafeClaimAutoreleasedReturnValue : Intrinsic<[llvm_ptr_ty],
-[llvm_ptr_ty]>;
def int_objc_retainedObject : Intrinsic<[llvm_ptr_ty],
[llvm_ptr_ty]>;
def int_objc_unretainedObject : Intrinsic<[llvm_ptr_ty],
diff --git a/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
b/