| 1 |
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -emit-llvm -disable-llvm-passes -o - %s | \ |
| 2 |
// RUN: llvm-cxxfilt | FileCheck %s --check-prefixes=CHECK,CHECK-DXIL |
| 3 |
// FIXME: SPIR-V codegen of llvm.spv.resource.handlefrombinding and resource types is not yet implemented |
| 4 |
// RUN-DISABLED: %clang_cc1 -triple spirv-vulkan-library -x hlsl -emit-llvm -disable-llvm-passes -o - %s | \ |
| 5 |
// llvm-cxxfilt | FileCheck %s --check-prefixes=CHECK,CHECK-SPIRV |
| 6 |
|
| 7 |
// NOTE: Itanium ABI for C++ requires Clang to generate 2 constructors types to support polymorphism: |
| 8 |
// - C1 - Complete object constructor - constructs the complete object, including virtual base classes. |
| 9 |
// - C2 - Base object constructor - creates the object itself and initializes data members and non-virtual base classes. |
| 10 |
// The constructors are distinquished by C1/C2 designators in their mangled name. |
| 11 |
// https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling-special-ctor-dtor |
| 12 |
|
| 13 |
// Resource with explicit binding |
| 14 |
ByteAddressBuffer Buf1 : register(t1, space2); |
| 15 |
|
| 16 |
// Resource with implicit binding |
| 17 |
RWByteAddressBuffer Buf2; |
| 18 |
|
| 19 |
export void foo() { |
| 20 |
// Local resource declaration |
| 21 |
RasterizerOrderedByteAddressBuffer Buf3; |
| 22 |
} |
| 23 |
|
| 24 |
// CHECK: %"class.hlsl::ByteAddressBuffer" = type { target("dx.RawBuffer", i8, 0, 0) } |
| 25 |
// CHECK: %"class.hlsl::RWByteAddressBuffer" = type { target("dx.RawBuffer", i8, 1, 0) } |
| 26 |
// CHECK: %"class.hlsl::RasterizerOrderedByteAddressBuffer" = type { target("dx.RawBuffer", i8, 1, 1) } |
| 27 |
|
| 28 |
// CHECK: @Buf1 = internal global %"class.hlsl::ByteAddressBuffer" poison, align 4 |
| 29 |
// CHECK: @[[Buf1Str:.*]] = private unnamed_addr constant [5 x i8] c"Buf1\00", align 1 |
| 30 |
// CHECK: @Buf2 = internal global %"class.hlsl::RWByteAddressBuffer" poison, align 4 |
| 31 |
// CHECK: @[[Buf2Str:.*]] = private unnamed_addr constant [5 x i8] c"Buf2\00", align 1 |
| 32 |
|
| 33 |
// Buf1 initialization part 1 - global init function that calls ByteAddressBuffer::__createFromBinding |
| 34 |
// CHECK: define internal void @__cxx_global_var_init() |
| 35 |
// CHECK-NEXT: entry: |
| 36 |
// CHECK-NEXT: call void @hlsl::ByteAddressBuffer::__createFromBinding(unsigned int, unsigned int, int, unsigned int, char const*) |
| 37 |
// CHECK-SAME: (ptr {{.*}} @Buf1, i32 noundef 1, i32 noundef 2, i32 noundef 1, i32 noundef 0, ptr noundef @[[Buf1Str]]) |
| 38 |
|
| 39 |
// Buf1 initialization part 2 - body of ByteAddressBuffer::__createFromBinding |
| 40 |
// CHECK: define {{.*}} void @hlsl::ByteAddressBuffer::__createFromBinding(unsigned int, unsigned int, int, unsigned int, char const*) |
| 41 |
// CHECK-SAME: (ptr {{.*}} sret(%"class.hlsl::ByteAddressBuffer") align 4 %[[RetValue1:.*]], i32 noundef %registerNo, |
| 42 |
// CHECK-SAME: i32 noundef %spaceNo, i32 noundef %range, i32 noundef %index, ptr noundef %name) |
| 43 |
// CHECK: %[[Tmp1:.*]] = alloca %"class.hlsl::ByteAddressBuffer", align 4 |
| 44 |
// CHECK: %[[Handle1:.*]] = call target("dx.RawBuffer", i8, 0, 0) |
| 45 |
// CHECK-SAME: @llvm.dx.resource.handlefrombinding.tdx.RawBuffer_i8_0_0t( |
| 46 |
// CHECK: %__handle = getelementptr inbounds nuw %"class.hlsl::ByteAddressBuffer", ptr %[[Tmp1]], i32 0, i32 0 |
| 47 |
// CHECK-DXIL: store target("dx.RawBuffer", i8, 0, 0) %[[Handle1]], ptr %__handle, align 4 |
| 48 |
// CHECK: call void @hlsl::ByteAddressBuffer::ByteAddressBuffer(hlsl::ByteAddressBuffer const&)(ptr {{.*}} %[[RetValue1]], ptr {{.*}} %[[Tmp1]]) |
| 49 |
|
| 50 |
// Buf2 initialization part 1 - global init function that calls RWByteAddressBuffer::__createFromImplicitBinding |
| 51 |
// CHECK: define internal void @__cxx_global_var_init.1() |
| 52 |
// CHECK-NEXT: entry: |
| 53 |
// CHECK-NEXT: call void @hlsl::RWByteAddressBuffer::__createFromImplicitBinding(unsigned int, unsigned int, int, unsigned int, char const*) |
| 54 |
// CHECK-SAME: (ptr {{.*}} @Buf2, i32 noundef 0, i32 noundef 0, i32 noundef 1, i32 noundef 0, ptr noundef @[[Buf2Str]]) |
| 55 |
|
| 56 |
// Buf2 initialization part 2 - body of RWByteAddressBuffer::__createFromImplicitBinding |
| 57 |
// CHECK: define hidden void @hlsl::RWByteAddressBuffer::__createFromImplicitBinding(unsigned int, unsigned int, int, unsigned int, char const*) |
| 58 |
// CHECK-SAME: (ptr {{.*}} sret(%"class.hlsl::RWByteAddressBuffer") align 4 %[[RetValue2:.*]], i32 noundef %orderId, |
| 59 |
// CHECK-SAME: i32 noundef %spaceNo, i32 noundef %range, i32 noundef %index, ptr noundef %name) |
| 60 |
// CHECK: %[[Tmp2:.*]] = alloca %"class.hlsl::RWByteAddressBuffer", align 4 |
| 61 |
// CHECK: %[[Handle2:.*]] = call target("dx.RawBuffer", i8, 1, 0) |
| 62 |
// CHECK-SAME: @llvm.dx.resource.handlefromimplicitbinding.tdx.RawBuffer_i8_1_0t( |
| 63 |
// CHECK: %__handle = getelementptr inbounds nuw %"class.hlsl::RWByteAddressBuffer", ptr %[[Tmp2]], i32 0, i32 0 |
| 64 |
// CHECK-DXIL: store target("dx.RawBuffer", i8, 1, 0) %[[Handle2]], ptr %__handle, align 4 |
| 65 |
// CHECK: call void @hlsl::RWByteAddressBuffer::RWByteAddressBuffer(hlsl::RWByteAddressBuffer const&)(ptr {{.*}} %[[RetValue2]], ptr {{.*}} %[[Tmp2]]) |
| 66 |
|
| 67 |
// Buf3 initialization part 1 - local variable declared in function foo() is initialized by |
| 68 |
// RasterizerOrderedByteAddressBuffer C1 default constructor |
| 69 |
// CHECK: define void @foo() |
| 70 |
// CHECK-NEXT: entry: |
| 71 |
// CHECK-NEXT: %Buf3 = alloca %"class.hlsl::RasterizerOrderedByteAddressBuffer", align 4 |
| 72 |
// CHECK-NEXT: call void @hlsl::RasterizerOrderedByteAddressBuffer::RasterizerOrderedByteAddressBuffer()(ptr {{.*}} %Buf3) |
| 73 |
|
| 74 |
// Buf3 initialization part 2 - body of RasterizerOrderedByteAddressBuffer default C1 constructor that |
| 75 |
// calls the default C2 constructor |
| 76 |
// CHECK: define linkonce_odr hidden void @hlsl::RasterizerOrderedByteAddressBuffer::RasterizerOrderedByteAddressBuffer()(ptr {{.*}} %this) |
| 77 |
// CHECK: call void @hlsl::RasterizerOrderedByteAddressBuffer::RasterizerOrderedByteAddressBuffer()(ptr {{.*}} %this1) |
| 78 |
// CHECK-NEXT: ret void |
| 79 |
|
| 80 |
// Buf3 initialization part 3 - body of RasterizerOrderedByteAddressBuffer default C2 constructor that |
| 81 |
// initializes handle to poison |
| 82 |
// CHECK: define linkonce_odr hidden void @hlsl::RasterizerOrderedByteAddressBuffer::RasterizerOrderedByteAddressBuffer()(ptr {{.*}} %this) |
| 83 |
// CHECK: %__handle = getelementptr inbounds nuw %"class.hlsl::RasterizerOrderedByteAddressBuffer", ptr %{{.*}}, i32 0, i32 0 |
| 84 |
// CHECK: store target("dx.RawBuffer", i8, 1, 1) poison, ptr %__handle, align 4 |
| 85 |
|
| 86 |
// Module initialization |
| 87 |
// CHECK: define internal void @_GLOBAL__sub_I_ByteAddressBuffers_constructors.hlsl() |
| 88 |
// CHECK-NEXT: entry: |
| 89 |
// CHECK-NEXT: call void @__cxx_global_var_init() |
| 90 |
// CHECK-NEXT: call void @__cxx_global_var_init.1() |