Skip to content

Commit 4250363

Browse files
committed
Refactor formatTypeName, add CB2 back to test
1 parent f4072fc commit 4250363

File tree

2 files changed

+26
-28
lines changed

2 files changed

+26
-28
lines changed

llvm/lib/Analysis/DXILResource.cpp

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -257,37 +257,34 @@ ResourceTypeInfo::ResourceTypeInfo(TargetExtType *HandleTy,
257257
}
258258

259259
static void formatTypeName(SmallString<64> &Dest, StringRef Name,
260-
bool IsWriteable, bool IsROV) {
261-
Dest = IsWriteable ? (IsROV ? "RasterizerOrdered" : "RW") : "";
262-
Dest += Name;
263-
}
264-
265-
static void formatTypeName(SmallString<64> &Dest, StringRef Name,
266-
bool IsWriteable, bool IsROV, Type *ContainedType,
267-
bool IsSigned) {
260+
bool IsWriteable, bool IsROV,
261+
Type *ContainedType = nullptr,
262+
bool IsSigned = true) {
268263
raw_svector_ostream DestStream(Dest);
269264
if (IsWriteable)
270265
DestStream << (IsROV ? "RasterizerOrdered" : "RW");
271266
DestStream << Name;
272267

273-
if (ContainedType) {
274-
StringRef ElementName;
275-
ElementType ET = toDXILElementType(ContainedType, IsSigned);
276-
if (ET != ElementType::Invalid) {
277-
ElementName = getElementTypeNameForTemplate(ET);
278-
} else if (StructType *ST = dyn_cast<StructType>(ContainedType)) {
279-
if (!ST->hasName())
280-
return;
281-
ElementName = ST->getStructName();
282-
} else {
283-
llvm_unreachable("invalid element type for raw buffer");
284-
}
268+
if (!ContainedType)
269+
return;
285270

286-
if (const FixedVectorType *VTy = dyn_cast<FixedVectorType>(ContainedType))
287-
DestStream << "<" << ElementName << VTy->getNumElements() << ">";
288-
else
289-
DestStream << "<" << ElementName << ">";
271+
StringRef ElementName;
272+
ElementType ET = toDXILElementType(ContainedType, IsSigned);
273+
if (ET != ElementType::Invalid) {
274+
ElementName = getElementTypeNameForTemplate(ET);
275+
} else {
276+
assert(isa<StructType>(ContainedType) &&
277+
"invalid element type for raw buffer");
278+
StructType *ST = cast<StructType>(ContainedType);
279+
if (!ST->hasName())
280+
return;
281+
ElementName = ST->getStructName();
290282
}
283+
284+
DestStream << "<" << ElementName;
285+
if (const FixedVectorType *VTy = dyn_cast<FixedVectorType>(ContainedType))
286+
DestStream << VTy->getNumElements();
287+
DestStream << ">";
291288
}
292289

293290
static StructType *getOrCreateElementStruct(Type *ElemType, StringRef Name) {

llvm/test/CodeGen/DirectX/Metadata/cbuffer_metadata.ll

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ target triple = "dxil-pc-shadermodel6.6-compute"
1111

1212
%__cblayout_CB2 = type <{ float, double, float, half, i16, i64, i32 }>
1313
@CB2.cb = global target("dx.CBuffer", target("dx.Layout", %__cblayout_CB2, 36, 0, 8, 16, 20, 22, 24, 32)) poison
14+
@CB2.str = private unnamed_addr constant [4 x i8] c"CB2\00", align 1
1415

1516
%__cblayout_MyConstants = type <{ double, <3 x float>, float, <3 x double>, half, <2 x double>, float, <3 x half>, <3 x half> }>
1617
@MyConstants.cb = global target("dx.CBuffer", target("dx.Layout", %__cblayout_MyConstants, 96, 0, 16, 28, 32, 56, 64, 80, 84, 90)) poison
@@ -21,7 +22,7 @@ target triple = "dxil-pc-shadermodel6.6-compute"
2122
; PRINT-NEXT:; Name Type Format Dim ID HLSL Bind Count
2223
; PRINT-NEXT:; ------------------------------ ---------- ------- ----------- ------- -------------- ------
2324
; PRINT-NEXT:; CB1 cbuffer NA NA CB0 cb0 1
24-
; PRINT-NEXT:; cbuffer NA NA CB1 cb1 1
25+
; PRINT-NEXT:; CB2 cbuffer NA NA CB1 cb1 1
2526
; PRINT-NEXT:; MyConstants cbuffer NA NA CB2 cb5,space15 1
2627

2728
define void @test() #0 {
@@ -45,7 +46,7 @@ define void @test() #0 {
4546
;}
4647

4748
%CB2.cb_h = call target("dx.CBuffer", target("dx.Layout", %__cblayout_CB2, 36, 0, 8, 16, 20, 22, 24, 32))
48-
@llvm.dx.resource.handlefrombinding(i32 0, i32 1, i32 1, i32 0, i1 false, ptr null)
49+
@llvm.dx.resource.handlefrombinding(i32 0, i32 1, i32 1, i32 0, i1 false, ptr @CB2.str)
4950
; cbuffer CB3 : register(b5) {
5051
; double B0;
5152
; float3 B1;
@@ -66,13 +67,13 @@ define void @test() #0 {
6667
attributes #0 = { noinline nounwind "hlsl.shader"="compute" }
6768

6869
; CHECK: @CB1 = external constant %CBuffer.CB1
69-
; CHECK: @0 = external constant %CBuffer
70+
; CHECK: @CB2 = external constant %CBuffer.CB2
7071
; CHECK: @MyConstants = external constant %CBuffer.MyConstants
7172

7273
; CHECK: !dx.resources = !{[[ResList:[!][0-9]+]]}
7374

7475
; CHECK: [[ResList]] = !{null, null, [[CBList:[!][0-9]+]], null}
7576
; CHECK: [[CBList]] = !{![[CB1:[0-9]+]], ![[CB2:[0-9]+]], ![[MYCONSTANTS:[0-9]+]]}
7677
; CHECK: ![[CB1]] = !{i32 0, ptr @CB1, !"CB1", i32 0, i32 0, i32 1, i32 24, null}
77-
; CHECK: ![[CB2]] = !{i32 1, ptr @0, !"", i32 0, i32 1, i32 1, i32 36, null}
78+
; CHECK: ![[CB2]] = !{i32 1, ptr @CB2, !"CB2", i32 0, i32 1, i32 1, i32 36, null}
7879
; CHECK: ![[MYCONSTANTS]] = !{i32 2, ptr @MyConstants, !"MyConstants", i32 15, i32 5, i32 1, i32 96, null}

0 commit comments

Comments
 (0)