Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SYCL] Change SPIR-V Enum token type from unsigned int to int for groups builtins #17445

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 35 additions & 19 deletions clang/lib/Sema/SPIRVBuiltins.td
Original file line number Diff line number Diff line change
Expand Up @@ -911,52 +911,68 @@ foreach name = ["MemoryBarrier"] in {
// 3.32.21. Group and Subgroup Instructions

foreach name = ["GroupAsyncCopy"] in {
// TODO: Allow enum flags instead of UInt ?
// TODO: We should enforce that the UInt must be a literal.
def : SPVBuiltin<name, [Event, UInt, PointerType<AGenTypeN, LocalAS>, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Size, Event], Attr.Convergent>;
def : SPVBuiltin<name, [Event, UInt, PointerType<AGenTypeN, GlobalAS>, PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Size, Event], Attr.Convergent>;
// TODO: Allow enum flags instead of Int ?
// TODO: We should enforce that the Int must be a literal.
def : SPVBuiltin<name,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as in #17438 (comment) , should we have a test checking that clang emits correct signature and mangling for the builtin in the IR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @Fznamznon
done in bc42ed1

[Event, Int, PointerType<AGenTypeN, LocalAS>,
PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Size,
Event],
Attr.Convergent>;
def : SPVBuiltin<name,
[Event, Int, PointerType<AGenTypeN, GlobalAS>,
PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Size,
Event],
Attr.Convergent>;
}

foreach name = ["GroupWaitEvents"] in {
def : SPVBuiltin<name, [Void, UInt, Int, PointerType<Event, DefaultAS>], Attr.Convergent>;
def : SPVBuiltin<name, [Void, UInt, Int, PointerType<Event, PrivateAS>], Attr.Convergent>;
def : SPVBuiltin<name, [Void, UInt, Int, PointerType<Event, GenericAS>], Attr.Convergent>;
def : SPVBuiltin<name, [Void, Int, Int, PointerType<Event, DefaultAS>],
Attr.Convergent>;
def : SPVBuiltin<name, [Void, Int, Int, PointerType<Event, PrivateAS>],
Attr.Convergent>;
def : SPVBuiltin<name, [Void, Int, Int, PointerType<Event, GenericAS>],
Attr.Convergent>;
}

foreach name = ["GroupAll", "GroupAny"] in {
def : SPVBuiltin<name, [Bool, UInt, Bool], Attr.Convergent>;
def : SPVBuiltin<name, [Bool, Int, Bool], Attr.Convergent>;
}

foreach name = ["GroupBroadcast"] in {
foreach IDType = TLAllInts.List in {
def : SPVBuiltin<name, [AGenTypeN, UInt, AGenTypeN, IDType], Attr.Convergent>;
def : SPVBuiltin<name, [AGenTypeN, UInt, AGenTypeN, VectorType<IDType, 2>], Attr.Convergent>;
def : SPVBuiltin<name, [AGenTypeN, UInt, AGenTypeN, VectorType<IDType, 3>], Attr.Convergent>;
def : SPVBuiltin<name, [Bool, UInt, Bool, IDType], Attr.Convergent>;
def : SPVBuiltin<name, [Bool, UInt, Bool, VectorType<IDType, 2>], Attr.Convergent>;
def : SPVBuiltin<name, [Bool, UInt, Bool, VectorType<IDType, 3>], Attr.Convergent>;
def : SPVBuiltin<name, [AGenTypeN, Int, AGenTypeN, IDType],
Attr.Convergent>;
def : SPVBuiltin<name, [AGenTypeN, Int, AGenTypeN, VectorType<IDType, 2>],
Attr.Convergent>;
def : SPVBuiltin<name, [AGenTypeN, Int, AGenTypeN, VectorType<IDType, 3>],
Attr.Convergent>;
def : SPVBuiltin<name, [Bool, Int, Bool, IDType], Attr.Convergent>;
def : SPVBuiltin<name, [Bool, Int, Bool, VectorType<IDType, 2>],
Attr.Convergent>;
def : SPVBuiltin<name, [Bool, Int, Bool, VectorType<IDType, 3>],
Attr.Convergent>;
}
}

foreach name = ["GroupIAdd", "GroupIMulKHR", "GroupBitwiseOrKHR",
"GroupBitwiseXorKHR", "GroupBitwiseAndKHR"] in {
def : SPVBuiltin<name, [AIGenTypeN, UInt, UInt, AIGenTypeN], Attr.Convergent>;
def : SPVBuiltin<name, [AIGenTypeN, Int, Int, AIGenTypeN], Attr.Convergent>;
}

foreach name = ["GroupFAdd", "GroupFMin", "GroupFMax",
"GroupFMulKHR"] in {
def : SPVBuiltin<name, [FGenTypeN, UInt, UInt, FGenTypeN], Attr.Convergent>;
def : SPVBuiltin<name, [FGenTypeN, Int, Int, FGenTypeN], Attr.Convergent>;
}

foreach name = ["GroupUMin", "GroupUMax"] in {
def : SPVBuiltin<name, [AUIGenTypeN, UInt, UInt, AUIGenTypeN], Attr.Convergent>;
def : SPVBuiltin<name, [AUIGenTypeN, Int, Int, AUIGenTypeN], Attr.Convergent>;
}

foreach name = ["GroupSMin", "GroupSMax"] in {
def : SPVBuiltin<name, [ASIGenTypeN, UInt, UInt, ASIGenTypeN], Attr.Convergent>;
def : SPVBuiltin<name, [ASIGenTypeN, Int, Int, ASIGenTypeN], Attr.Convergent>;
}

// TODO: These builtins need to support vectors of bool.
foreach name = ["GroupLogicalAndKHR", "GroupLogicalOrKHR"] in {
def : SPVBuiltin<name, [Bool, UInt, UInt, Bool], Attr.Convergent>;
def : SPVBuiltin<name, [Bool, Int, Int, Bool], Attr.Convergent>;
}
110 changes: 110 additions & 0 deletions clang/test/CodeGenSPIRV/spirv-builtin-lookup-group.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// RUN: %clang_cc1 -triple=spir64 -cl-std=CL2.0 -fdeclare-spirv-builtins -emit-llvm %s -o - | FileCheck %s

void group_async_copy(short __attribute__((opencl_local)) *dst , short const __attribute__((opencl_global)) *src,
event_t event) {
// CHECK-LABEL: @group_async_copy(
// CHECK: tail call spir_func target("spirv.Event") @_Z22__spirv_GroupAsyncCopyiPU3AS3sPU3AS1Ksmm9ocl_event(
__spirv_GroupAsyncCopy(2, dst, src, 32, 16, event);
}

void group_wait_event(event_t event) {
// CHECK-LABEL: @group_wait_event(
// CHECK: call spir_func void @_Z23__spirv_GroupWaitEventsiiP9ocl_event(
__spirv_GroupWaitEvents(1, 0, &event);
}

bool group_all(bool predicate) {
// CHECK-LABEL: @group_all(
// CHECK: call spir_func zeroext i1 @_Z16__spirv_GroupAllib(
return __spirv_GroupAll(2, predicate);
}

bool group_any(bool predicate) {
// CHECK-LABEL: @group_any(
// CHECK: call spir_func zeroext i1 @_Z16__spirv_GroupAnyib(
return __spirv_GroupAny(2, predicate);
}

char group_broad_cast(char a) {
// CHECK-LABEL: @group_broad_cast(
// CHECK: call spir_func i32 @_Z22__spirv_GroupBroadcastiij(
return __spirv_GroupBroadcast(2, a, 0u);
}

int group_iadd(int a) {
// CHECK-LABEL: @group_iadd(
// CHECK: call spir_func i32 @_Z17__spirv_GroupIAddiii(
return __spirv_GroupIAdd(2, 2, a);
}

int group_imul_khr(short a) {
// CHECK-LABEL: @group_imul_khr(
// CHECK: call spir_func signext i16 @_Z20__spirv_GroupIMulKHRiis(
return __spirv_GroupIMulKHR(2, 0, a);
}

bool group_bitwise_or_khr(long a) {
// CHECK-LABEL: @group_bitwise_or_khr(
// CHECK: call spir_func i64 @_Z25__spirv_GroupBitwiseOrKHRiil(
return __spirv_GroupBitwiseOrKHR(2, 0, a);
}

float group_fadd(float a) {
// CHECK-LABEL: @group_fadd(
// CHECK: call spir_func float @_Z17__spirv_GroupFAddiif(
return __spirv_GroupFAdd(2, 1, a);
}

float group_fmin(float a) {
// CHECK-LABEL: @group_fmin(
// CHECK: call spir_func float @_Z17__spirv_GroupFMiniif(
return __spirv_GroupFMin(2, 0, a);
}

float group_fmax(float a) {
// CHECK-LABEL: @group_fmax(
// CHECK: call spir_func float @_Z17__spirv_GroupFMaxiif(
return __spirv_GroupFMax(2, 2, a);
}

float group_ful_khr(float a) {
// CHECK-LABEL: @group_ful_khr(
// CHECK: call spir_func float @_Z20__spirv_GroupFMulKHRiif(
return __spirv_GroupFMulKHR(2, 2, a);
}

unsigned char group_umin(unsigned char a ) {
// CHECK-LABEL: @group_umin(
// CHECK: call spir_func zeroext i8 @_Z17__spirv_GroupUMiniih(
return __spirv_GroupUMin(2, 0, a);
}

unsigned long group_umax(unsigned long a) {
// CHECK-LABEL: @group_umax(
// CHECK: call spir_func i64 @_Z17__spirv_GroupUMaxiim(
return __spirv_GroupUMax(2, 0, a);
}

char group_smin(char a) {
// CHECK-LABEL: @group_smin(
// CHECK: call spir_func i32 @_Z17__spirv_GroupSMiniii(
return __spirv_GroupSMin(2, 0, a);
}

short group_smax(short a) {
// CHECK-LABEL: @group_smax(
// CHECK: call spir_func signext i16 @_Z17__spirv_GroupSMaxiis(
return __spirv_GroupSMax(2, 0, a);
}

bool group_logical_and_khr(bool a) {
// CHECK-LABEL: @group_logical_and_khr(
// CHECK: call spir_func zeroext i1 @_Z26__spirv_GroupLogicalAndKHRiib(
return __spirv_GroupLogicalAndKHR(2, 0, a);
}

bool group_logical_or_khr(bool a) {
// CHECK-LABEL: @group_logical_or_khr(
// CHECK: call spir_func zeroext i1 @_Z25__spirv_GroupLogicalOrKHRiib(
return __spirv_GroupLogicalOrKHR(2, 0, a);
}
Loading