Skip to content

Commit 9b54bbd

Browse files
committed
code review feedback - use std::array, llvm_unreachanble, add test, fix typo
1 parent d1b3e3a commit 9b54bbd

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

clang/lib/CodeGen/CGHLSLRuntime.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ static int getTotalArraySize(ASTContext &AST, const clang::Type *Ty) {
117117
static CXXConstructorDecl *findResourceConstructorDecl(ASTContext &AST,
118118
QualType ResTy,
119119
bool ExplicitBinding) {
120-
SmallVector<QualType> ExpParmTypes = {
120+
std::array<QualType, 5> ExpParmTypes = {
121121
AST.UnsignedIntTy, AST.UnsignedIntTy, AST.UnsignedIntTy,
122122
AST.UnsignedIntTy, AST.getPointerType(AST.CharTy.withConst())};
123123
ExpParmTypes[ExplicitBinding ? 2 : 1] = AST.IntTy;
@@ -126,8 +126,8 @@ static CXXConstructorDecl *findResourceConstructorDecl(ASTContext &AST,
126126
for (auto *Ctor : ResDecl->ctors()) {
127127
if (Ctor->getNumParams() != ExpParmTypes.size())
128128
continue;
129-
ParmVarDecl **ParmIt = Ctor->param_begin();
130-
QualType *ExpTyIt = ExpParmTypes.begin();
129+
auto *ParmIt = Ctor->param_begin();
130+
auto ExpTyIt = ExpParmTypes.begin();
131131
for (; ParmIt != Ctor->param_end() && ExpTyIt != ExpParmTypes.end();
132132
++ParmIt, ++ExpTyIt) {
133133
if ((*ParmIt)->getType() != *ExpTyIt)
@@ -807,9 +807,10 @@ std::optional<LValue> CGHLSLRuntime::emitResourceArraySubscriptExpr(
807807
if (!ArrayDecl || !ArrayDecl->hasGlobalStorage())
808808
return std::nullopt;
809809

810-
// FIXME: this is not yet implemented (llvm/llvm-project#145426)
811-
assert(!ArraySubsExpr->getType()->isArrayType() &&
812-
"indexing of array subsets it not supported yet");
810+
if (ArraySubsExpr->getType()->isArrayType())
811+
// FIXME: this is not yet implemented (llvm/llvm-project#145426)
812+
llvm_unreachable(
813+
"indexing of sub-arrays of multidimensional arrays not supported yet");
813814

814815
// get the resource array type
815816
ASTContext &AST = ArrayDecl->getASTContext();

clang/test/CodeGenHLSL/resources/res-array-global.hlsl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// CHECK: @[[BufB:.*]] = private unnamed_addr constant [2 x i8] c"B\00", align 1
88
// CHECK: @[[BufC:.*]] = private unnamed_addr constant [2 x i8] c"C\00", align 1
99
// CHECK: @[[BufD:.*]] = private unnamed_addr constant [2 x i8] c"D\00", align 1
10+
// CHECK: @[[BufE:.*]] = private unnamed_addr constant [2 x i8] c"E\00", align 1
1011

1112
// different explicit binding for DXIL and SPIR-V
1213
[[vk::binding(12, 2)]]
@@ -22,6 +23,9 @@ RWBuffer<int> C[3] : register(u2);
2223
// implicit binding for both DXIL and SPIR-V in space/set 0
2324
RWBuffer<double> D[10];
2425

26+
// implicit binding for both DXIL and SPIR-V with specified space/set 0
27+
RWBuffer<uint> E[15] : register(space2);
28+
2529
RWStructuredBuffer<float> Out;
2630

2731
[numthreads(4,1,1)]
@@ -31,6 +35,7 @@ void main() {
3135
// CHECK: %[[Tmp1:.*]] = alloca %"class.hlsl::RWBuffer
3236
// CHECK: %[[Tmp2:.*]] = alloca %"class.hlsl::RWBuffer
3337
// CHECK: %[[Tmp3:.*]] = alloca %"class.hlsl::RWBuffer
38+
// CHECK: %[[Tmp4:.*]] = alloca %"class.hlsl::RWBuffer
3439

3540
// NOTE:
3641
// Constructor call for explicit binding has "jjij" in the mangled name and the arguments are (register, space, range_size, index, name).
@@ -62,5 +67,9 @@ void main() {
6267
// for both DXIL and SPIR-V
6368
// DXIL: call void @_ZN4hlsl8RWBufferIdEC1EjijjPKc(ptr {{.*}} %[[Tmp3]], i32 noundef 0, i32 noundef 10, i32 noundef 7, i32 noundef 1, ptr noundef @[[BufD]])
6469
// SPV: call void @_ZN4hlsl8RWBufferIdEC1EjijjPKc(ptr {{.*}} %[[Tmp3]], i32 noundef 0, i32 noundef 10, i32 noundef 7, i32 noundef 0, ptr noundef @[[BufD]])
65-
Out[0] = A[2][0] + (float)B[3][0] + (float)C[1][0] + (float)D[7][0];
70+
71+
// Make sure E[5][0] is translated to RWBuffer<uint> constructor call with implicit binding and specified space/set 2
72+
// DXIL: call void @_ZN4hlsl8RWBufferIjEC1EjijjPKc(ptr {{.*}} %[[Tmp4]], i32 noundef 2, i32 noundef 15, i32 noundef 5, i32 noundef 2, ptr noundef @[[BufE]])
73+
// SPV: call void @_ZN4hlsl8RWBufferIjEC1EjijjPKc(ptr {{.*}} %[[Tmp4]], i32 noundef 2, i32 noundef 15, i32 noundef 5, i32 noundef 1, ptr noundef @[[BufE]])
74+
Out[0] = A[2][0] + (float)B[3][0] + (float)C[1][0] + (float)D[7][0] + (float)E[5][0];
6675
}

clang/test/CodeGenHLSL/resources/resource-bindings.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct S {
4444
};
4545
RWStructuredBuffer<S> T3S0 : register(u3);
4646

47-
// Resource array elements are initialized on access; make sure there is not call
47+
// Resource array elements are initialized on access; make sure there is no call
4848
// to initialize RWBuffer<double>.
4949
// CHECK-NOT: call target("dx.TypedBuffer", double, 1, 0, 0) @llvm.dx.resource.handlefrombinding.tdx.TypedBuffer_f64_1_0_0t(
5050
RWBuffer<double> Array[10] : register(u4, space0);

0 commit comments

Comments
 (0)