-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[HLSL][NFC] Move IsIntangibleType from SemaHLSL to Type to make it accessible outside of Sema #113206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…cessible 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.
@llvm/pr-subscribers-clang @llvm/pr-subscribers-hlsl Author: Helena Kotas (hekota) ChangesMoves This change makes Full diff: https://github.com/llvm/llvm-project/pull/113206.diff 6 Files Affected:
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
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little bit worried about how subtle the naming difference is from when we want to talk about if the builtin itself is intangible or if the type is transitively intangible, but that might just be because we're replacing one name with the other in this change and maybe it's not so bad in practice.
In any case, this change seems correct and indeed NFC. LG.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Moves
IsIntangibleType
from SemaHLSL to Type class and renames it toisHLSLIntangibleType
. The existingisHLSLIntangibleType
is renamed toisHLSLBuiltinIntangibleType
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.