Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b410f3b

Browse filesBrowse files
[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 <ahmed@bougacha.org>
1 parent 0917519 commit b410f3b
Copy full SHA for b410f3b

File tree

6 files changed

+32
-8
lines changed
Filter options

6 files changed

+32
-8
lines changed

‎llvm/include/llvm/Analysis/ObjCARCUtil.h

Copy file name to clipboardExpand all lines: llvm/include/llvm/Analysis/ObjCARCUtil.h
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,21 @@ inline std::optional<Function *> getAttachedARCFunction(const CallBase *CB) {
4848
return cast<Function>(B->Inputs[0]);
4949
}
5050

51+
/// This function determines whether the clang_arc_attachedcall should be
52+
/// emitted with or without the marker.
53+
/// Concretely, this is the difference between:
54+
/// objc_retainAutoreleasedReturnValue
55+
/// and
56+
/// objc_claimAutoreleasedReturnValue
57+
/// retainRV (and unsafeClaimRV) requires a marker, but claimRV does not.
58+
inline bool attachedCallOpBundleNeedsMarker(const CallBase *CB) {
59+
// FIXME: do this on ARCRuntimeEntryPoints, and do the todo above ARCInstKind
60+
if (std::optional<Function *> Fn = getAttachedARCFunction(CB))
61+
if ((*Fn)->getName() == "objc_claimAutoreleasedReturnValue")
62+
return false;
63+
return true;
64+
}
65+
5166
/// Check whether the function is retainRV/unsafeClaimRV.
5267
inline bool isRetainOrClaimRV(ARCInstKind Kind) {
5368
return Kind == ARCInstKind::RetainRV || Kind == ARCInstKind::UnsafeClaimRV;

‎llvm/include/llvm/IR/Intrinsics.td

Copy file name to clipboardExpand all lines: llvm/include/llvm/IR/Intrinsics.td
+7-2Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -777,10 +777,12 @@ def int_objc_loadWeakRetained : Intrinsic<[llvm_ptr_ty],
777777
def int_objc_moveWeak : Intrinsic<[],
778778
[llvm_ptr_ty,
779779
llvm_ptr_ty]>;
780+
780781
def int_objc_release : Intrinsic<[], [llvm_ptr_ty]>;
781782
def int_objc_retain : Intrinsic<[llvm_ptr_ty],
782783
[llvm_ptr_ty],
783784
[Returned<ArgIndex<0>>]>;
785+
784786
def int_objc_retainAutorelease : Intrinsic<[llvm_ptr_ty],
785787
[llvm_ptr_ty],
786788
[Returned<ArgIndex<0>>]>;
@@ -789,6 +791,11 @@ def int_objc_retainAutoreleaseReturnValue : Intrinsic<[llvm_ptr_ty],
789791
[Returned<ArgIndex<0>>]>;
790792
def int_objc_retainAutoreleasedReturnValue : Intrinsic<[llvm_ptr_ty],
791793
[llvm_ptr_ty]>;
794+
def int_objc_unsafeClaimAutoreleasedReturnValue : Intrinsic<[llvm_ptr_ty],
795+
[llvm_ptr_ty]>;
796+
def int_objc_claimAutoreleasedReturnValue : Intrinsic<[llvm_ptr_ty],
797+
[llvm_ptr_ty]>;
798+
792799
def int_objc_retainBlock : Intrinsic<[llvm_ptr_ty],
793800
[llvm_ptr_ty]>;
794801
def int_objc_storeStrong : Intrinsic<[],
@@ -802,8 +809,6 @@ def int_objc_clang_arc_use : Intrinsic<[],
802809
def int_objc_clang_arc_noop_use : DefaultAttrsIntrinsic<[],
803810
[llvm_vararg_ty],
804811
[IntrInaccessibleMemOnly]>;
805-
def int_objc_unsafeClaimAutoreleasedReturnValue : Intrinsic<[llvm_ptr_ty],
806-
[llvm_ptr_ty]>;
807812
def int_objc_retainedObject : Intrinsic<[llvm_ptr_ty],
808813
[llvm_ptr_ty]>;
809814
def int_objc_unretainedObject : Intrinsic<[llvm_ptr_ty],

‎llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp

Copy file name to clipboardExpand all lines: llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,7 @@ static bool lowerObjCCall(Function &F, const char *NewFn,
160160
auto *CB = cast<CallBase>(U.getUser());
161161

162162
if (CB->getCalledFunction() != &F) {
163-
objcarc::ARCInstKind Kind = objcarc::getAttachedARCFunctionKind(CB);
164-
(void)Kind;
165-
assert((Kind == objcarc::ARCInstKind::RetainRV ||
166-
Kind == objcarc::ARCInstKind::UnsafeClaimRV) &&
163+
assert((*objcarc::getAttachedARCFunction(CB) == &F) &&
167164
"use expected to be the argument of operand bundle "
168165
"\"clang.arc.attachedcall\"");
169166
U.set(FCache.getCallee());
@@ -529,6 +526,9 @@ bool PreISelIntrinsicLowering::lowerIntrinsics(Module &M) const {
529526
case Intrinsic::objc_retainAutoreleasedReturnValue:
530527
Changed |= lowerObjCCall(F, "objc_retainAutoreleasedReturnValue");
531528
break;
529+
case Intrinsic::objc_claimAutoreleasedReturnValue:
530+
Changed |= lowerObjCCall(F, "objc_claimAutoreleasedReturnValue");
531+
break;
532532
case Intrinsic::objc_retainBlock:
533533
Changed |= lowerObjCCall(F, "objc_retainBlock");
534534
break;

‎llvm/lib/IR/Verifier.cpp

Copy file name to clipboardExpand all lines: llvm/lib/IR/Verifier.cpp
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7282,11 +7282,13 @@ void Verifier::verifyAttachedCallBundle(const CallBase &Call,
72827282

72837283
if (IID) {
72847284
Check((IID == Intrinsic::objc_retainAutoreleasedReturnValue ||
7285+
IID == Intrinsic::objc_claimAutoreleasedReturnValue ||
72857286
IID == Intrinsic::objc_unsafeClaimAutoreleasedReturnValue),
72867287
"invalid function argument", Call);
72877288
} else {
72887289
StringRef FnName = Fn->getName();
72897290
Check((FnName == "objc_retainAutoreleasedReturnValue" ||
7291+
FnName == "objc_claimAutoreleasedReturnValue" ||
72907292
FnName == "objc_unsafeClaimAutoreleasedReturnValue"),
72917293
"invalid function argument", Call);
72927294
}

‎llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Copy file name to clipboardExpand all lines: llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9545,7 +9545,9 @@ AArch64TargetLowering::LowerCall(CallLoweringInfo &CLI,
95459545
// Do what the frontend tells us: if the rvmarker module flag is present,
95469546
// emit the marker. Always emit the call regardless.
95479547
// Tell the pseudo expansion using an additional boolean op.
9548-
SDValue DoEmitMarker = DAG.getTargetConstant(true, DL, MVT::i32);
9548+
bool ShouldEmitMarker = objcarc::attachedCallOpBundleNeedsMarker(CLI.CB);
9549+
SDValue DoEmitMarker =
9550+
DAG.getTargetConstant(ShouldEmitMarker, DL, MVT::i32);
95499551
Ops.insert(Ops.begin() + 2, DoEmitMarker);
95509552
} else if (CallConv == CallingConv::ARM64EC_Thunk_X64) {
95519553
Opc = AArch64ISD::CALL_ARM64EC_TO_X64;

‎llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp

Copy file name to clipboardExpand all lines: llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,7 @@ bool AArch64CallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
13691369
// Do what the frontend tells us: if the rvmarker module flag is present,
13701370
// emit the marker. Always emit the call regardless.
13711371
// Tell the pseudo expansion using an additional boolean op.
1372-
MIB.addImm(true);
1372+
MIB.addImm(objcarc::attachedCallOpBundleNeedsMarker(Info.CB));
13731373
++CalleeOpNo;
13741374
} else if (Info.CFIType) {
13751375
MIB->setCFIType(MF, Info.CFIType->getZExtValue());

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.