Skip to content

Commit eada966

Browse files
committed
Move findHandleTypeOnResource to static method on HLSLAttributedResourceType
1 parent 71d7514 commit eada966

File tree

4 files changed

+27
-26
lines changed

4 files changed

+27
-26
lines changed

clang/include/clang/AST/Type.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6320,6 +6320,10 @@ class HLSLAttributedResourceType : public Type, public llvm::FoldingSetNode {
63206320
static bool classof(const Type *T) {
63216321
return T->getTypeClass() == HLSLAttributedResource;
63226322
}
6323+
6324+
// Returns handle type from HLSL resource, if the type is a resource
6325+
static const HLSLAttributedResourceType *
6326+
findHandleTypeOnResource(const Type *RT);
63236327
};
63246328

63256329
class TemplateTypeParmType : public Type, public llvm::FoldingSetNode {

clang/lib/AST/Type.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5334,3 +5334,18 @@ std::string FunctionEffectWithCondition::description() const {
53345334
Result += "(expr)";
53355335
return Result;
53365336
}
5337+
5338+
const HLSLAttributedResourceType *
5339+
HLSLAttributedResourceType::findHandleTypeOnResource(const Type *RT) {
5340+
// If the type T is an HLSL resource class, the first field must
5341+
// be the resource handle of type HLSLAttributedResourceType
5342+
const clang::Type *Ty = RT->getUnqualifiedDesugaredType();
5343+
if (const RecordDecl *RD = Ty->getAsCXXRecordDecl()) {
5344+
if (!RD->fields().empty()) {
5345+
const auto &FirstFD = RD->fields().begin();
5346+
return dyn_cast<HLSLAttributedResourceType>(
5347+
FirstFD->getType().getTypePtr());
5348+
}
5349+
}
5350+
return nullptr;
5351+
}

clang/lib/CodeGen/CGHLSLRuntime.cpp

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

498-
// Returns handle type of a resource, if the type is a resource
499-
// or an array of resources
500-
static const HLSLAttributedResourceType *findHandleTypeOnResource(QualType QT) {
501-
// If the type is a resource class, the first field must
502-
// be the resource handle of type HLSLAttributedResourceType
503-
const clang::Type *Ty = QT->getUnqualifiedDesugaredType();
504-
if (RecordDecl *RD = Ty->getAsCXXRecordDecl()) {
505-
if (!RD->fields().empty()) {
506-
const auto &FirstFD = RD->fields().begin();
507-
return dyn_cast<HLSLAttributedResourceType>(
508-
FirstFD->getType().getTypePtr());
509-
}
510-
}
511-
return nullptr;
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);
512502
}
513503

514504
void CGHLSLRuntime::handleGlobalVarDefinition(const VarDecl *VD,
@@ -519,7 +509,7 @@ void CGHLSLRuntime::handleGlobalVarDefinition(const VarDecl *VD,
519509
if (!RBA)
520510
return;
521511

522-
if (!findHandleTypeOnResource(VD->getType()))
512+
if (!findHandleTypeOnResource(VD->getType().getTypePtr()))
523513
// FIXME: Only simple declarations of resources are supported for now.
524514
// Arrays of resources or resources in user defined classes are
525515
// not implemented yet.
@@ -557,7 +547,7 @@ llvm::Function *CGHLSLRuntime::createResourceBindingInitFn() {
557547
continue;
558548

559549
const HLSLAttributedResourceType *AttrResType =
560-
findHandleTypeOnResource(VD->getType());
550+
findHandleTypeOnResource(VD->getType().getTypePtr());
561551

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

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,16 +1000,8 @@ static CXXRecordDecl *getRecordDeclFromVarDecl(VarDecl *VD) {
10001000
}
10011001

10021002
static const HLSLAttributedResourceType *
1003-
findAttributedResourceTypeOnField(VarDecl *VD) {
1004-
assert(VD != nullptr && "expected VarDecl");
1005-
if (RecordDecl *RD = getRecordDeclFromVarDecl(VD)) {
1006-
for (auto *FD : RD->fields()) {
1007-
if (const HLSLAttributedResourceType *AttrResType =
1008-
dyn_cast<HLSLAttributedResourceType>(FD->getType().getTypePtr()))
1009-
return AttrResType;
1010-
}
1011-
}
1012-
return nullptr;
1003+
findHandleTypeOnResource(const Type *Ty) {
1004+
return HLSLAttributedResourceType::findHandleTypeOnResource(Ty);
10131005
}
10141006

10151007
// Iterate over RecordType fields and return true if any of them matched the

0 commit comments

Comments
 (0)