Skip to content

Commit f7336b9

Browse files
[SPIR-V] Add __spirv_ wrapper to the OpAtomicExchange instruction (#95961)
This PR adds __spirv_ wrapper to the OpAtomicExchange instruction. A new test case is added for the change introduced.
1 parent 0daeed6 commit f7336b9

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

llvm/lib/Target/SPIRV/SPIRVBuiltins.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ defm : DemangledNativeBuiltin<"__spirv_AtomicAnd", OpenCL_std, Atomic, 4, 4, OpA
533533
defm : DemangledNativeBuiltin<"atomic_exchange", OpenCL_std, Atomic, 2, 4, OpAtomicExchange>;
534534
defm : DemangledNativeBuiltin<"atomic_exchange_explicit", OpenCL_std, Atomic, 2, 4, OpAtomicExchange>;
535535
defm : DemangledNativeBuiltin<"AtomicEx__spirv_change", OpenCL_std, Atomic, 2, 4, OpAtomicExchange>;
536+
defm : DemangledNativeBuiltin<"__spirv_AtomicExchange", OpenCL_std, Atomic, 4, 4, OpAtomicExchange>;
536537
defm : DemangledNativeBuiltin<"atomic_work_item_fence", OpenCL_std, Atomic, 1, 3, OpMemoryBarrier>;
537538
defm : DemangledNativeBuiltin<"__spirv_MemoryBarrier", OpenCL_std, Atomic, 2, 2, OpMemoryBarrier>;
538539
defm : DemangledNativeBuiltin<"atomic_fetch_add", OpenCL_std, Atomic, 2, 4, OpAtomicIAdd>;
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
2+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
3+
4+
; CHECK-DAG: %[[#Long:]] = OpTypeInt 64 0
5+
; CHECK-COUNT-9: %[[#]] = OpAtomicExchange %[[#Long]] %[[#]] %[[#]] %[[#]] %[[#]]
6+
7+
%Type1 = type { i64 }
8+
%Type2 = type { ptr addrspace(4) }
9+
10+
define linkonce_odr dso_local spir_func void @f1() {
11+
entry:
12+
%a = alloca %Type1, align 8
13+
%a.ascast = addrspacecast ptr %a to ptr addrspace(4)
14+
%p = ptrtoint ptr addrspace(4) %a.ascast to i64
15+
%res = call spir_func i64 @_Z22__spirv_AtomicExchangePyN5__spv5Scope4FlagENS0_19MemorySemanticsMask4FlagEy(ptr addrspace(4) %a.ascast, i32 0, i32 912, i64 3)
16+
ret void
17+
}
18+
19+
define linkonce_odr dso_local spir_func void @f2() {
20+
entry:
21+
%a = alloca %Type1, align 8
22+
%a.ascast = addrspacecast ptr %a to ptr addrspace(4)
23+
%p = ptrtoint ptr addrspace(4) %a.ascast to i64
24+
%res = call spir_func i64 @_Z22__spirv_AtomicExchangePxN5__spv5Scope4FlagENS0_19MemorySemanticsMask4FlagEx(ptr addrspace(4) %a.ascast, i32 0, i32 912, i64 3)
25+
ret void
26+
}
27+
28+
define linkonce_odr dso_local spir_func void @f3() {
29+
entry:
30+
%a = alloca %Type1, align 8
31+
%a.ascast = addrspacecast ptr %a to ptr addrspace(4)
32+
%p = ptrtoint ptr addrspace(4) %a.ascast to i64
33+
%res = call spir_func i64 @_Z22__spirv_AtomicExchangePmN5__spv5Scope4FlagENS0_19MemorySemanticsMask4FlagEm(ptr addrspace(4) %a.ascast, i32 0, i32 912, i64 3)
34+
ret void
35+
}
36+
37+
define linkonce_odr dso_local spir_func void @f4() {
38+
entry:
39+
%a = alloca %Type1, align 8
40+
%a.ascast = addrspacecast ptr %a to ptr addrspace(4)
41+
%p = ptrtoint ptr addrspace(4) %a.ascast to i64
42+
%res = call spir_func i64 @_Z22__spirv_AtomicExchangePlN5__spv5Scope4FlagENS0_19MemorySemanticsMask4FlagEl(ptr addrspace(4) %a.ascast, i32 0, i32 912, i64 3)
43+
ret void
44+
}
45+
46+
47+
define linkonce_odr dso_local spir_func void @f5() {
48+
entry:
49+
%a = alloca %Type2, align 8
50+
%a.ascast = addrspacecast ptr %a to ptr addrspace(4)
51+
%p = ptrtoint ptr addrspace(4) %a.ascast to i64
52+
%res = call spir_func i64 @_Z22__spirv_AtomicExchangePmN5__spv5Scope4FlagENS0_19MemorySemanticsMask4FlagEm(ptr addrspace(4) %a.ascast, i32 0, i32 912, i64 %p)
53+
ret void
54+
}
55+
56+
define linkonce_odr dso_local spir_func void @f6() {
57+
entry:
58+
%a = alloca %Type2, align 8
59+
%a.ascast = addrspacecast ptr %a to ptr addrspace(4)
60+
%p = ptrtoint ptr addrspace(4) %a.ascast to i64
61+
%res = call spir_func i64 @_Z22__spirv_AtomicExchangePmN5__spv5Scope4FlagENS0_19MemorySemanticsMask4FlagEm(ptr addrspace(4) %a.ascast, i32 0, i32 912, i64 %p)
62+
ret void
63+
}
64+
65+
define linkonce_odr dso_local spir_func void @f7() {
66+
entry:
67+
%a = alloca %Type2, align 8
68+
%a.ascast = addrspacecast ptr %a to ptr addrspace(4)
69+
%p = ptrtoint ptr addrspace(4) %a.ascast to i64
70+
%res = call spir_func i64 @_Z22__spirv_AtomicExchangePmN5__spv5Scope4FlagENS0_19MemorySemanticsMask4FlagEm(ptr addrspace(4) %a.ascast, i32 0, i32 912, i64 %p)
71+
ret void
72+
}
73+
74+
define linkonce_odr dso_local spir_func void @f8() {
75+
entry:
76+
%a = alloca %Type2, align 8
77+
%a.ascast = addrspacecast ptr %a to ptr addrspace(4)
78+
%p = ptrtoint ptr addrspace(4) %a.ascast to i64
79+
%res = call spir_func i64 @_Z22__spirv_AtomicExchangePmN5__spv5Scope4FlagENS0_19MemorySemanticsMask4FlagEm(ptr addrspace(4) %a.ascast, i32 0, i32 912, i64 %p)
80+
ret void
81+
}
82+
83+
; Function Attrs: convergent mustprogress norecurse nounwind
84+
define linkonce_odr dso_local spir_func void @f9() {
85+
entry:
86+
%a = alloca %Type2, align 8
87+
%a.ascast = addrspacecast ptr %a to ptr addrspace(4)
88+
%p = ptrtoint ptr addrspace(4) %a.ascast to i64
89+
%res = call spir_func i64 @_Z22__spirv_AtomicExchangePmN5__spv5Scope4FlagENS0_19MemorySemanticsMask4FlagEm(ptr addrspace(4) %a.ascast, i32 0, i32 912, i64 %p)
90+
ret void
91+
}
92+
93+
declare dso_local spir_func i64 @_Z22__spirv_AtomicExchangePyN5__spv5Scope4FlagENS0_19MemorySemanticsMask4FlagEy(ptr addrspace(4), i32, i32, i64)
94+
declare dso_local spir_func i64 @_Z22__spirv_AtomicExchangePxN5__spv5Scope4FlagENS0_19MemorySemanticsMask4FlagEx(ptr addrspace(4), i32, i32, i64)
95+
declare dso_local spir_func i64 @_Z22__spirv_AtomicExchangePmN5__spv5Scope4FlagENS0_19MemorySemanticsMask4FlagEm(ptr addrspace(4), i32, i32, i64)
96+
declare dso_local spir_func i64 @_Z22__spirv_AtomicExchangePlN5__spv5Scope4FlagENS0_19MemorySemanticsMask4FlagEl(ptr addrspace(4), i32, i32, i64)

0 commit comments

Comments
 (0)