Debian Codegraph @

clang/test/CodeGenHLSL/GlobalConstructorFunction.hlsl

raw
1 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s --check-prefixes=CHECK,NOINLINE
2 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -emit-llvm -O0 %s -o - | FileCheck %s --check-prefixes=CHECK,INLINE
3
4 int i;
5
6 __attribute__((constructor)) void call_me_first(void) {
7 i = 12;
8 }
9
10 __attribute__((constructor)) void then_call_me(void) {
11 i = 13;
12 }
13
14 __attribute__((destructor)) void call_me_last(void) {
15 i = 0;
16 }
17
18 [numthreads(1,1,1)]
19 void main(unsigned GI : SV_GroupIndex) {}
20
21 // Make sure global variable for ctors/dtors removed.
22 // CHECK-NOT:@llvm.global_ctors
23 // CHECK-NOT:@llvm.global_dtors
24
25 // CHECK: define void @main()
26 // CHECK-NEXT: entry:
27 // Verify function constructors are emitted
28 // NOINLINE-NEXT: call void @_Z13call_me_firstv()
29 // NOINLINE-NEXT: call void @_Z12then_call_mev()
30 // NOINLINE-NEXT: call void @_GLOBAL__sub_I_GlobalConstructorFunction.hlsl()
31 // NOINLINE-NEXT: %0 = call i32 @llvm.dx.flattened.thread.id.in.group()
32 // NOINLINE-NEXT: call void @_Z4mainj(i32 %0)
33 // NOINLINE-NEXT: call void @_Z12call_me_lastv(
34 // NOINLINE-NEXT: ret void
35
36 // Verify constructor calls are inlined when AlwaysInline is run
37 // INLINE-NEXT: alloca
38 // INLINE-NEXT: store i32 12
39 // INLINE-NEXT: store i32 13
40 // INLINE-NEXT: %[[HANDLE:.*]] = call target("dx.CBuffer", %"__cblayout_$Globals") @"llvm.dx.resource.handlefromimplicitbinding.tdx.CBuffer_s___cblayout_$Globalsst"(i32 0, i32 0, i32 1, i32 0, ptr @"$Globals.str")
41 // INLINE-NEXT: store target("dx.CBuffer", %"__cblayout_$Globals") %[[HANDLE]], ptr @"$Globals.cb", align 4
42 // INLINE-NEXT: %0 = call i32 @llvm.dx.flattened.thread.id.in.group()
43 // INLINE-NEXT: store i32 %
44 // INLINE-NEXT: store i32 0
45 // INLINE: ret void