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]>; 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: 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)