[clang] [HLSL][NFC] Move IsIntangibleType from SemaHLSL to Type to make it accessible outside of Sema (PR #113206)
Helena Kotas via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 21 12:21:01 PDT 2024
https://github.com/hekota created https://github.com/llvm/llvm-project/pull/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.
>From ae8b3c909231915f87631665b06321a9f9baff33 Mon Sep 17 00:00:00 2001
From: Helena Kotas <hekotas at microsoft.com>
Date: Mon, 21 Oct 2024 12:17:58 -0700
Subject: [PATCH] [HLSL][NFC] Move IsIntangibleType from SemaHLSL to Type to
make it accessible outside of Sema
Moves `IsIntangibleType` from SemaHLSL to Type class and renames it to `isHLSLIntangibleType`.
The existing `isHLSLIntangibleType` is renamed to `isHLSLBuiltinIntangibleType` to reflect that
it returns true only for the builtin `__hlsl_resource_t` type.
This change makes isHLSLIntangibleType accesible outside of Sema, for example from CodeGen,
which will be needed in the future.
---
clang/include/clang/AST/Type.h | 10 ++++++----
clang/include/clang/Sema/SemaHLSL.h | 1 -
clang/lib/AST/DeclCXX.cpp | 3 ++-
clang/lib/AST/Type.cpp | 23 ++++++++++++++++++++++
clang/lib/Sema/SemaExprCXX.cpp | 2 +-
clang/lib/Sema/SemaHLSL.cpp | 30 ++---------------------------
6 files changed, 34 insertions(+), 35 deletions(-)
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 40e617bf8f3b8d..ba3161c366f4d9 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2661,8 +2661,10 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) bool is##Id##Type() const;
#include "clang/Basic/HLSLIntangibleTypes.def"
bool isHLSLSpecificType() const; // Any HLSL specific type
- bool isHLSLIntangibleType() const; // Any HLSL intangible type
+ bool isHLSLBuiltinIntangibleType() const; // Any HLSL builtin intangible type
bool isHLSLAttributedResourceType() const;
+ bool isHLSLIntangibleType()
+ const; // Any HLSL intangible type (builtin, array, class)
/// Determines if this type, which must satisfy
/// isObjCLifetimeType(), is implicitly __unsafe_unretained rather
@@ -8450,15 +8452,15 @@ inline bool Type::isOpenCLSpecificType() const {
}
#include "clang/Basic/HLSLIntangibleTypes.def"
-inline bool Type::isHLSLIntangibleType() const {
+inline bool Type::isHLSLBuiltinIntangibleType() const {
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) is##Id##Type() ||
return
#include "clang/Basic/HLSLIntangibleTypes.def"
- isHLSLAttributedResourceType();
+ false;
}
inline bool Type::isHLSLSpecificType() const {
- return isHLSLIntangibleType() || isa<HLSLAttributedResourceType>(this);
+ return isHLSLBuiltinIntangibleType() || isHLSLAttributedResourceType();
}
inline bool Type::isHLSLAttributedResourceType() const {
diff --git a/clang/include/clang/Sema/SemaHLSL.h b/clang/include/clang/Sema/SemaHLSL.h
index 4f1fc9a31404c6..e30acd87f77218 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -132,7 +132,6 @@ class SemaHLSL : public SemaBase {
// HLSL Type trait implementations
bool IsScalarizedLayoutCompatible(QualType T1, QualType T2) const;
- bool IsIntangibleType(QualType T1);
bool CheckCompatibleParameterABI(FunctionDecl *New, FunctionDecl *Old);
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 08615d4393f5d1..576aa969cb55d6 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -1414,7 +1414,8 @@ void CXXRecordDecl::addedMember(Decl *D) {
if (const RecordType *RT = dyn_cast<RecordType>(Ty))
data().IsHLSLIntangible |= RT->getAsCXXRecordDecl()->isHLSLIntangible();
else
- data().IsHLSLIntangible |= Ty->isHLSLIntangibleType();
+ data().IsHLSLIntangible |= (Ty->isHLSLAttributedResourceType() ||
+ Ty->isHLSLBuiltinIntangibleType());
}
}
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 5232efae4e3630..5b2b1e5f3ca498 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -5030,6 +5030,29 @@ bool Type::hasSizedVLAType() const {
return false;
}
+bool Type::isHLSLIntangibleType() const {
+ const Type *Ty = getUnqualifiedDesugaredType();
+
+ // check if it's a builtin type first (simple check, no need to cache it)
+ if (Ty->isBuiltinType())
+ return Ty->isHLSLBuiltinIntangibleType();
+
+ // unwrap arrays
+ while (isa<ConstantArrayType>(Ty))
+ Ty = Ty->getArrayElementTypeNoTypeQual();
+
+ const RecordType *RT =
+ dyn_cast<RecordType>(Ty->getUnqualifiedDesugaredType());
+ if (!RT)
+ return false;
+
+ CXXRecordDecl *RD = RT->getAsCXXRecordDecl();
+ assert(RD != nullptr &&
+ "all HLSL struct and classes should be CXXRecordDecl");
+ assert(RD->isCompleteDefinition() && "expecting complete type");
+ return RD->isHLSLIntangible();
+}
+
QualType::DestructionKind QualType::isDestructedTypeImpl(QualType type) {
switch (type.getObjCLifetime()) {
case Qualifiers::OCL_None:
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 40f24ea0ab2eaa..7075a35a314790 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5713,7 +5713,7 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait UTT,
if (DiagnoseVLAInCXXTypeTrait(Self, TInfo,
tok::kw___builtin_hlsl_is_intangible))
return false;
- return Self.HLSL().IsIntangibleType(T);
+ return T->isHLSLIntangibleType();
}
}
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index c6627b0e993226..1f6c5b8d4561bc 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -2104,32 +2104,6 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
return false;
}
-bool SemaHLSL::IsIntangibleType(clang::QualType QT) {
- if (QT.isNull())
- return false;
-
- const Type *Ty = QT->getUnqualifiedDesugaredType();
-
- // check if it's a builtin type first (simple check, no need to cache it)
- if (Ty->isBuiltinType())
- return Ty->isHLSLIntangibleType();
-
- // unwrap arrays
- while (isa<ConstantArrayType>(Ty))
- Ty = Ty->getArrayElementTypeNoTypeQual();
-
- const RecordType *RT =
- dyn_cast<RecordType>(Ty->getUnqualifiedDesugaredType());
- if (!RT)
- return false;
-
- CXXRecordDecl *RD = RT->getAsCXXRecordDecl();
- assert(RD != nullptr &&
- "all HLSL struct and classes should be CXXRecordDecl");
- assert(RD->isCompleteDefinition() && "expecting complete type");
- return RD->isHLSLIntangible();
-}
-
static void BuildFlattenedTypeList(QualType BaseTy,
llvm::SmallVectorImpl<QualType> &List) {
llvm::SmallVector<QualType, 16> WorkList;
@@ -2325,7 +2299,7 @@ void SemaHLSL::ActOnVariableDeclarator(VarDecl *VD) {
}
// find all resources on decl
- if (IsIntangibleType(VD->getType()))
+ if (VD->getType()->isHLSLIntangibleType())
collectResourcesOnVarDecl(VD);
// process explicit bindings
@@ -2336,7 +2310,7 @@ void SemaHLSL::ActOnVariableDeclarator(VarDecl *VD) {
// Walks though the global variable declaration, collects all resource binding
// requirements and adds them to Bindings
void SemaHLSL::collectResourcesOnVarDecl(VarDecl *VD) {
- assert(VD->hasGlobalStorage() && IsIntangibleType(VD->getType()) &&
+ assert(VD->hasGlobalStorage() && VD->getType()->isHLSLIntangibleType() &&
"expected global variable that contains HLSL resource");
// Cbuffers and Tbuffers are HLSLBufferDecl types
More information about the cfe-commits
mailing list