1 ; RUN: opt -mtriple=x86_64-pc-linux-gnu -pre-isel-intrinsic-lowering -S -o - %s | FileCheck %s
2 ; RUN: opt -mtriple=x86_64-pc-linux-gnu -passes=pre-isel-intrinsic-lowering -S -o - %s | FileCheck %s
4 ; Make sure calls to the objc intrinsics are translated to calls in to the
8 declare i32 @__gxx_personality_v0(...)
10 define ptr @test_objc_autorelease(ptr %arg0) {
11 ; CHECK-LABEL: test_objc_autorelease
13 ; CHECK-NEXT: %0 = notail call ptr @objc_autorelease(ptr returned %arg0)
14 ; CHECK-NEXT: ret ptr %0
16 %0 = call ptr @llvm.objc.autorelease(ptr %arg0)
20 define void @test_objc_autoreleasePoolPop(ptr %arg0) {
21 ; CHECK-LABEL: test_objc_autoreleasePoolPop
23 ; CHECK-NEXT: call void @objc_autoreleasePoolPop(ptr %arg0)
24 ; CHECK-NEXT: ret void
26 call void @llvm.objc.autoreleasePoolPop(ptr %arg0)
30 define ptr @test_objc_autoreleasePoolPush() {
31 ; CHECK-LABEL: test_objc_autoreleasePoolPush
33 ; CHECK-NEXT: %0 = call ptr @objc_autoreleasePoolPush()
34 ; CHECK-NEXT: ret ptr %0
36 %0 = call ptr @llvm.objc.autoreleasePoolPush()
40 define ptr @test_objc_autoreleaseReturnValue(ptr %arg0) {
41 ; CHECK-LABEL: test_objc_autoreleaseReturnValue
43 ; CHECK-NEXT: %0 = tail call ptr @objc_autoreleaseReturnValue(ptr returned %arg0)
44 ; CHECK-NEXT: ret ptr %0
46 %0 = call ptr @llvm.objc.autoreleaseReturnValue(ptr %arg0)
50 define void @test_objc_copyWeak(ptr %arg0, ptr %arg1) {
51 ; CHECK-LABEL: test_objc_copyWeak
53 ; CHECK-NEXT: call void @objc_copyWeak(ptr %arg0, ptr %arg1)
54 ; CHECK-NEXT: ret void
56 call void @llvm.objc.copyWeak(ptr %arg0, ptr %arg1)
60 define void @test_objc_destroyWeak(ptr %arg0) {
61 ; CHECK-LABEL: test_objc_destroyWeak
63 ; CHECK-NEXT: call void @objc_destroyWeak(ptr %arg0)
64 ; CHECK-NEXT: ret void
66 call void @llvm.objc.destroyWeak(ptr %arg0)
70 define ptr @test_objc_initWeak(ptr %arg0, ptr %arg1) {
71 ; CHECK-LABEL: test_objc_initWeak
73 ; CHECK-NEXT: %0 = call ptr @objc_initWeak(ptr %arg0, ptr %arg1)
74 ; CHECK-NEXT: ret ptr %0
76 %0 = call ptr @llvm.objc.initWeak(ptr %arg0, ptr %arg1)
80 define ptr @test_objc_loadWeak(ptr %arg0) {
81 ; CHECK-LABEL: test_objc_loadWeak
83 ; CHECK-NEXT: %0 = call ptr @objc_loadWeak(ptr %arg0)
84 ; CHECK-NEXT: ret ptr %0
86 %0 = call ptr @llvm.objc.loadWeak(ptr %arg0)
90 define ptr @test_objc_loadWeakRetained(ptr %arg0) {
91 ; CHECK-LABEL: test_objc_loadWeakRetained
93 ; CHECK-NEXT: %0 = call ptr @objc_loadWeakRetained(ptr %arg0)
94 ; CHECK-NEXT: ret ptr %0
96 %0 = call ptr @llvm.objc.loadWeakRetained(ptr %arg0)
100 define void @test_objc_moveWeak(ptr %arg0, ptr %arg1) {
101 ; CHECK-LABEL: test_objc_moveWeak
103 ; CHECK-NEXT: call void @objc_moveWeak(ptr %arg0, ptr %arg1)
104 ; CHECK-NEXT: ret void
106 call void @llvm.objc.moveWeak(ptr %arg0, ptr %arg1)
110 define void @test_objc_release(ptr %arg0) {
111 ; CHECK-LABEL: test_objc_release
113 ; CHECK-NEXT: call void @objc_release(ptr %arg0)
114 ; CHECK-NEXT: ret void
116 call void @llvm.objc.release(ptr %arg0)
120 define ptr @test_objc_retain(ptr %arg0) {
121 ; CHECK-LABEL: test_objc_retain
123 ; CHECK-NEXT: %0 = tail call ptr @objc_retain(ptr returned %arg0)
124 ; CHECK-NEXT: ret ptr %0
126 %0 = call ptr @llvm.objc.retain(ptr %arg0)
130 define ptr @test_objc_retainAutorelease(ptr %arg0) {
131 ; CHECK-LABEL: test_objc_retainAutorelease
133 ; CHECK-NEXT: %0 = call ptr @objc_retainAutorelease(ptr returned %arg0)
134 ; CHECK-NEXT: ret ptr %0
136 %0 = call ptr @llvm.objc.retainAutorelease(ptr %arg0)
140 define ptr @test_objc_retainAutoreleaseReturnValue(ptr %arg0) {
141 ; CHECK-LABEL: test_objc_retainAutoreleaseReturnValue
143 ; CHECK-NEXT: %0 = tail call ptr @objc_retainAutoreleaseReturnValue(ptr returned %arg0)
144 ; CHECK-NEXT: ret ptr %0
146 %0 = tail call ptr @llvm.objc.retainAutoreleaseReturnValue(ptr %arg0)
150 ; Note: we don't want this intrinsic to have its argument marked 'returned',
151 ; since that breaks the autorelease elision marker optimization when
152 ; save/restores of the reciever are introduced between the msg send and the
153 ; retain. See issue#69658.
154 define ptr @test_objc_retainAutoreleasedReturnValue(ptr %arg0) {
155 ; CHECK-LABEL: test_objc_retainAutoreleasedReturnValue
157 ; CHECK-NEXT: %0 = tail call ptr @objc_retainAutoreleasedReturnValue(ptr %arg0)
158 ; CHECK-NEXT: ret ptr %0
160 %0 = call ptr @llvm.objc.retainAutoreleasedReturnValue(ptr %arg0)
164 define void @test_objc_retainAutoreleasedReturnValue_bundle() {
165 ; CHECK-LABEL: test_objc_retainAutoreleasedReturnValue_bundle(
166 ; CHECK-NEXT: call ptr @foo() [ "clang.arc.attachedcall"(ptr @objc_retainAutoreleasedReturnValue) ]
167 call ptr @foo() [ "clang.arc.attachedcall"(ptr @llvm.objc.retainAutoreleasedReturnValue) ]
171 define void @test_objc_retainAutoreleasedReturnValue_bundle_invoke() personality ptr @__gxx_personality_v0 {
172 ; CHECK-LABEL: test_objc_retainAutoreleasedReturnValue_bundle_invoke(
174 ; CHECK-NEXT: invoke ptr @foo() [ "clang.arc.attachedcall"(ptr @objc_retainAutoreleasedReturnValue) ]
176 invoke ptr @foo() [ "clang.arc.attachedcall"(ptr @llvm.objc.retainAutoreleasedReturnValue) ]
177 to label %invoke.cont unwind label %lpad
183 %1 = landingpad { ptr, i32 }
185 resume { ptr, i32 } %1
188 define ptr @test_objc_retainBlock(ptr %arg0) {
189 ; CHECK-LABEL: test_objc_retainBlock
191 ; CHECK-NEXT: %0 = call ptr @objc_retainBlock(ptr %arg0)
192 ; CHECK-NEXT: ret ptr %0
194 %0 = call ptr @llvm.objc.retainBlock(ptr %arg0)
198 define void @test_objc_storeStrong(ptr %arg0, ptr %arg1) {
199 ; CHECK-LABEL: test_objc_storeStrong
201 ; CHECK-NEXT: call void @objc_storeStrong(ptr %arg0, ptr %arg1)
202 ; CHECK-NEXT: ret void
204 call void @llvm.objc.storeStrong(ptr %arg0, ptr %arg1)
208 define ptr @test_objc_storeWeak(ptr %arg0, ptr %arg1) {
209 ; CHECK-LABEL: test_objc_storeWeak
211 ; CHECK-NEXT: %0 = call ptr @objc_storeWeak(ptr %arg0, ptr %arg1)
212 ; CHECK-NEXT: ret ptr %0
214 %0 = call ptr @llvm.objc.storeWeak(ptr %arg0, ptr %arg1)
218 ; Note: we don't want this intrinsic to have its argument marked 'returned',
219 ; since that breaks the autorelease elision marker optimization when
220 ; save/restores of the reciever are introduced between the msg send and the
221 ; claim. See issue#69658.
222 define ptr @test_objc_unsafeClaimAutoreleasedReturnValue(ptr %arg0) {
223 ; CHECK-LABEL: test_objc_unsafeClaimAutoreleasedReturnValue
225 ; CHECK-NEXT: %0 = tail call ptr @objc_unsafeClaimAutoreleasedReturnValue(ptr %arg0)
226 ; CHECK-NEXT: ret ptr %0
228 %0 = call ptr @llvm.objc.unsafeClaimAutoreleasedReturnValue(ptr %arg0)
232 define void @test_objc_unsafeClaimAutoreleasedReturnValue_bundle() {
233 ; CHECK-LABEL: test_objc_unsafeClaimAutoreleasedReturnValue_bundle(
234 ; CHECK-NEXT: call ptr @foo() [ "clang.arc.attachedcall"(ptr @objc_unsafeClaimAutoreleasedReturnValue) ]
235 call ptr @foo() [ "clang.arc.attachedcall"(ptr @llvm.objc.unsafeClaimAutoreleasedReturnValue) ]
239 define ptr @test_objc_retainedObject(ptr %arg0) {
240 ; CHECK-LABEL: test_objc_retainedObject
242 ; CHECK-NEXT: %0 = call ptr @objc_retainedObject(ptr %arg0)
243 ; CHECK-NEXT: ret ptr %0
245 %0 = call ptr @llvm.objc.retainedObject(ptr %arg0)
249 define ptr @test_objc_unretainedObject(ptr %arg0) {
250 ; CHECK-LABEL: test_objc_unretainedObject
252 ; CHECK-NEXT: %0 = call ptr @objc_unretainedObject(ptr %arg0)
253 ; CHECK-NEXT: ret ptr %0
255 %0 = call ptr @llvm.objc.unretainedObject(ptr %arg0)
259 define ptr @test_objc_unretainedPointer(ptr %arg0) {
260 ; CHECK-LABEL: test_objc_unretainedPointer
262 ; CHECK-NEXT: %0 = call ptr @objc_unretainedPointer(ptr %arg0)
263 ; CHECK-NEXT: ret ptr %0
265 %0 = call ptr @llvm.objc.unretainedPointer(ptr %arg0)
269 define ptr @test_objc_retain_autorelease(ptr %arg0) {
270 ; CHECK-LABEL: test_objc_retain_autorelease
272 ; CHECK-NEXT: %0 = call ptr @objc_retain_autorelease(ptr returned %arg0)
273 ; CHECK-NEXT: ret ptr %0
275 %0 = call ptr @llvm.objc.retain.autorelease(ptr %arg0)
279 define i32 @test_objc_sync_enter(ptr %arg0) {
280 ; CHECK-LABEL: test_objc_sync_enter
282 ; CHECK-NEXT: %0 = call i32 @objc_sync_enter(ptr %arg0)
283 ; CHECK-NEXT: ret i32 %0
285 %0 = call i32 @llvm.objc.sync.enter(ptr %arg0)
289 define i32 @test_objc_sync_exit(ptr %arg0) {
290 ; CHECK-LABEL: test_objc_sync_exit
292 ; CHECK-NEXT: %0 = call i32 @objc_sync_exit(ptr %arg0)
293 ; CHECK-NEXT: ret i32 %0
295 %0 = call i32 @llvm.objc.sync.exit(ptr %arg0)
299 declare ptr @llvm.objc.autorelease(ptr)
300 declare void @llvm.objc.autoreleasePoolPop(ptr)
301 declare ptr @llvm.objc.autoreleasePoolPush()
302 declare ptr @llvm.objc.autoreleaseReturnValue(ptr)
303 declare void @llvm.objc.copyWeak(ptr, ptr)
304 declare void @llvm.objc.destroyWeak(ptr)
305 declare extern_weak ptr @llvm.objc.initWeak(ptr, ptr)
306 declare ptr @llvm.objc.loadWeak(ptr)
307 declare ptr @llvm.objc.loadWeakRetained(ptr)
308 declare void @llvm.objc.moveWeak(ptr, ptr)
309 declare void @llvm.objc.release(ptr)
310 declare ptr @llvm.objc.retain(ptr)
311 declare ptr @llvm.objc.retainAutorelease(ptr)
312 declare ptr @llvm.objc.retainAutoreleaseReturnValue(ptr)
313 declare ptr @llvm.objc.retainAutoreleasedReturnValue(ptr)
314 declare ptr @llvm.objc.retainBlock(ptr)
315 declare void @llvm.objc.storeStrong(ptr, ptr)
316 declare ptr @llvm.objc.storeWeak(ptr, ptr)
317 declare ptr @llvm.objc.unsafeClaimAutoreleasedReturnValue(ptr)
318 declare ptr @llvm.objc.retainedObject(ptr)
319 declare ptr @llvm.objc.unretainedObject(ptr)
320 declare ptr @llvm.objc.unretainedPointer(ptr)
321 declare ptr @llvm.objc.retain.autorelease(ptr)
322 declare i32 @llvm.objc.sync.enter(ptr)
323 declare i32 @llvm.objc.sync.exit(ptr)
325 attributes #0 = { nounwind }
327 ; CHECK: declare ptr @objc_autorelease(ptr)
328 ; CHECK: declare void @objc_autoreleasePoolPop(ptr)
329 ; CHECK: declare ptr @objc_autoreleasePoolPush()
330 ; CHECK: declare ptr @objc_autoreleaseReturnValue(ptr)
331 ; CHECK: declare void @objc_copyWeak(ptr, ptr)
332 ; CHECK: declare void @objc_destroyWeak(ptr)
333 ; CHECK: declare extern_weak ptr @objc_initWeak(ptr, ptr)
334 ; CHECK: declare ptr @objc_loadWeak(ptr)
335 ; CHECK: declare ptr @objc_loadWeakRetained(ptr)
336 ; CHECK: declare void @objc_moveWeak(ptr, ptr)
337 ; CHECK: declare void @objc_release(ptr) [[NLB:#[0-9]+]]
338 ; CHECK: declare ptr @objc_retain(ptr) [[NLB]]
339 ; CHECK: declare ptr @objc_retainAutorelease(ptr)
340 ; CHECK: declare ptr @objc_retainAutoreleaseReturnValue(ptr)
341 ; CHECK: declare ptr @objc_retainAutoreleasedReturnValue(ptr)
342 ; CHECK: declare ptr @objc_retainBlock(ptr)
343 ; CHECK: declare void @objc_storeStrong(ptr, ptr)
344 ; CHECK: declare ptr @objc_storeWeak(ptr, ptr)
345 ; CHECK: declare ptr @objc_unsafeClaimAutoreleasedReturnValue(ptr)
346 ; CHECK: declare ptr @objc_retainedObject(ptr)
347 ; CHECK: declare ptr @objc_unretainedObject(ptr)
348 ; CHECK: declare ptr @objc_unretainedPointer(ptr)
349 ; CHECK: declare ptr @objc_retain_autorelease(ptr)
350 ; CHECK: declare i32 @objc_sync_enter(ptr)
351 ; CHECK: declare i32 @objc_sync_exit(ptr)
353 ; CHECK: attributes #0 = { nounwind }
354 ; CHECK: attributes [[NLB]] = { nonlazybind }