| 1 |
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -emit-llvm -o - -disable-llvm-passes %s | \ |
| 2 |
// RUN: llvm-cxxfilt | FileCheck %s |
| 3 |
|
| 4 |
// Verify that no per variable _Init_thread instructions are emitted for non-trivial static locals |
| 5 |
// These would normally be emitted by the MicrosoftCXXABI, but the DirectX backend should exlude them |
| 6 |
// Instead, check for the guardvar operations that should protect the constructor initialization should |
| 7 |
// only take place once. |
| 8 |
|
| 9 |
RWBuffer<int> buf[10]; |
| 10 |
|
| 11 |
// CHECK: @[[main_mybuf:.*]] = internal global %"class.hlsl::RWBuffer" zeroinitializer, align 4 |
| 12 |
// CHECK: @[[main_mybuf_guard:.*]] = internal global i8 0, align 1 |
| 13 |
|
| 14 |
void InitBuf(RWBuffer<int> buf) { |
| 15 |
for (unsigned int i = 0; i < 100; i++) |
| 16 |
buf[i] = 0; |
| 17 |
} |
| 18 |
|
| 19 |
// CHECK-NOT: _Init_thread_epoch |
| 20 |
// CHECK: define internal void @main |
| 21 |
// CHECK-NEXT: entry: |
| 22 |
// CHECK-NEXT: [[Tmp0:%.*]] = alloca %"class.hlsl::RWBuffer" |
| 23 |
// CHECK-NEXT: [[Tmp1:%.*]] = alloca %"class.hlsl::RWBuffer" |
| 24 |
// CHECK-NEXT: [[Tmp2:%.*]] = load i8, ptr @guard variable for main()::mybuf |
| 25 |
// CHECK-NEXT: [[Tmp3:%.*]] = icmp eq i8 [[Tmp2]], 0 |
| 26 |
// CHECK-NEXT: br i1 [[Tmp3]] |
| 27 |
// CHECK-NOT: _Init_thread_header |
| 28 |
// CHECK: init.check: |
| 29 |
// CHECK-NEXT: call void @hlsl::RWBuffer<int>::__createFromImplicitBinding |
| 30 |
// CHECK-NEXT: call void @hlsl::RWBuffer<int>::RWBuffer(hlsl::RWBuffer<int> const&)(ptr {{.*}} @main()::mybuf, ptr {{.*}}) # |
| 31 |
// CHECK-NEXT: store i8 1, ptr @guard variable for main()::mybuf |
| 32 |
// CHECK-NOT: _Init_thread_footer |
| 33 |
|
| 34 |
[shader("compute")] |
| 35 |
[numthreads(1,1,1)] |
| 36 |
void main() { |
| 37 |
// A non-trivially constructed static local will get checks to verify that it is generated just once |
| 38 |
static RWBuffer<int> mybuf = buf[0]; |
| 39 |
InitBuf(mybuf); |
| 40 |
} |