Debian Codegraph @

clang/test/CodeGenHLSL/GlobalDestructors.hlsl

raw
1 // RUN: %clang_cc1 -triple spirv-unknown-vulkan1.3-compute -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s --check-prefixes=CS,NOINLINE-SPIRV,CHECK
2 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s --check-prefixes=CS,NOINLINE-DXIL,CHECK
3 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s --check-prefixes=LIB,NOINLINE-DXIL,CHECK
4 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -emit-llvm -O0 %s -o - | FileCheck %s --check-prefixes=INLINE,CHECK
5 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -emit-llvm -O0 %s -o - | FileCheck %s --check-prefixes=INLINE,CHECK
6
7 // Tests that constructors and destructors are appropriately generated for globals
8 // and that their calls are inlined when AlwaysInline is run
9 // but global variables are retained for the library profiles
10
11 // Make sure global variable for ctors/dtors exist for lib profile.
12 // LIB:@llvm.global_ctors
13 // LIB:@llvm.global_dtors
14 // Make sure global variable for ctors/dtors removed for compute profile.
15 // CS-NOT:@llvm.global_ctors
16 // CS-NOT:@llvm.global_dtors
17
18 struct 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
33 struct Pupper {
34 static int Count;
35
36 Pupper() {
37 Count += 1; // :)
38 }
39
40 ~Pupper() {
41 Count -= 1; // :(
42 }
43 } GlobalPup;
44
45 void Wag() {
46 static Tail T;
47 T.add(0);
48 }
49
50 int Pupper::Count = 0;
51
52 [numthreads(1,1,1)]
53 [shader("compute")]
54 void main(unsigned GI : SV_GroupIndex) {
55 Wag();
56 }
57
58 // CHECK: define void @main()
59 // CHECK-NEXT: entry:
60 // Verify destructor is emitted
61 // 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 void
66
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 void
73
74 // Verify inlining leaves only calls to "llvm." intrinsics
75 // INLINE-NOT: call {{[^@]*}} @{{[^l][^l][^v][^m][^\.]}}
76 // INLINE: ret void
77
78 // This is really just a sanity check I needed for myself to verify that
79 // 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 void
86
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 void
93
94 // NOINLINE: attributes [[IntAttr]] = {{.*}} alwaysinline