Skip to content

Commit 9b98455

Browse files
authored
[HLSL][NFC] Move IsIntangibleType from SemaHLSL to Type to make it accessible outside of Sema (#113206)
Moves `IsIntangibleType` from SemaHLSL to Type class and renames it to `isHLSLIntangibleType`. The existing `isHLSLIntangibleType` is renamed to `isHLSLBuiltinIntangibleType` and updated to return true only for the builtin `__hlsl_resource_t` type. This change makes `isHLSLIntangibleType` functionality accessible outside of Sema, for example from clang CodeGen.
1 parent 4334f31 commit 9b98455

File tree

6 files changed

+34
-35
lines changed

6 files changed

+34
-35
lines changed

clang/include/clang/AST/Type.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2661,8 +2661,10 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
26612661
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) bool is##Id##Type() const;
26622662
#include "clang/Basic/HLSLIntangibleTypes.def"
26632663
bool isHLSLSpecificType() const; // Any HLSL specific type
2664-
bool isHLSLIntangibleType() const; // Any HLSL intangible type
2664+
bool isHLSLBuiltinIntangibleType() const; // Any HLSL builtin intangible type
26652665
bool isHLSLAttributedResourceType() const;
2666+
bool isHLSLIntangibleType()
2667+
const; // Any HLSL intangible type (builtin, array, class)
26662668

26672669
/// Determines if this type, which must satisfy
26682670
/// isObjCLifetimeType(), is implicitly __unsafe_unretained rather
@@ -8450,15 +8452,15 @@ inline bool Type::isOpenCLSpecificType() const {
84508452
}
84518453
#include "clang/Basic/HLSLIntangibleTypes.def"
84528454

8453-
inline bool Type::isHLSLIntangibleType() const {
8455+
inline bool Type::isHLSLBuiltinIntangibleType() const {
84548456
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) is##Id##Type() ||
84558457
return
84568458
#include "clang/Basic/HLSLIntangibleTypes.def"
8457-
isHLSLAttributedResourceType();
8459+
false;
84588460
}
84598461

84608462
inline bool Type::isHLSLSpecificType() const {
8461-
return isHLSLIntangibleType() || isa<HLSLAttributedResourceType>(this);
8463+
return isHLSLBuiltinIntangibleType() || isHLSLAttributedResourceType();
84628464
}
84638465

84648466
inline bool Type::isHLSLAttributedResourceType() const {

clang/include/clang/Sema/SemaHLSL.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ class SemaHLSL : public SemaBase {
132132

133133
// HLSL Type trait implementations
134134
bool IsScalarizedLayoutCompatible(QualType T1, QualType T2) const;
135-
bool IsIntangibleType(QualType T1);
136135

137136
bool CheckCompatibleParameterABI(FunctionDecl *New, FunctionDecl *Old);
138137

clang/lib/AST/DeclCXX.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1420,7 +1420,8 @@ void CXXRecordDecl::addedMember(Decl *D) {
14201420
if (const RecordType *RT = dyn_cast<RecordType>(Ty))
14211421
data().IsHLSLIntangible |= RT->getAsCXXRecordDecl()->isHLSLIntangible();
14221422
else
1423-
data().IsHLSLIntangible |= Ty->isHLSLIntangibleType();
1423+
data().IsHLSLIntangible |= (Ty->isHLSLAttributedResourceType() ||
1424+
Ty->isHLSLBuiltinIntangibleType());
14241425
}
14251426
}
14261427

clang/lib/AST/Type.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5030,6 +5030,29 @@ bool Type::hasSizedVLAType() const {
50305030
return false;
50315031
}
50325032

5033+
bool Type::isHLSLIntangibleType() const {
5034+
const Type *Ty = getUnqualifiedDesugaredType();
5035+
5036+
// check if it's a builtin type first
5037+
if (Ty->isBuiltinType())
5038+
return Ty->isHLSLBuiltinIntangibleType();
5039+
5040+
// unwrap arrays
5041+
while (isa<ConstantArrayType>(Ty))
5042+
Ty = Ty->getArrayElementTypeNoTypeQual();
5043+
5044+
const RecordType *RT =
5045+
dyn_cast<RecordType>(Ty->getUnqualifiedDesugaredType());
5046+
if (!RT)
5047+
return false;
5048+
5049+
CXXRecordDecl *RD = RT->getAsCXXRecordDecl();
5050+
assert(RD != nullptr &&
5051+
"all HLSL struct and classes should be CXXRecordDecl");
5052+
assert(RD->isCompleteDefinition() && "expecting complete type");
5053+
return RD->isHLSLIntangible();
5054+
}
5055+
50335056
QualType::DestructionKind QualType::isDestructedTypeImpl(QualType type) {
50345057
switch (type.getObjCLifetime()) {
50355058
case Qualifiers::OCL_None:

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5713,7 +5713,7 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait UTT,
57135713
if (DiagnoseVLAInCXXTypeTrait(Self, TInfo,
57145714
tok::kw___builtin_hlsl_is_intangible))
57155715
return false;
5716-
return Self.HLSL().IsIntangibleType(T);
5716+
return T->isHLSLIntangibleType();
57175717
}
57185718
}
57195719

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2104,32 +2104,6 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
21042104
return false;
21052105
}
21062106

