Skip to content

Commit 69371e5

Browse files
committed
Use static findHandleTypeOnResource directly, update tests after merge
1 parent f1d1e55 commit 69371e5

File tree

5 files changed

+24
-26
lines changed

5 files changed

+24
-26
lines changed

clang/lib/AST/Type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5338,7 +5338,7 @@ std::string FunctionEffectWithCondition::description() const {
53385338

53395339
const HLSLAttributedResourceType *
53405340
HLSLAttributedResourceType::findHandleTypeOnResource(const Type *RT) {
5341-
// If the type T is an HLSL resource class, the first field must
5341+
// If the type RT is an HLSL resource class, the first field must
53425342
// be the resource handle of type HLSLAttributedResourceType
53435343
const clang::Type *Ty = RT->getUnqualifiedDesugaredType();
53445344
if (const RecordDecl *RD = Ty->getAsCXXRecordDecl()) {

clang/lib/CodeGen/CGHLSLRuntime.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -495,12 +495,6 @@ void CGHLSLRuntime::generateGlobalCtorDtorCalls() {
495495
}
496496
}
497497

498-
// Returns handle type from a resource, if the type is a resource
499-
static const HLSLAttributedResourceType *
500-
findHandleTypeOnResource(const clang::Type *Ty) {
501-
return HLSLAttributedResourceType::findHandleTypeOnResource(Ty);
502-
}
503-
504498
void CGHLSLRuntime::handleGlobalVarDefinition(const VarDecl *VD,
505499
llvm::GlobalVariable *GV) {
506500
// If the global variable has resource binding, add it to the list of globals
@@ -509,7 +503,8 @@ void CGHLSLRuntime::handleGlobalVarDefinition(const VarDecl *VD,
509503
if (!RBA)
510504
return;
511505

512-
if (!findHandleTypeOnResource(VD->getType().getTypePtr()))
506+
if (!HLSLAttributedResourceType::findHandleTypeOnResource(
507+
VD->getType().getTypePtr()))
513508
// FIXME: Only simple declarations of resources are supported for now.
514509
// Arrays of resources or resources in user defined classes are
515510
// not implemented yet.
@@ -547,7 +542,8 @@ llvm::Function *CGHLSLRuntime::createResourceBindingInitFn() {
547542
continue;
548543

549544
const HLSLAttributedResourceType *AttrResType =
550-
findHandleTypeOnResource(VD->getType().getTypePtr());
545+
HLSLAttributedResourceType::findHandleTypeOnResource(
546+
VD->getType().getTypePtr());
551547

552548
// FIXME: Only simple declarations of resources are supported for now.
553549
// Arrays of resources or resources in user defined classes are

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,12 +1039,6 @@ SemaHLSL::TakeLocForHLSLAttribute(const HLSLAttributedResourceType *RT) {
10391039
return LocInfo;
10401040
}
10411041

1042-
// Returns handle type of a resource, if the type is a resource
1043-
static const HLSLAttributedResourceType *
1044-
findHandleTypeOnResource(const Type *Ty) {
1045-
return HLSLAttributedResourceType::findHandleTypeOnResource(Ty);
1046-
}
1047-
10481042
// Walks though the global variable declaration, collects all resource binding
10491043
// requirements and adds them to Bindings
10501044
void SemaHLSL::collectResourcesOnUserRecordDecl(const VarDecl *VD,
@@ -1066,7 +1060,7 @@ void SemaHLSL::collectResourcesOnUserRecordDecl(const VarDecl *VD,
10661060
continue;
10671061

10681062
if (const HLSLAttributedResourceType *AttrResType =
1069-
findHandleTypeOnResource(Ty)) {
1063+
HLSLAttributedResourceType::findHandleTypeOnResource(Ty)) {
10701064
// Add a new DeclBindingInfo to Bindings if it does not already exist
10711065
ResourceClass RC = AttrResType->getAttrs().ResourceClass;
10721066
DeclBindingInfo *DBI = Bindings.getDeclBindingInfo(VD, RC);
@@ -1117,7 +1111,8 @@ static bool DiagnoseLocalRegisterBinding(Sema &S, SourceLocation &ArgLoc,
11171111

11181112
// Resource
11191113
if (const HLSLAttributedResourceType *AttrResType =
1120-
findHandleTypeOnResource(VD->getType().getTypePtr())) {
1114+
HLSLAttributedResourceType::findHandleTypeOnResource(
1115+
VD->getType().getTypePtr())) {
11211116
if (RegType == getRegisterType(AttrResType->getAttrs().ResourceClass))
11221117
return true;
11231118

@@ -2360,7 +2355,7 @@ void SemaHLSL::collectResourcesOnVarDecl(VarDecl *VD) {
23602355

23612356
// Resource (or array of resources)
23622357
if (const HLSLAttributedResourceType *AttrResType =
2363-
findHandleTypeOnResource(Ty)) {
2358+
HLSLAttributedResourceType::findHandleTypeOnResource(Ty)) {
23642359
Bindings.addDeclBindingInfo(VD, AttrResType->getAttrs().ResourceClass);
23652360
return;
23662361
}

clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,20 @@
66

77
RWBuffer<float> Buf : register(u5, space3);
88

9-
// CHECK: define linkonce_odr noundef ptr @"??0?$RWBuffer@M@hlsl@@QAA@XZ"
9+
// CHECK: %"class.hlsl::RWBuffer" = type { target("dx.TypedBuffer", float, 1, 0, 0), float }
10+
// CHECK: @Buf = global %"class.hlsl::RWBuffer" zeroinitializer, align 4
11+
12+
// CHECK: define linkonce_odr void @_ZN4hlsl8RWBufferIfEC2Ev(ptr noundef nonnull align 4 dereferenceable(8) %this)
1013
// CHECK-NEXT: entry:
1114

1215
// CHECK: define internal void @_GLOBAL__sub_I_RWBuffer_constructor.hlsl()
1316
// CHECK-NEXT: entry:
14-
// CHECK-NEXT: call void @"??__EBuf@@YAXXZ"()
17+
// CHECK-NEXT: call void @__cxx_global_var_init()
1518
// CHECK-NEXT: call void @_init_resource_bindings()
1619

1720
// CHECK: define internal void @_init_resource_bindings() {
1821
// CHECK-NEXT: entry:
1922
// CHECK-DXIL-NEXT: %Buf_h = call target("dx.TypedBuffer", float, 1, 0, 0) @llvm.dx.handle.fromBinding.tdx.TypedBuffer_f32_1_0_0t(i32 3, i32 5, i32 1, i32 0, i1 false)
20-
// CHECK-DXIL-NEXT: store target("dx.TypedBuffer", float, 1, 0, 0) %Buf_h, ptr @"?Buf@@3V?$RWBuffer@M@hlsl@@A", align 4
23+
// CHECK-DXIL-NEXT: store target("dx.TypedBuffer", float, 1, 0, 0) %Buf_h, ptr @Buf, align 4
2124
// CHECK-SPIRV-NEXT: %Buf_h = call target("dx.TypedBuffer", float, 1, 0, 0) @llvm.spv.handle.fromBinding.tdx.TypedBuffer_f32_1_0_0t(i32 3, i32 5, i32 1, i32 0, i1 false)
22-
// CHECK-SPIRV-NEXT: store target("dx.TypedBuffer", float, 1, 0, 0) %Buf_h, ptr @"?Buf@@3V?$RWBuffer@M@hlsl@@A", align 4
25+
// CHECK-SPIRV-NEXT: store target("dx.TypedBuffer", float, 1, 0, 0) %Buf_h, ptr @Buf, align 4

clang/test/CodeGenHLSL/builtins/StructuredBuffer-constructor.hlsl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,23 @@
22
// RUN-DISABLED: %clang_cc1 -triple spirv-vulkan-library -x hlsl -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-SPIRV
33

44
// NOTE: SPIRV codegen for resource types is not yet implemented
5+
56
StructuredBuffer<float> Buf : register(u10);
67

7-
// CHECK: define linkonce_odr noundef ptr @"??0?$StructuredBuffer@M@hlsl@@QAA@XZ"
8+
// CHECK: %"class.hlsl::StructuredBuffer" = type { target("dx.RawBuffer", float, 1, 0), float }
9+
// CHECK: @Buf = global %"class.hlsl::StructuredBuffer" zeroinitializer, align 4
10+
11+
// CHECK: define linkonce_odr void @_ZN4hlsl16StructuredBufferIfEC2Ev(ptr noundef nonnull align 4 dereferenceable(8) %this)
812
// CHECK-NEXT: entry:
913

1014
// CHECK: define internal void @_GLOBAL__sub_I_StructuredBuffer_constructor.hlsl()
1115
// CHECK-NEXT: entry:
12-
// CHECK-NEXT: call void @"??__EBuf@@YAXXZ"()
16+
// CHECK-NEXT: call void @__cxx_global_var_init()
1317
// CHECK-NEXT: call void @_init_resource_bindings()
1418

1519
// CHECK: define internal void @_init_resource_bindings() {
1620
// CHECK-NEXT: entry:
1721
// CHECK-DXIL-NEXT: %Buf_h = call target("dx.RawBuffer", float, 1, 0) @llvm.dx.handle.fromBinding.tdx.RawBuffer_f32_1_0t(i32 0, i32 10, i32 1, i32 0, i1 false)
18-
// CHECK-DXIL-NEXT: store target("dx.RawBuffer", float, 1, 0) %Buf_h, ptr @"?Buf@@3V?$StructuredBuffer@M@hlsl@@A", align 4
22+
// CHECK-DXIL-NEXT: store target("dx.RawBuffer", float, 1, 0) %Buf_h, ptr @Buf, align 4
1923
// CHECK-SPIRV-NEXT: %Buf_h = call target("dx.RawBuffer", float, 1, 0) @llvm.spv.handle.fromBinding.tdx.RawBuffer_f32_1_0t(i32 0, i32 10, i32 1, i32 0, i1 false)
20-
// CHECK-SPIRV-NEXT: store target("dx.RawBuffer", float, 1, 0) %Buf_h, ptr @"?Buf@@3V?$StructuredBuffer@M@hlsl@@A", align 4
24+
// CHECK-SPIRV-NEXT: store target("dx.RawBuffer", float, 1, 0) %Buf_h, ptr @Buf", align 4

0 commit comments

Comments
 (0)