Skip to content

Commit 44e32fb

Browse files
authored
[Clang][OpenCL] Fix wait_for_event argument address space with -fdeclare-opencl-builtins (#134598)
The pointer argument for `wait_for_event(int, event_t*)` should take the default address space: generic if available, otherwise private. Before this patch it would always be generic with `-fdeclare-opencl-builtins`. This was inconsistent with the behavior when opencl-c.h is included.
1 parent 4a425a4 commit 44e32fb

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

clang/lib/Sema/OpenCLBuiltins.td

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -958,13 +958,25 @@ foreach name = ["async_work_group_strided_copy"] in {
958958
def : Builtin<name, [Event, PointerType<AGenTypeN, LocalAS>, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Size, Event]>;
959959
def : Builtin<name, [Event, PointerType<AGenTypeN, GlobalAS>, PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Size, Event]>;
960960
}
961-
foreach name = ["wait_group_events"] in {
962-
def : Builtin<name, [Void, Int, PointerType<Event, GenericAS>]>;
963-
}
964961
foreach name = ["prefetch"] in {
965962
def : Builtin<name, [Void, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size]>;
966963
}
967964

965+
// The wait_group_events is declared with an argument of type event_t*.
966+
// The address-space of the pointer parameter is different if the generic address space is available.
967+
multiclass BuiltinWithDefaultPointerArg<AddressSpace AS> {
968+
foreach name = ["wait_group_events"] in {
969+
def : Builtin<name, [Void, Int, PointerType<Event, AS>]>;
970+
}
971+
}
972+
973+
let Extension = FuncExtOpenCLCNamedAddressSpaceBuiltins in {
974+
defm : BuiltinWithDefaultPointerArg<PrivateAS>;
975+
}
976+
let Extension = FuncExtOpenCLCGenericAddressSpace in {
977+
defm : BuiltinWithDefaultPointerArg<GenericAS>;
978+
}
979+
968980
//--------------------------------------------------------------------
969981
// OpenCL v2.0 s6.13.11 - Atomics Functions.
970982
// Functions that use memory_order and cl_mem_fence_flags enums are not

clang/test/CodeGenOpenCL/fdeclare-opencl-builtins.cl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ void test_generic_optionality(float a, float *b) {
4848
float res = fract(a, b);
4949
}
5050

51+
// Test that the correct builtin is called depending on the generic address
52+
// space feature availability. If not available, the __private version is called
53+
// CHECK-LABEL: @test_wait_group_events
54+
// CHECK-GAS: call spir_func void @_Z17wait_group_eventsiPU3AS49ocl_event
55+
// CHECK-NOGAS: call spir_func void @_Z17wait_group_eventsiP9ocl_event
56+
void test_wait_group_events(int i, event_t *e) {
57+
wait_group_events(i, e);
58+
}
59+
5160
// CHECK: attributes [[ATTR_CONST]] =
5261
// CHECK-SAME: memory(none)
5362
// CHECK: attributes [[ATTR_PURE]] =

0 commit comments

Comments
 (0)