clang 24.0.0git
HLSLBuiltinTypeDeclBuilder.h
Go to the documentation of this file.
1//===--- HLSLBuiltinTypeDeclBuilder.h - HLSL Builtin Type Decl Builder ---===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Helper classes for creating HLSL builtin class types. Used by external HLSL
10// sema source.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_SEMA_HLSLBUILTINTYPEDECLBUILDER_H
15#define LLVM_CLANG_SEMA_HLSLBUILTINTYPEDECLBUILDER_H
16
17#include "clang/AST/Type.h"
18#include "clang/Sema/Sema.h"
19#include "llvm/ADT/StringMap.h"
20
21using llvm::hlsl::ResourceClass;
22using llvm::hlsl::ResourceDimension;
23
24namespace clang {
25
27class NamespaceDecl;
28class CXXRecordDecl;
29class FieldDecl;
30
31namespace hlsl {
32
33// Builder for builtin HLSL class types such as HLSL resource classes.
34// Allows creating declaration of builtin types using the builder pattern
35// like this:
36//
37// Decl = BuiltinTypeDeclBuilder(Sema, Namespace, "BuiltinClassName")
38// .addSimpleTemplateParams({"T"}, Concept)
39// .finalizeForwardDeclaration();
40//
41// And then completing the type like this:
42//
43// BuiltinTypeDeclBuilder(Sema, Decl)
44// .addDefaultHandleConstructor();
45// .addLoadMethods()
46// .completeDefinition();
47//
49private:
50 Sema &SemaRef;
51 CXXRecordDecl *Record = nullptr;
52 ClassTemplateDecl *Template = nullptr;
53 ClassTemplateDecl *PrevTemplate = nullptr;
54 NamespaceDecl *HLSLNamespace = nullptr;
55 llvm::StringMap<FieldDecl *> Fields;
56
57public:
60
62 BuiltinTypeDeclBuilder(Sema &SemaRef, NamespaceDecl *Namespace,
63 StringRef Name);
65
67 ConceptDecl *CD = nullptr);
70 ArrayRef<QualType> DefaultTypes, ConceptDecl *CD);
71 // Adds `<typename element_type, int sample_count = 0>` for multisampled
72 // textures, with \p CD constraining the element type. Unlike the other
73 // textures the element type has no default argument.
75 StringRef SampleCountName,
76 ConceptDecl *CD);
79
83
85 addBufferHandles(ResourceClass RC, bool IsROV, bool RawBuffer,
86 bool HasCounter,
89 addTextureHandle(ResourceClass RC, bool IsROV, bool IsArray,
90 ResourceDimension RD, Expr *SampleCountExpr = nullptr,
95 addArraySubscriptOperators(ResourceDimension Dim = ResourceDimension::Unknown,
96 bool IsArray = false);
97
98 // Builtin types constructors
102 addHeapResourceInfoConstructor(bool HasCounter = false);
108
109 // Static create methods
111
112 // Builtin types methods
115 bool IsArray = false);
117 bool IsArray = false);
119 bool IsArray = false);
124 bool IsArray = false);
126 bool IsArray = false);
128 bool IsArray = false);
130 bool IsArray = false);
132 bool IsArray = false);
134 bool IsArray = false);
137 bool IsArray = false);
139 bool IsArray = false);
143 bool IsConstReturn,
144 bool IsRef, QualType IndexTy,
145 QualType ElemTy = QualType(),
146 bool TransposeResult = false);
149 QualType ReturnTy = QualType());
151 QualType ValueType,
152 bool TransposeArg = false);
154 addByteAddressBufferInterlockedMethod(StringRef MethodName, QualType ValueTy,
155 StringRef BuiltinName,
156 bool RequiresOriginalValue = false);
158 StringRef MethodName, QualType ValueTy, StringRef BuiltinName,
159 bool WithOriginalValue = false);
162
165 BuiltinTypeDeclBuilder &addMipsMember(ResourceDimension Dim);
166
167private:
168 BuiltinTypeDeclBuilder &addCreateFromBinding();
169 BuiltinTypeDeclBuilder &addCreateFromImplicitBinding();
170 BuiltinTypeDeclBuilder &addCreateFromBindingWithImplicitCounter();
171 BuiltinTypeDeclBuilder &addCreateFromImplicitBindingWithImplicitCounter();
173 addResourceMember(StringRef MemberName, ResourceClass RC,
174 ResourceDimension RD, bool IsROV, bool RawBuffer,
175 bool IsCounter, bool IsArray, QualType ElementTy,
176 Expr *SampleCountExpr = nullptr,
179 CXXRecordDecl *addPrivateNestedRecord(StringRef Name);
180 CXXRecordDecl *addMipsSliceType(ResourceDimension Dim, QualType ReturnType);
181 CXXRecordDecl *addMipsType(ResourceDimension Dim, QualType ReturnType);
183 addHandleMember(ResourceClass RC, ResourceDimension RD, bool IsROV,
184 bool RawBuffer, bool IsArray, QualType ElementTy,
187 addCounterHandleMember(ResourceClass RC, bool IsROV, bool RawBuffer,
188 QualType ElementTy,
190 QualType getGatherReturnType();
191 BuiltinTypeDeclBuilder &addDerivativeAvailability(StringRef MethodName);
193 FieldDecl *getResourceCounterHandleField() const;
194 QualType getFirstTemplateTypeParam();
195 QualType getHandleElementType();
196 Expr *getConstantIntExpr(int value);
197 Expr *getConstantUnsignedIntExpr(unsigned value);
198 HLSLAttributedResourceType::Attributes getResourceAttrs() const;
199};
200
201} // namespace hlsl
202
203} // namespace clang
204
205#endif // LLVM_CLANG_SEMA_HLSLBUILTINTYPEDECLBUILDER_H
static const FieldDecl * getResourceHandleField(QualType ResourceTy)
llvm::dxil::ResourceClass ResourceClass
C Language Family Type Representation.
BuiltinTypeDeclBuilder(Sema &SemaRef, CXXRecordDecl *R)
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
Declaration of a class template.
Declaration of a C++20 concept.
The name of a declaration.
This represents one expression.
Definition Expr.h:113
Represents a member of a struct/union/class.
Definition Decl.h:3299
Represent a C++ namespace.
Definition Decl.h:593
A (possibly-)qualified type.
Definition TypeBase.h:938
Sema - This implements semantic analysis and AST building for C.
Definition Sema.h:863
The base class of the type hierarchy.
Definition TypeBase.h:1879
BuiltinTypeDeclBuilder & addMSTextureTemplateParams(StringRef ElementName, StringRef SampleCountName, ConceptDecl *CD)
BuiltinTypeDeclBuilder & addRWTextureLoadMethods(ResourceDimension Dim, bool IsArray=false)
BuiltinTypeDeclBuilder & addDefaultHandleConstructor(AccessSpecifier Access=AccessSpecifier::AS_public)
BuiltinTypeDeclBuilder(Sema &SemaRef, CXXRecordDecl *R)
BuiltinTypeDeclBuilder & addMemberVariable(StringRef Name, QualType Type, llvm::ArrayRef< Attr * > Attrs, AccessSpecifier Access=AccessSpecifier::AS_private)
BuiltinTypeDeclBuilder & addSampleGradMethods(ResourceDimension Dim, bool IsArray=false)
BuiltinTypeDeclBuilder & addCopyAssignmentOperator(AccessSpecifier Access=AccessSpecifier::AS_public)
BuiltinTypeDeclBuilder & addGatherCmpMethods(ResourceDimension Dim, bool IsArray=false)
BuiltinTypeDeclBuilder & addStoreFunction(DeclarationName &Name, bool IsConst, QualType ValueType, bool TransposeArg=false)
BuiltinTypeDeclBuilder & addGetDimensionsMethodForBuffer()
BuiltinTypeDeclBuilder & addTextureLoadMSMethods(ResourceDimension Dim, bool IsArray=false)
BuiltinTypeDeclBuilder & addConstantBufferConversionToType()
BuiltinTypeDeclBuilder & addTextureLoadMethods(ResourceDimension Dim, bool IsArray=false)
BuiltinTypeDeclBuilder & addSampleBiasMethods(ResourceDimension Dim, bool IsArray=false)
BuiltinTypeDeclBuilder & addBufferHandles(ResourceClass RC, bool IsROV, bool RawBuffer, bool HasCounter, AccessSpecifier Access=AccessSpecifier::AS_private)
BuiltinTypeDeclBuilder & addByteAddressBufferStoreMethods()
BuiltinTypeDeclBuilder & addSampleMethods(ResourceDimension Dim, bool IsArray=false)
BuiltinTypeDeclBuilder & addArraySubscriptOperators(ResourceDimension Dim=ResourceDimension::Unknown, bool IsArray=false)
BuiltinTypeDeclBuilder & addSampleLevelMethods(ResourceDimension Dim, bool IsArray=false)
BuiltinTypeDeclBuilder & addCopyConstructor(AccessSpecifier Access=AccessSpecifier::AS_public)
BuiltinTypeDeclBuilder & addHandleAccessFunction(DeclarationName &Name, bool IsConstReturn, bool IsRef, QualType IndexTy, QualType ElemTy=QualType(), bool TransposeResult=false)
BuiltinTypeDeclBuilder & addHeapResourceInfoConstructor(bool HasCounter=false)
BuiltinTypeDeclBuilder & addByteAddressBufferInterlockedMethod(StringRef MethodName, QualType ValueTy, StringRef BuiltinName, bool RequiresOriginalValue=false)
BuiltinTypeDeclBuilder & addLoadWithStatusFunction(DeclarationName &Name, QualType ReturnTy=QualType())
BuiltinTypeDeclBuilder & addSampleCmpMethods(ResourceDimension Dim, bool IsArray=false)
BuiltinTypeDeclBuilder & addByteAddressBufferInterlockedCompareMethod(StringRef MethodName, QualType ValueTy, StringRef BuiltinName, bool WithOriginalValue=false)
BuiltinTypeDeclBuilder & addMipsMember(ResourceDimension Dim)
BuiltinTypeDeclBuilder & addByteAddressBufferLoadMethods()
BuiltinTypeDeclBuilder & addStaticInitializationFunctions(bool HasCounter)
BuiltinTypeDeclBuilder & addGatherMethods(ResourceDimension Dim, bool IsArray=false)
BuiltinTypeDeclBuilder & addCalculateLodMethods(ResourceDimension Dim)
BuiltinTypeDeclBuilder & addGetDimensionsMethods(ResourceDimension Dim)
BuiltinTypeDeclBuilder & addByteAddressBufferInterlockedMethods()
BuiltinTypeDeclBuilder & addSimpleTemplateParams(ArrayRef< StringRef > Names, ConceptDecl *CD=nullptr)
BuiltinTypeDeclBuilder & addTextureHandle(ResourceClass RC, bool IsROV, bool IsArray, ResourceDimension RD, Expr *SampleCountExpr=nullptr, AccessSpecifier Access=AccessSpecifier::AS_private)
BuiltinTypeDeclBuilder & addSampleCmpLevelZeroMethods(ResourceDimension Dim, bool IsArray=false)
Top level wrappers for InstallAPI frontend operations.
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Definition Specifiers.h:127
@ AS_public
Definition Specifiers.h:128
@ AS_private
Definition Specifiers.h:130