Skip to content

Commit 10a06e3

Browse files
committed
[HLSL] Add isHLSLResourceRecordArray method to clang::Type
1 parent 35f003d commit 10a06e3

File tree

4 files changed

+15
-19
lines changed

4 files changed

+15
-19
lines changed

clang/include/clang/AST/Type.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2724,6 +2724,7 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
27242724
bool isHLSLAttributedResourceType() const;
27252725
bool isHLSLInlineSpirvType() const;
27262726
bool isHLSLResourceRecord() const;
2727+
bool isHLSLResourceRecordArray() const;
27272728
bool isHLSLIntangibleType()
27282729
const; // Any HLSL intangible type (builtin, array, class)
27292730

clang/lib/AST/Type.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5246,6 +5246,15 @@ bool Type::isHLSLResourceRecord() const {
52465246
return HLSLAttributedResourceType::findHandleTypeOnResource(this) != nullptr;
52475247
}
52485248

5249+
bool Type::isHLSLResourceRecordArray() const {
5250+
const Type *Ty = getUnqualifiedDesugaredType();
5251+
if (!Ty->isArrayType())
5252+
return false;
5253+
while (isa<ConstantArrayType>(Ty))
5254+
Ty = Ty->getArrayElementTypeNoTypeQual();
5255+
return Ty->isHLSLResourceRecord();
5256+
}
5257+
52495258
bool Type::isHLSLIntangibleType() const {
52505259
const Type *Ty = getUnqualifiedDesugaredType();
52515260

clang/lib/CodeGen/CGHLSLRuntime.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,6 @@ llvm::Triple::ArchType CGHLSLRuntime::getArch() {
103103
return CGM.getTarget().getTriple().getArch();
104104
}
105105

106-
// Returns true if the type is an HLSL resource class or an array of them
107-
static bool isResourceRecordTypeOrArrayOf(const clang::Type *Ty) {
108-
while (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(Ty))
109-
Ty = CAT->getArrayElementTypeNoTypeQual();
110-
return Ty->isHLSLResourceRecord();
111-
}
112-
113106
// Emits constant global variables for buffer constants declarations
114107
// and creates metadata linking the constant globals with the buffer global.
115108
void CGHLSLRuntime::emitBufferGlobalsAndMetadata(const HLSLBufferDecl *BufDecl,
@@ -146,7 +139,7 @@ void CGHLSLRuntime::emitBufferGlobalsAndMetadata(const HLSLBufferDecl *BufDecl,
146139
if (VDTy.getAddressSpace() != LangAS::hlsl_constant) {
147140
if (VD->getStorageClass() == SC_Static ||
148141
VDTy.getAddressSpace() == LangAS::hlsl_groupshared ||
149-
isResourceRecordTypeOrArrayOf(VDTy.getTypePtr())) {
142+
VDTy->isHLSLResourceRecord() || VDTy->isHLSLResourceRecordArray()) {
150143
// Emit static and groupshared variables and resource classes inside
151144
// cbuffer as regular globals
152145
CGM.EmitGlobal(VD);

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -337,16 +337,9 @@ static bool isZeroSizedArray(const ConstantArrayType *CAT) {
337337
return CAT != nullptr;
338338
}
339339

340-
// Returns true if the record type is an HLSL resource class or an array of
341-
// resource classes
342-
static bool isResourceRecordTypeOrArrayOf(const Type *Ty) {
343-
while (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(Ty))
344-
Ty = CAT->getArrayElementTypeNoTypeQual();
345-
return HLSLAttributedResourceType::findHandleTypeOnResource(Ty) != nullptr;
346-
}
347-
348340
static bool isResourceRecordTypeOrArrayOf(VarDecl *VD) {
349-
return isResourceRecordTypeOrArrayOf(VD->getType().getTypePtr());
341+
const Type *Ty = VD->getType().getTypePtr();
342+
return Ty->isHLSLResourceRecord() || Ty->isHLSLResourceRecordArray();
350343
}
351344

352345
// Returns true if the type is a leaf element type that is not valid to be
@@ -355,7 +348,7 @@ static bool isResourceRecordTypeOrArrayOf(VarDecl *VD) {
355348
// type or if it is a record type that needs to be inspected further.
356349
static bool isInvalidConstantBufferLeafElementType(const Type *Ty) {
357350
Ty = Ty->getUnqualifiedDesugaredType();
358-
if (isResourceRecordTypeOrArrayOf(Ty))
351+
if (Ty->isHLSLResourceRecord() || Ty->isHLSLResourceRecordArray())
359352
return true;
360353
if (Ty->isRecordType())
361354
return Ty->getAsCXXRecordDecl()->isEmpty();
@@ -3597,7 +3590,7 @@ void SemaHLSL::deduceAddressSpace(VarDecl *Decl) {
35973590
return;
35983591

35993592
// Resource handles.
3600-
if (isResourceRecordTypeOrArrayOf(Type->getUnqualifiedDesugaredType()))
3593+
if (Type->isHLSLResourceRecord() || Type->isHLSLResourceRecordArray())
36013594
return;
36023595

36033596
// Only static globals belong to the Private address space.

0 commit comments

Comments
 (0)