[clang] cc47db6 - [HLSL] Add HLSLResource attribute
Chris Bieneman via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 28 19:14:53 PDT 2022
Author: Chris Bieneman
Date: 2022-07-28T20:54:51-05:00
New Revision: cc47db6737049f0c30e9c092de65e40823eb14be
URL: https://github.com/llvm/llvm-project/commit/cc47db6737049f0c30e9c092de65e40823eb14be
DIFF: https://github.com/llvm/llvm-project/commit/cc47db6737049f0c30e9c092de65e40823eb14be.diff
LOG: [HLSL] Add HLSLResource attribute
HLSL Resource objects will have restrictions on use and codegen
requirements. This patch is fairly minimal just adding the attribute
with no spellings since it will only be attached by the
HLSLExternalSemaSource.
Depends on D1300017.
Differential Revision: https://reviews.llvm.org/D130018
Added:
Modified:
clang/include/clang/Basic/Attr.td
clang/lib/Sema/HLSLExternalSemaSource.cpp
clang/test/AST/HLSL/RWBuffer-AST.hlsl
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td
index d61f3583281d..0460371d26c9 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4022,6 +4022,17 @@ def HLSLShader : InheritableAttr {
let Documentation = [HLSLSV_ShaderTypeAttrDocs];
}
+def HLSLResource : InheritableAttr {
+ let Spellings = [];
+ let Subjects = SubjectList<[Struct]>;
+ let LangOpts = [HLSL];
+ let Args = [EnumArgument<"ResourceType", "ResourceClass",
+ ["SRV", "UAV", "CBuffer", "Sampler"],
+ ["SRV", "UAV", "CBuffer", "Sampler"]
+ >];
+ let Documentation = [InternalOnly];
+}
+
def RandomizeLayout : InheritableAttr {
let Spellings = [GCC<"randomize_layout">];
let Subjects = SubjectList<[Record]>;
diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index 79f61c43ded4..fe963fdbf278 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -107,6 +107,13 @@ struct BuiltinTypeDeclBuilder {
return addMemberVariable("h", Record->getASTContext().VoidPtrTy, Access);
}
+ BuiltinTypeDeclBuilder &
+ annotateResourceClass(HLSLResourceAttr::ResourceClass RC) {
+ Record->addAttr(
+ HLSLResourceAttr::CreateImplicit(Record->getASTContext(), RC));
+ return *this;
+ }
+
static DeclRefExpr *lookupBuiltinFunction(ASTContext &AST, Sema &S,
StringRef Name) {
CXXScopeSpec SS;
@@ -361,5 +368,6 @@ void HLSLExternalSemaSource::completeBufferType(CXXRecordDecl *Record) {
BuiltinTypeDeclBuilder(Record)
.addHandleMember()
.addDefaultHandleConstructor(*SemaPtr, ResourceClass::UAV)
+ .annotateResourceClass(HLSLResourceAttr::UAV)
.completeDefinition();
}
diff --git a/clang/test/AST/HLSL/RWBuffer-AST.hlsl b/clang/test/AST/HLSL/RWBuffer-AST.hlsl
index 9d4fff346f79..c9cbd730933f 100644
--- a/clang/test/AST/HLSL/RWBuffer-AST.hlsl
+++ b/clang/test/AST/HLSL/RWBuffer-AST.hlsl
@@ -38,10 +38,12 @@ RWBuffer<float> Buffer;
// CHECK-NEXT: CXXRecordDecl 0x{{[0-9A-Fa-f]+}} <<invalid sloc>> <invalid sloc> implicit class RWBuffer definition
// CHECK: FinalAttr 0x{{[0-9A-Fa-f]+}} <<invalid sloc>> Implicit final
+// CHECK-NEXT: HLSLResourceAttr 0x{{[0-9A-Fa-f]+}} <<invalid sloc>> Implicit UAV
// CHECK-NEXT: FieldDecl 0x{{[0-9A-Fa-f]+}} <<invalid sloc>> <invalid sloc> implicit h 'void *'
// CHECK: ClassTemplateSpecializationDecl 0x{{[0-9A-Fa-f]+}} <<invalid sloc>> <invalid sloc> class RWBuffer definition
// CHECK: TemplateArgument type 'float'
// CHECK-NEXT: BuiltinType 0x{{[0-9A-Fa-f]+}} 'float'
// CHECK-NEXT: FinalAttr 0x{{[0-9A-Fa-f]+}} <<invalid sloc>> Implicit final
+// CHECK-NEXT: HLSLResourceAttr 0x{{[0-9A-Fa-f]+}} <<invalid sloc>> Implicit UAV
// CHECK-NEXT: FieldDecl 0x{{[0-9A-Fa-f]+}} <<invalid sloc>> <invalid sloc> implicit referenced h 'void *'
More information about the cfe-commits
mailing list