95 lines · plain
1// RUN: %clang_cc1 -triple spirv-unknown-vulkan1.3-compute -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s --check-prefixes=CS,NOINLINE-SPIRV,CHECK2// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s --check-prefixes=CS,NOINLINE-DXIL,CHECK3// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s --check-prefixes=LIB,NOINLINE-DXIL,CHECK4// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -emit-llvm -O0 %s -o - | FileCheck %s --check-prefixes=INLINE,CHECK5// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -emit-llvm -O0 %s -o - | FileCheck %s --check-prefixes=INLINE,CHECK6 7// Tests that constructors and destructors are appropriately generated for globals8// and that their calls are inlined when AlwaysInline is run9// but global variables are retained for the library profiles10 11// Make sure global variable for ctors/dtors exist for lib profile.12// LIB:@llvm.global_ctors13// LIB:@llvm.global_dtors14// Make sure global variable for ctors/dtors removed for compute profile.15// CS-NOT:@llvm.global_ctors16// CS-NOT:@llvm.global_dtors17 18struct Tail {19 Tail() {20 add(1);21 }22 23 ~Tail() {24 add(-1);25 }26 27 void add(int V) {28 static int Count = 0;29 Count += V;30 }31};32 33struct Pupper {34 static int Count;35 36 Pupper() {37 Count += 1; // :)38 }39 40 ~Pupper() {41 Count -= 1; // :(42 }43} GlobalPup;44 45void Wag() {46 static Tail T;47 T.add(0);48}49 50int Pupper::Count = 0;51 52[numthreads(1,1,1)]53[shader("compute")]54void main(unsigned GI : SV_GroupIndex) {55 Wag();56}57 58// CHECK: define void @main()59// CHECK-NEXT: entry:60// Verify destructor is emitted61// NOINLINE-DXIL-NEXT: call void @_GLOBAL__sub_I_GlobalDestructors.hlsl()62// NOINLINE-DXIL-NEXT: %0 = call i32 @llvm.dx.flattened.thread.id.in.group()63// NOINLINE-DXIL-NEXT: call void @_Z4mainj(i32 %0)64// NOINLINE-DXIL-NEXT: call void @_GLOBAL__D_a()65// NOINLINE-DXIL-NEXT: ret void66 67// NOINLINE-SPIRV-NEXT: %0 = call token @llvm.experimental.convergence.entry()68// NOINLINE-SPIRV-NEXT: call spir_func void @_GLOBAL__sub_I_GlobalDestructors.hlsl() [ "convergencectrl"(token %0) ]69// NOINLINE-SPIRV-NEXT: %1 = call i32 @llvm.spv.flattened.thread.id.in.group()70// NOINLINE-SPIRV-NEXT: call spir_func void @_Z4mainj(i32 %1) [ "convergencectrl"(token %0) ]71// NOINLINE-SPIRV-NEXT: call spir_func void @_GLOBAL__D_a() [ "convergencectrl"(token %0) ]72// NOINLINE-SPIRV-NEXT: ret void73 74// Verify inlining leaves only calls to "llvm." intrinsics75// INLINE-NOT: call {{[^@]*}} @{{[^l][^l][^v][^m][^\.]}}76// INLINE: ret void77 78// This is really just a sanity check I needed for myself to verify that79// function scope static variables also get destroyed properly.80 81// NOINLINE-DXIL: define internal void @_GLOBAL__D_a() [[IntAttr:\#[0-9]+]]82// NOINLINE-DXIL-NEXT: entry:83// NOINLINE-DXIL-NEXT: call void @_ZN4TailD1Ev(ptr @_ZZ3WagvE1T)84// NOINLINE-DXIL-NEXT: call void @_ZN6PupperD1Ev(ptr @GlobalPup)85// NOINLINE-DXIL-NEXT: ret void86 87// NOINLINE-SPIRV: define internal spir_func void @_GLOBAL__D_a() [[IntAttr:\#[0-9]+]]88// NOINLINE-SPIRV-NEXT: entry:89// NOINLINE-SPIRV-NEXT: %0 = call token @llvm.experimental.convergence.entry()90// NOINLINE-SPIRV-NEXT: call spir_func void @_ZN4TailD1Ev(ptr addrspacecast (ptr addrspace(10) @_ZZ3WagvE1T to ptr)) [ "convergencectrl"(token %0) ]91// NOINLINE-SPIRV-NEXT: call spir_func void @_ZN6PupperD1Ev(ptr @GlobalPup) [ "convergencectrl"(token %0) ]92// NOINLINE-SPIRV-NEXT: ret void93 94// NOINLINE: attributes [[IntAttr]] = {{.*}} alwaysinline95