|
| 1 | +// RUN: %clang_cc1 -fsycl -fsycl-is-device -triple spir64-unknown-unknown-sycldevice -disable-llvm-passes %s -emit-llvm -o - | FileCheck %s |
| 2 | +// Test that static initializers do not force the emission of globals on sycl device |
| 3 | + |
| 4 | +// CHECK: %struct._ZTS16RegisterBaseInit.RegisterBaseInit = type { i8 } |
| 5 | +// CHECK-NOT: $_ZN8BaseInitI12TestBaseTypeE15s_regbase_ncsdmE = comdat any |
| 6 | +// CHECK: $_ZN8BaseInitI12TestBaseTypeE3varE = comdat any |
| 7 | +// CHECK: @_ZN8BaseInitI12TestBaseTypeE9s_regbaseE = {{.*}} global %struct._ZTS16RegisterBaseInit.RegisterBaseInit |
| 8 | +// CHECK-NOT: @_ZN8BaseInitI12TestBaseTypeE15s_regbase_ncsdmE = weak_odr addrspace(1) global %struct._ZTS16RegisterBaseInit.RegisterBaseInit zeroinitializer, comdat, align 1 |
| 9 | +// CHECK: @_ZN8BaseInitI12TestBaseTypeE3varE = weak_odr addrspace(1) constant i32 9, comdat, align 4 |
| 10 | +// CHECK: @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @__cxx_global_var_init, i8* addrspacecast (i8 addrspace(1)* getelementptr inbounds (%struct._ZTS16RegisterBaseInit.RegisterBaseInit, %struct._ZTS16RegisterBaseInit.RegisterBaseInit addrspace(1)* @_ZN8BaseInitI12TestBaseTypeE9s_regbaseE, i32 0, i32 0) to i8*) }] |
| 11 | +// CHECK-NOT: @_ZGVN8BaseInitI12TestBaseTypeE15s_regbase_ncsdmE = weak_odr global i64 0, comdat($_ZN8BaseInitI12TestBaseTypeE9s_regbaseE), align 8 |
| 12 | +// CHECK: define spir_kernel void @_ZTSZ4mainE11fake_kernel() |
| 13 | +// CHECK: call spir_func void @"_ZZ4mainENK3$_0clE16RegisterBaseInit |
| 14 | +// CHECK: declare spir_func void @_ZN16RegisterBaseInit3fooEv |
| 15 | + |
| 16 | +struct TestBaseType {}; |
| 17 | +struct RegisterBaseInit { |
| 18 | + __attribute__((sycl_device)) void foo(); |
| 19 | + RegisterBaseInit(); |
| 20 | +}; |
| 21 | +template <class T> |
| 22 | +struct BaseInit { |
| 23 | + static const RegisterBaseInit s_regbase; |
| 24 | + static RegisterBaseInit s_regbase_ncsdm; |
| 25 | + static const int var; |
| 26 | +}; |
| 27 | +template <class T> |
| 28 | +const RegisterBaseInit BaseInit<T>::s_regbase; |
| 29 | +template <class T> |
| 30 | +RegisterBaseInit BaseInit<T>::s_regbase_ncsdm; |
| 31 | +template <class T> |
| 32 | +const int BaseInit<T>::var = 9; |
| 33 | +template struct BaseInit<TestBaseType>; |
| 34 | +template <typename name, typename Func> |
| 35 | +__attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) { |
| 36 | + kernelFunc(BaseInit<TestBaseType>::s_regbase); |
| 37 | +} |
| 38 | +int main() { |
| 39 | + kernel_single_task<class fake_kernel>([=](RegisterBaseInit s) { |
| 40 | + s.foo(); |
| 41 | + }); |
| 42 | + return 0; |
| 43 | +} |
0 commit comments