Skip to content

[Clang][OpenCL] Fix wait_for_event argument address space with -fdeclare-opencl-builtins #134598

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

Merged
merged 1 commit into from
Apr 7, 2025
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
18 changes: 15 additions & 3 deletions clang/lib/Sema/OpenCLBuiltins.td
Original file line number Diff line number Diff line change
Expand Up @@ -958,13 +958,25 @@ foreach name = ["async_work_group_strided_copy"] in {
def : Builtin<name, [Event, PointerType<AGenTypeN, LocalAS>, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Size, Event]>;
def : Builtin<name, [Event, PointerType<AGenTypeN, GlobalAS>, PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Size, Event]>;
}
foreach name = ["wait_group_events"] in {
def : Builtin<name, [Void, Int, PointerType<Event, GenericAS>]>;
}
foreach name = ["prefetch"] in {
def : Builtin<name, [Void, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size]>;
}

// The wait_group_events is declared with an argument of type event_t*.
// The address-space of the pointer parameter is different if the generic address space is available.
multiclass BuiltinWithDefaultPointerArg<AddressSpace AS> {
foreach name = ["wait_group_events"] in {
def : Builtin<name, [Void, Int, PointerType<Event, AS>]>;
}
}

let Extension = FuncExtOpenCLCNamedAddressSpaceBuiltins in {
defm : BuiltinWithDefaultPointerArg<PrivateAS>;
}
let Extension = FuncExtOpenCLCGenericAddressSpace in {
defm : BuiltinWithDefaultPointerArg<GenericAS>;
}

//--------------------------------------------------------------------
// OpenCL v2.0 s6.13.11 - Atomics Functions.
// Functions that use memory_order and cl_mem_fence_flags enums are not
Expand Down
9 changes: 9 additions & 0 deletions clang/test/CodeGenOpenCL/fdeclare-opencl-builtins.cl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ void test_generic_optionality(float a, float *b) {
float res = fract(a, b);
}

// Test that the correct builtin is called depending on the generic address
// space feature availability. If not available, the __private version is called
// CHECK-LABEL: @test_wait_group_events
// CHECK-GAS: call spir_func void @_Z17wait_group_eventsiPU3AS49ocl_event
// CHECK-NOGAS: call spir_func void @_Z17wait_group_eventsiP9ocl_event
void test_wait_group_events(int i, event_t *e) {
wait_group_events(i, e);
}

// CHECK: attributes [[ATTR_CONST]] =
// CHECK-SAME: memory(none)
// CHECK: attributes [[ATTR_PURE]] =
Expand Down