1; RUN: opt -S -passes=dxil-translate-metadata,dxil-op-lower %s | FileCheck %s 2; RUN: opt -S -passes=dxil-pretty-printer %s 2>&1 >/dev/null | FileCheck --check-prefix=CHECK-PRETTY %s 3 4; CHECK-PRETTY: Type Format Dim ID HLSL Bind Count 5; CHECK-PRETTY: ---------- ------- ----------- ------- -------------- --------- 6; CHECK-PRETTY: SRV f32 buf T0 t7 unbounded 7; CHECK-PRETTY: SRV byte r/o T1 t8,space1 1 8; CHECK-PRETTY: SRV struct r/o T2 t2,space4 1 9; CHECK-PRETTY: SRV u32 buf T3 t3,space5 24 10; CHECK-PRETTY: UAV i32 buf U0 u7,space2 1 11; CHECK-PRETTY: UAV f32 buf U1 u5,space3 1 12 13target triple = "dxil-pc-shadermodel6.0-compute" 14 15declare i32 @some_val(); 16 17define void @test_buffers() { 18 ; RWBuffer<float4> Buf : register(u5, space3) 19 %typed0 = call target("dx.TypedBuffer", <4 x float>, 1, 0, 0) 20 @llvm.dx.resource.handlefrombinding.tdx.TypedBuffer_v4f32_1_0_0( 21 i32 3, i32 5, i32 1, i32 0, i1 false) 22 ; CHECK: call %dx.types.Handle @dx.op.createHandle(i32 57, i8 1, i32 1, i32 5, i1 false) #[[#ATTR:]] 23 ; CHECK-NOT: @llvm.dx.cast.handle 24 25 ; RWBuffer<int> Buf : register(u7, space2) 26 %typed1 = call target("dx.TypedBuffer", i32, 1, 0, 1) 27 @llvm.dx.resource.handlefrombinding.tdx.TypedBuffer_i32_1_0_1t( 28 i32 2, i32 7, i32 1, i32 0, i1 false) 29 ; CHECK: call %dx.types.Handle @dx.op.createHandle(i32 57, i8 1, i32 0, i32 7, i1 false) #[[#ATTR]] 30 31 ; Buffer<uint4> Buf[24] : register(t3, space5) 32 ; Buffer<uint4> typed2 = Buf[4] 33 ; Note that the index below is 3 + 4 = 7 34 %typed2 = call target("dx.TypedBuffer", <4 x i32>, 0, 0, 0) 35 @llvm.dx.resource.handlefrombinding.tdx.TypedBuffer_i32_0_0_0t( 36 i32 5, i32 3, i32 24, i32 4, i1 false) 37 ; CHECK: call %dx.types.Handle @dx.op.createHandle(i32 57, i8 0, i32 3, i32 7, i1 false) #[[#ATTR]] 38 39 ; struct S { float4 a; uint4 b; }; 40 ; StructuredBuffer<S> Buf : register(t2, space4) 41 %struct0 = call target("dx.RawBuffer", {<4 x float>, <4 x i32>}, 0, 0) 42 @llvm.dx.resource.handlefrombinding.tdx.RawBuffer_sl_v4f32v4i32s_0_0t( 43 i32 4, i32 2, i32 1, i32 0, i1 true) 44 ; CHECK: call %dx.types.Handle @dx.op.createHandle(i32 57, i8 0, i32 2, i32 2, i1 true) #[[#ATTR]] 45 46 ; ByteAddressBuffer Buf : register(t8, space1) 47 %byteaddr0 = call target("dx.RawBuffer", i8, 0, 0) 48 @llvm.dx.resource.handlefrombinding.tdx.RawBuffer_i8_0_0t( 49 i32 1, i32 8, i32 1, i32 0, i1 false) 50 ; CHECK: call %dx.types.Handle @dx.op.createHandle(i32 57, i8 0, i32 1, i32 8, i1 false) #[[#ATTR]] 51 52 ; Buffer<float4> Buf[] : register(t7) 53 ; Buffer<float4> typed3 = Buf[ix] 54 %typed3_ix = call i32 @some_val() 55 %typed3 = call target("dx.TypedBuffer", <4 x float>, 0, 0, 0) 56 @llvm.dx.resource.handlefrombinding.tdx.TypedBuffer_v4f32_0_0_0t( 57 i32 0, i32 7, i32 -1, i32 %typed3_ix, i1 false) 58 ; CHECK: %[[IX:.*]] = add i32 %typed3_ix, 7 59 ; CHECK: call %dx.types.Handle @dx.op.createHandle(i32 57, i8 0, i32 0, i32 %[[IX]], i1 false) #[[#ATTR]] 60 61 ret void 62} 63 64; CHECK: attributes #[[#ATTR]] = {{{.*}} memory(read) {{.*}}} 65 66; Just check that we have the right types and number of metadata nodes, the 67; contents of the metadata are tested elsewhere. 68; 69; CHECK: !dx.resources = !{[[RESMD:![0-9]+]]} 70; CHECK: [[RESMD]] = !{[[SRVMD:![0-9]+]], [[UAVMD:![0-9]+]], null, null} 71; CHECK-DAG: [[SRVMD]] = !{!{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}} 72; CHECK-DAG: [[UAVMD]] = !{!{{[0-9]+}}, !{{[0-9]+}}} 73 74attributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) } 75