[PATCH] D55233: Add objc_retain and objc_release intrinsics and codegen them to their runtime methods
Pete Cooper via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 3 13:04:56 PST 2018
pete created this revision.
pete added reviewers: erik.pilkington, ahatanak.
Herald added a subscriber: llvm-commits.
This is the first in a series of patches to move objc retain/release to intrinsics and have the ARC optimizer work on those instead.
For some context, see clang r263607 which converted [a retain] to objc_retain(a). That was ultimately reverted as the ARC optimizer couldn't handle the new calls.
The eventual solution is to move the ARC inserted retain/release calls to intrinsics and only optimize the intrinsics. Manually inserted retain/release will then no longer be optimized.
Repository:
rL LLVM
https://reviews.llvm.org/D55233
Files:
include/llvm/IR/Intrinsics.td
lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
test/CodeGen/X86/objc-arc.ll
Index: test/CodeGen/X86/objc-arc.ll
===================================================================
--- /dev/null
+++ test/CodeGen/X86/objc-arc.ll
@@ -0,0 +1,22 @@
+; RUN: llc < %s -mtriple=x86_64-apple-darwin | FileCheck %s
+
+; Make sure calls to the objc intrinsics are translated to calls in to the runtime
+
+define i8* @test1(i8* %arg) {
+; CHECK-LABEL: test1
+; CHECK: callq _objc_retain
+entry:
+ %0 = call i8* @llvm.objc.retain(i8* %arg)
+ ret i8* %0
+}
+
+define void @test2(i8* %arg) {
+; CHECK-LABEL: test2
+; CHECK: callq _objc_release
+entry:
+ call void @llvm.objc.release(i8* %arg)
+ ret void
+}
+
+declare i8* @llvm.objc.retain(i8*)
+declare void @llvm.objc.release(i8* %arg)
Index: lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -6337,6 +6337,10 @@
// MachineFunction in SelectionDAGISel::PrepareEHLandingPad. We can safely
// delete it now.
return nullptr;
+ case Intrinsic::objc_retain:
+ return "objc_retain";
+ case Intrinsic::objc_release:
+ return "objc_release";
}
}
Index: include/llvm/IR/Intrinsics.td
===================================================================
--- include/llvm/IR/Intrinsics.td
+++ include/llvm/IR/Intrinsics.td
@@ -319,6 +319,11 @@
[llvm_ptr_ty, llvm_ptr_ty, llvm_ptrptr_ty],
[IntrArgMemOnly, NoCapture<1>, NoCapture<2>]>;
+//===------------------- ObjC ARC runtime Intrinsics --------------------===//
+//
+def int_objc_retain : Intrinsic<[llvm_ptr_ty], [llvm_ptr_ty], [Returned<0>]>;
+def int_objc_release : Intrinsic<[], [llvm_ptr_ty]>;
+
//===--------------------- Code Generator Intrinsics ----------------------===//
//
def int_returnaddress : Intrinsic<[llvm_ptr_ty], [llvm_i32_ty], [IntrNoMem]>;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55233.176459.patch
Type: text/x-patch
Size: 1935 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181203/29301e4a/attachment.bin>
More information about the llvm-commits
mailing list