2107-
bool SemaHLSL::IsIntangibleType(clang::QualType QT) {
2108-
if (QT.isNull())
2109-
return false;
2110-
2111-
const Type *Ty = QT->getUnqualifiedDesugaredType();
2112-
2113-
// check if it's a builtin type first (simple check, no need to cache it)
2114-
if (Ty->isBuiltinType())
2115-
return Ty->isHLSLIntangibleType();
2116-
2117-
// unwrap arrays
2118-
while (isa<ConstantArrayType>(Ty))
2119-
Ty = Ty->getArrayElementTypeNoTypeQual();
2120-
2121-
const RecordType *RT =
2122-
dyn_cast<RecordType>(Ty->getUnqualifiedDesugaredType());
2123-
if (!RT)
2124-
return false;
2125-
2126-
CXXRecordDecl *RD = RT->getAsCXXRecordDecl();
2127-
assert(RD != nullptr &&
2128-
"all HLSL struct and classes should be CXXRecordDecl");
2129-
assert(RD->isCompleteDefinition() && "expecting complete type");
2130-
return RD->isHLSLIntangible();
2131-
}
2132-
21332107
static void BuildFlattenedTypeList(QualType BaseTy,
21342108
llvm::SmallVectorImpl<QualType> &List) {
21352109
llvm::SmallVector<QualType, 16> WorkList;
@@ -2325,7 +2299,7 @@ void SemaHLSL::ActOnVariableDeclarator(VarDecl *VD) {
23252299
}
23262300

23272301
// find all resources on decl
2328-
if (IsIntangibleType(VD->getType()))
2302+
if (VD->getType()->isHLSLIntangibleType())
23292303
collectResourcesOnVarDecl(VD);
23302304

23312305
// process explicit bindings
@@ -2336,7 +2310,7 @@ void SemaHLSL::ActOnVariableDeclarator(VarDecl *VD) {
23362310
// Walks though the global variable declaration, collects all resource binding
23372311
// requirements and adds them to Bindings
23382312
void SemaHLSL::collectResourcesOnVarDecl(VarDecl *VD) {
2339-
assert(VD->hasGlobalStorage() && IsIntangibleType(VD->getType()) &&
2313+
assert(VD->hasGlobalStorage() && VD->getType()->isHLSLIntangibleType() &&
23402314
"expected global variable that contains HLSL resource");
23412315

23422316
// Cbuffers and Tbuffers are HLSLBufferDecl types

0 commit comments

Comments
 (0)