OpenCL spec restricts that variable in local address space can only be declared at kernel function scope. Add a Clang internal extension __cl_clang_function_scope_local_variables to lift the restriction. To expose static local allocations at kernel scope, targets can either force-inline non-kernel functions that declare local memory or pass a kernel-allocated local buffer to those functions via an implicit argument. Motivation: support local memory allocation in libclc's implementation of work-group collective built-ins, see example at: https://github.com/intel/llvm/blob/41455e305117/libclc/libspirv/lib/amdgcn-amdhsa/group/collectives_helpers.ll https://github.com/intel/llvm/blob/41455e305117/libclc/libspirv/lib/amdgcn-amdhsa/group/collectives.cl#L182 Right now this is a Clang-only OpenCL extension intended for compiling OpenCL libraries with Clang. It could be proposed as a standard OpenCL extension in the future.
20 lines
439 B
Common Lisp
20 lines
439 B
Common Lisp
// RUN: %clang_cc1 %s -triple spir64 -disable-llvm-passes -emit-llvm -o - | FileCheck %s
|
|
|
|
#pragma OPENCL EXTENSION __cl_clang_function_scope_local_variables : enable
|
|
|
|
void func(local int*);
|
|
|
|
void bar() {
|
|
// CHECK: @bar.i = internal addrspace(3) global i32 undef, align 4
|
|
local int i;
|
|
func(&i);
|
|
}
|
|
|
|
__kernel void foo(void) {
|
|
// CHECK: @foo.i = internal addrspace(3) global i32 undef, align 4
|
|
{
|
|
local int i;
|
|
func(&i);
|
|
}
|
|
}
|