aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib
diff options
context:
space:
mode:
authorMarina Taylor <marina_taylor@apple.com>2025-05-13 16:04:49 +0100
committerGitHub <noreply@github.com>2025-05-13 16:04:49 +0100
commit4b794c8aff3ba01d95bd29973f45ff776aaee3ed (patch)
tree8a14756263c68e3f41c6c355cd342697c380aa48 /llvm/lib
parente4b6cc314a459b803ea6b3dc8b63da38d1dd50db (diff)
downloadllvm-4b794c8aff3ba01d95bd29973f45ff776aaee3ed.zip
llvm-4b794c8aff3ba01d95bd29973f45ff776aaee3ed.tar.gz
llvm-4b794c8aff3ba01d95bd29973f45ff776aaee3ed.tar.bz2
[ObjC] Support objc_claimAutoreleasedReturnValue (#139720)
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 <ahmed@bougacha.org>
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp8
-rw-r--r--llvm/lib/IR/Verifier.cpp2
-rw-r--r--llvm/lib/Target/AArch64/AArch64ISelLowering.cpp6
-rw-r--r--llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp4
4 files changed, 10 insertions, 10 deletions
diff --git a/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp b/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
index 1c29123..6f52b7c 100644
--- a/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
+++ b/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
@@ -160,10 +160,7 @@ static bool lowerObjCCall(Function &F, const char *NewFn,
auto *CB = cast<CallBase>(U.getUser());
if (CB->getCalledFunction() != &F) {
- objcarc::ARCInstKind Kind = objcarc::getAttachedARCFunctionKind(CB);
- (void)Kind;
- assert((Kind == objcarc::ARCInstKind::RetainRV ||
- Kind == objcarc::ARCInstKind::UnsafeClaimRV) &&
+ assert(objcarc::getAttachedARCFunction(CB) == &F &&
"use expected to be the argument of operand bundle "
"\"clang.arc.attachedcall\"");
U.set(FCache.getCallee());
@@ -529,6 +526,9 @@ bool PreISelIntrinsicLowering::lowerIntrinsics(Module &M) const {
case Intrinsic::objc_retainAutoreleasedReturnValue:
Changed |= lowerObjCCall(F, "objc_retainAutoreleasedReturnValue");
break;
+ case Intrinsic::objc_claimAutoreleasedReturnValue:
+ Changed |= lowerObjCCall(F, "objc_claimAutoreleasedReturnValue");
+ break;
case Intrinsic::objc_retainBlock:
Changed |= lowerObjCCall(F, "objc_retainBlock");
break;
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index da6963a..81cf53f 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -7283,11 +7283,13 @@ void Verifier::verifyAttachedCallBundle(const CallBase &Call,
if (IID) {
Check((IID == Intrinsic::objc_retainAutoreleasedReturnValue ||
+ IID == Intrinsic::objc_claimAutoreleasedReturnValue ||
IID == Intrinsic::objc_unsafeClaimAutoreleasedReturnValue),
"invalid function argument", Call);
} else {
StringRef FnName = Fn->getName();
Check((FnName == "objc_retainAutoreleasedReturnValue" ||
+ FnName == "objc_claimAutoreleasedReturnValue" ||
FnName == "objc_unsafeClaimAutoreleasedReturnValue"),
"invalid function argument", Call);
}
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index ad48be4..13fb6a3 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -9545,10 +9545,10 @@ AArch64TargetLowering::LowerCall(CallLoweringInfo &CLI,
Ops.insert(Ops.begin() + 1, GA);
// We may or may not need to emit both the marker and the retain/claim call.
- // Do what the frontend tells us: if the rvmarker module flag is present,
- // emit the marker. Always emit the call regardless.
// Tell the pseudo expansion using an additional boolean op.
- SDValue DoEmitMarker = DAG.getTargetConstant(true, DL, MVT::i32);
+ bool ShouldEmitMarker = objcarc::attachedCallOpBundleNeedsMarker(CLI.CB);
+ SDValue DoEmitMarker =
+ DAG.getTargetConstant(ShouldEmitMarker, DL, MVT::i32);
Ops.insert(Ops.begin() + 2, DoEmitMarker);
} else if (CallConv == CallingConv::ARM64EC_Thunk_X64) {
Opc = AArch64ISD::CALL_ARM64EC_TO_X64;
diff --git a/llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp b/llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp
index 91e4536..9bef102 100644
--- a/llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp
+++ b/llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp
@@ -1366,10 +1366,8 @@ bool AArch64CallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
++CalleeOpNo;
// We may or may not need to emit both the marker and the retain/claim call.
- // Do what the frontend tells us: if the rvmarker module flag is present,
- // emit the marker. Always emit the call regardless.
// Tell the pseudo expansion using an additional boolean op.
- MIB.addImm(true);
+ MIB.addImm(objcarc::attachedCallOpBundleNeedsMarker(Info.CB));
++CalleeOpNo;
} else if (Info.CFIType) {
MIB->setCFIType(MF, Info.CFIType->getZExtValue());