Skip to content

Commit 19f3039

Browse files
authored
[SYCL] Change SPIR-V Enum token type from unsigned int to int for groups builtins (#17445)
Motivation is the same as PR #17438, i.e. unifying SPIR-V builtin mangling to enhance SYCL AOT support for backend targets that bypass SPIR-V generation.
1 parent 4337f0f commit 19f3039

File tree

18 files changed

+874
-762
lines changed

18 files changed

+874
-762
lines changed

clang/lib/Sema/SPIRVBuiltins.td

+35-19
Original file line numberDiff line numberDiff line change
@@ -911,52 +911,68 @@ foreach name = ["MemoryBarrier"] in {
911911
// 3.32.21. Group and Subgroup Instructions
912912

913913
foreach name = ["GroupAsyncCopy"] in {
914-
// TODO: Allow enum flags instead of UInt ?
915-
// TODO: We should enforce that the UInt must be a literal.
916-
def : SPVBuiltin<name, [Event, UInt, PointerType<AGenTypeN, LocalAS>, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Size, Event], Attr.Convergent>;
917-
def : SPVBuiltin<name, [Event, UInt, PointerType<AGenTypeN, GlobalAS>, PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Size, Event], Attr.Convergent>;
914+
// TODO: Allow enum flags instead of Int ?
915+
// TODO: We should enforce that the Int must be a literal.
916+
def : SPVBuiltin<name,
917+
[Event, Int, PointerType<AGenTypeN, LocalAS>,
918+
PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Size,
919+
Event],
920+
Attr.Convergent>;
921+
def : SPVBuiltin<name,
922+
[Event, Int, PointerType<AGenTypeN, GlobalAS>,
923+
PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Size,
924+
Event],
925+
Attr.Convergent>;
918926
}
919927

920928
foreach name = ["GroupWaitEvents"] in {
921-
def : SPVBuiltin<name, [Void, UInt, Int, PointerType<Event, DefaultAS>], Attr.Convergent>;
922-
def : SPVBuiltin<name, [Void, UInt, Int, PointerType<Event, PrivateAS>], Attr.Convergent>;
923-
def : SPVBuiltin<name, [Void, UInt, Int, PointerType<Event, GenericAS>], Attr.Convergent>;
929+
def : SPVBuiltin<name, [Void, Int, Int, PointerType<Event, DefaultAS>],
930+
Attr.Convergent>;
931+
def : SPVBuiltin<name, [Void, Int, Int, PointerType<Event, PrivateAS>],
932+
Attr.Convergent>;
933+
def : SPVBuiltin<name, [Void, Int, Int, PointerType<Event, GenericAS>],
934+
Attr.Convergent>;
924935
}
925936

926937
foreach name = ["GroupAll", "GroupAny"] in {
927-
def : SPVBuiltin<name, [Bool, UInt, Bool], Attr.Convergent>;
938+
def : SPVBuiltin<name, [Bool, Int, Bool], Attr.Convergent>;
928939
}
929940

930941
foreach name = ["GroupBroadcast"] in {
931942
foreach IDType = TLAllInts.List in {
932-
def : SPVBuiltin<name, [AGenTypeN, UInt, AGenTypeN, IDType], Attr.Convergent>;
933-
def : SPVBuiltin<name, [AGenTypeN, UInt, AGenTypeN, VectorType<IDType, 2>], Attr.Convergent>;
934-
def : SPVBuiltin<name, [AGenTypeN, UInt, AGenTypeN, VectorType<IDType, 3>], Attr.Convergent>;
935-
def : SPVBuiltin<name, [Bool, UInt, Bool, IDType], Attr.Convergent>;
936-
def : SPVBuiltin<name, [Bool, UInt, Bool, VectorType<IDType, 2>], Attr.Convergent>;
937-
def : SPVBuiltin<name, [Bool, UInt, Bool, VectorType<IDType, 3>], Attr.Convergent>;
943+
def : SPVBuiltin<name, [AGenTypeN, Int, AGenTypeN, IDType],
944+
Attr.Convergent>;
945+
def : SPVBuiltin<name, [AGenTypeN, Int, AGenTypeN, VectorType<IDType, 2>],
946+
Attr.Convergent>;
947+
def : SPVBuiltin<name, [AGenTypeN, Int, AGenTypeN, VectorType<IDType, 3>],
948+
Attr.Convergent>;
949+
def : SPVBuiltin<name, [Bool, Int, Bool, IDType], Attr.Convergent>;
950+
def : SPVBuiltin<name, [Bool, Int, Bool, VectorType<IDType, 2>],
951+
Attr.Convergent>;
952+
def : SPVBuiltin<name, [Bool, Int, Bool, VectorType<IDType, 3>],
953+
Attr.Convergent>;
938954
}
939955
}
940956

941957
foreach name = ["GroupIAdd", "GroupIMulKHR", "GroupBitwiseOrKHR",
942958
"GroupBitwiseXorKHR", "GroupBitwiseAndKHR"] in {
943-
def : SPVBuiltin<name, [AIGenTypeN, UInt, UInt, AIGenTypeN], Attr.Convergent>;
959+
def : SPVBuiltin<name, [AIGenTypeN, Int, Int, AIGenTypeN], Attr.Convergent>;
944960
}
945961

946962
foreach name = ["GroupFAdd", "GroupFMin", "GroupFMax",
947963
"GroupFMulKHR"] in {
948-
def : SPVBuiltin<name, [FGenTypeN, UInt, UInt, FGenTypeN], Attr.Convergent>;
964+
def : SPVBuiltin<name, [FGenTypeN, Int, Int, FGenTypeN], Attr.Convergent>;
949965
}
950966

951967
foreach name = ["GroupUMin", "GroupUMax"] in {
952-
def : SPVBuiltin<name, [AUIGenTypeN, UInt, UInt, AUIGenTypeN], Attr.Convergent>;
968+
def : SPVBuiltin<name, [AUIGenTypeN, Int, Int, AUIGenTypeN], Attr.Convergent>;
953969
}
954970

955971
foreach name = ["GroupSMin", "GroupSMax"] in {
956-
def : SPVBuiltin<name, [ASIGenTypeN, UInt, UInt, ASIGenTypeN], Attr.Convergent>;
972+
def : SPVBuiltin<name, [ASIGenTypeN, Int, Int, ASIGenTypeN], Attr.Convergent>;
957973
}
958974

959975
// TODO: These builtins need to support vectors of bool.
960976
foreach name = ["GroupLogicalAndKHR", "GroupLogicalOrKHR"] in {
961-
def : SPVBuiltin<name, [Bool, UInt, UInt, Bool], Attr.Convergent>;
977+
def : SPVBuiltin<name, [Bool, Int, Int, Bool], Attr.Convergent>;
962978
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// RUN: %clang_cc1 -triple=spir64 -cl-std=CL2.0 -fdeclare-spirv-builtins -emit-llvm %s -o - | FileCheck %s
2+
3+
void group_async_copy(short __attribute__((opencl_local)) *dst , short const __attribute__((opencl_global)) *src,
4+
event_t event) {
5+
// CHECK-LABEL: @group_async_copy(
6+
// CHECK: tail call spir_func target("spirv.Event") @_Z22__spirv_GroupAsyncCopyiPU3AS3sPU3AS1Ksmm9ocl_event(
7+
__spirv_GroupAsyncCopy(2, dst, src, 32, 16, event);
8+
}
9+
10+
void group_wait_event(event_t event) {
11+
// CHECK-LABEL: @group_wait_event(
12+
// CHECK: call spir_func void @_Z23__spirv_GroupWaitEventsiiP9ocl_event(
13+
__spirv_GroupWaitEvents(1, 0, &event);
14+
}
15+
16+
bool group_all(bool predicate) {
17+
// CHECK-LABEL: @group_all(
18+
// CHECK: call spir_func zeroext i1 @_Z16__spirv_GroupAllib(
19+
return __spirv_GroupAll(2, predicate);
20+
}
21+
22+
bool group_any(bool predicate) {
23+
// CHECK-LABEL: @group_any(
24+
// CHECK: call spir_func zeroext i1 @_Z16__spirv_GroupAnyib(
25+
return __spirv_GroupAny(2, predicate);
26+
}
27+
28+
char group_broad_cast(char a) {
29+
// CHECK-LABEL: @group_broad_cast(
30+
// CHECK: call spir_func i32 @_Z22__spirv_GroupBroadcastiij(
31+
return __spirv_GroupBroadcast(2, a, 0u);
32+
}
33+
34+
int group_iadd(int a) {
35+
// CHECK-LABEL: @group_iadd(
36+
// CHECK: call spir_func i32 @_Z17__spirv_GroupIAddiii(
37+
return __spirv_GroupIAdd(2, 2, a);
38+
}
39+
40+
int group_imul_khr(short a) {
41+
// CHECK-LABEL: @group_imul_khr(
42+
// CHECK: call spir_func signext i16 @_Z20__spirv_GroupIMulKHRiis(
43+
return __spirv_GroupIMulKHR(2, 0, a);
44+
}
45+
46+
bool group_bitwise_or_khr(long a) {
47+
// CHECK-LABEL: @group_bitwise_or_khr(
48+
// CHECK: call spir_func i64 @_Z25__spirv_GroupBitwiseOrKHRiil(
49+
return __spirv_GroupBitwiseOrKHR(2, 0, a);
50+
}
51+
52+
float group_fadd(float a) {
53+
// CHECK-LABEL: @group_fadd(
54+
// CHECK: call spir_func float @_Z17__spirv_GroupFAddiif(
55+
return __spirv_GroupFAdd(2, 1, a);
56+
}
57+
58+
float group_fmin(float a) {
59+
// CHECK-LABEL: @group_fmin(
60+
// CHECK: call spir_func float @_Z17__spirv_GroupFMiniif(
61+
return __spirv_GroupFMin(2, 0, a);
62+
}
63+
64+
float group_fmax(float a) {
65+
// CHECK-LABEL: @group_fmax(
66+
// CHECK: call spir_func float @_Z17__spirv_GroupFMaxiif(
67+
return __spirv_GroupFMax(2, 2, a);
68+
}
69+
70+
float group_ful_khr(float a) {
71+
// CHECK-LABEL: @group_ful_khr(
72+
// CHECK: call spir_func float @_Z20__spirv_GroupFMulKHRiif(
73+
return __spirv_GroupFMulKHR(2, 2, a);
74+
}
75+
76+
unsigned char group_umin(unsigned char a ) {
77+
// CHECK-LABEL: @group_umin(
78+
// CHECK: call spir_func zeroext i8 @_Z17__spirv_GroupUMiniih(
79+
return __spirv_GroupUMin(2, 0, a);
80+
}
81+
82+
unsigned long group_umax(unsigned long a) {
83+
// CHECK-LABEL: @group_umax(
84+
// CHECK: call spir_func i64 @_Z17__spirv_GroupUMaxiim(
85+
return __spirv_GroupUMax(2, 0, a);
86+
}
87+
88+
char group_smin(char a) {
89+
// CHECK-LABEL: @group_smin(
90+
// CHECK: call spir_func i32 @_Z17__spirv_GroupSMiniii(
91+
return __spirv_GroupSMin(2, 0, a);
92+
}
93+
94+
short group_smax(short a) {
95+
// CHECK-LABEL: @group_smax(
96+
// CHECK: call spir_func signext i16 @_Z17__spirv_GroupSMaxiis(
97+
return __spirv_GroupSMax(2, 0, a);
98+
}
99+
100+
bool group_logical_and_khr(bool a) {
101+
// CHECK-LABEL: @group_logical_and_khr(
102+
// CHECK: call spir_func zeroext i1 @_Z26__spirv_GroupLogicalAndKHRiib(
103+
return __spirv_GroupLogicalAndKHR(2, 0, a);
104+
}
105+
106+
bool group_logical_or_khr(bool a) {
107+
// CHECK-LABEL: @group_logical_or_khr(
108+
// CHECK: call spir_func zeroext i1 @_Z25__spirv_GroupLogicalOrKHRiib(
109+
return __spirv_GroupLogicalOrKHR(2, 0, a);
110+
}

0 commit comments

Comments
 (0)