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 d33e5c5

Browse filesBrowse files
[ObjC] Support objc_claimAutoreleasedReturnValue (#138696)
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 d33e5c5
Copy full SHA for d33e5c5

File tree

7 files changed

+60
-12
lines changed
Filter options

7 files changed

+60
-12
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-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9542,10 +9542,10 @@ AArch64TargetLowering::LowerCall(CallLoweringInfo &CLI,
95429542
Ops.insert(Ops.begin() + 1, GA);
95439543

95449544
// We may or may not need to emit both the marker and the retain/claim call.
9545-
// Do what the frontend tells us: if the rvmarker module flag is present,
9546-
// emit the marker. Always emit the call regardless.
95479545
// Tell the pseudo expansion using an additional boolean op.
9548-
SDValue DoEmitMarker = DAG.getTargetConstant(true, DL, MVT::i32);
9546+
bool ShouldEmitMarker = objcarc::attachedCallOpBundleNeedsMarker(CLI.CB);
9547+
SDValue DoEmitMarker =
9548+
DAG.getTargetConstant(ShouldEmitMarker, DL, MVT::i32);
95499549
Ops.insert(Ops.begin() + 2, DoEmitMarker);
95509550
} else if (CallConv == CallingConv::ARM64EC_Thunk_X64) {
95519551
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-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,10 +1366,8 @@ bool AArch64CallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
13661366
++CalleeOpNo;
13671367

13681368
// We may or may not need to emit both the marker and the retain/claim call.
1369-
// Do what the frontend tells us: if the rvmarker module flag is present,
1370-
// emit the marker. Always emit the call regardless.
13711369
// Tell the pseudo expansion using an additional boolean op.
1372-
MIB.addImm(true);
1370+
MIB.addImm(objcarc::attachedCallOpBundleNeedsMarker(Info.CB));
13731371
++CalleeOpNo;
13741372
} else if (Info.CFIType) {
13751373
MIB->setCFIType(MF, Info.CFIType->getZExtValue());

‎llvm/test/CodeGen/AArch64/call-rv-marker.ll

Copy file name to clipboardExpand all lines: llvm/test/CodeGen/AArch64/call-rv-marker.ll
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,35 @@ define dso_local void @rv_marker_multiarg(i64 %a, i64 %b, i64 %c) {
544544
ret void
545545
}
546546

547+
define dso_local ptr @rv_marker_claim() {
548+
; SELDAG-LABEL: rv_marker_claim:
549+
; SELDAG: ; %bb.0: ; %entry
550+
; SELDAG-NEXT: stp x29, x30, [sp, #-16]! ; 16-byte Folded Spill
551+
; SELDAG-NEXT: .cfi_def_cfa_offset 16
552+
; SELDAG-NEXT: .cfi_offset w30, -8
553+
; SELDAG-NEXT: .cfi_offset w29, -16
554+
; SELDAG-NEXT: bl _foo1
555+
; SELDAG-NEXT: bl _objc_claimAutoreleasedReturnValue
556+
; SELDAG-NEXT: ldp x29, x30, [sp], #16 ; 16-byte Folded Reload
557+
; SELDAG-NEXT: ret
558+
;
559+
; GISEL-LABEL: rv_marker_claim:
560+
; GISEL: ; %bb.0: ; %entry
561+
; GISEL-NEXT: stp x29, x30, [sp, #-16]! ; 16-byte Folded Spill
562+
; GISEL-NEXT: .cfi_def_cfa_offset 16
563+
; GISEL-NEXT: .cfi_offset w30, -8
564+
; GISEL-NEXT: .cfi_offset w29, -16
565+
; GISEL-NEXT: bl _foo1
566+
; GISEL-NEXT: bl _objc_claimAutoreleasedReturnValue
567+
; GISEL-NEXT: ldp x29, x30, [sp], #16 ; 16-byte Folded Reload
568+
; GISEL-NEXT: ret
569+
entry:
570+
%call = call ptr @foo1() [ "clang.arc.attachedcall"(ptr @objc_claimAutoreleasedReturnValue) ]
571+
ret ptr %call
572+
}
573+
547574
declare ptr @objc_retainAutoreleasedReturnValue(ptr)
575+
declare ptr @objc_claimAutoreleasedReturnValue(ptr)
548576
declare ptr @objc_unsafeClaimAutoreleasedReturnValue(ptr)
549577
declare i32 @__gxx_personality_v0(...)
550578
;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:

0 commit comments

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