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
105
106 // Static create methods
108
109 // Builtin types methods
112 bool IsArray = false);
114 bool IsArray = false);
116 bool IsArray = false);
121 bool IsArray = false);
123 bool IsArray = false);
125 bool IsArray = false);
127 bool IsArray = false);
129 bool IsArray = false);
131 bool IsArray = false);
134 bool IsArray = false);
136 bool IsArray = false);
140 bool IsConstReturn,
141 bool IsRef, QualType IndexTy,
142 QualType ElemTy = QualType(),
143 bool TransposeResult = false);
146 QualType ReturnTy = QualType());
148 QualType ValueType,
149 bool TransposeArg = false);
151 addByteAddressBufferInterlockedMethod(StringRef MethodName, QualType ValueTy,
152 StringRef BuiltinName);
155
158 BuiltinTypeDeclBuilder &addMipsMember(ResourceDimension Dim);
159
160private:
161 BuiltinTypeDeclBuilder &addCreateFromBinding();
162 BuiltinTypeDeclBuilder &addCreateFromImplicitBinding();
163 BuiltinTypeDeclBuilder &addCreateFromBindingWithImplicitCounter();
164 BuiltinTypeDeclBuilder &addCreateFromImplicitBindingWithImplicitCounter();
166 addResourceMember(StringRef MemberName, ResourceClass RC,
167 ResourceDimension RD, bool IsROV, bool RawBuffer,
168 bool IsCounter, bool IsArray, QualType ElementTy,
169 Expr *SampleCountExpr = nullptr,
172 CXXRecordDecl *addPrivateNestedRecord(StringRef Name);
173 CXXRecordDecl *addMipsSliceType(ResourceDimension Dim, QualType ReturnType);
174 CXXRecordDecl *addMipsType(ResourceDimension Dim, QualType ReturnType);
176 addHandleMember(ResourceClass RC, ResourceDimension RD, bool IsROV,
177 bool RawBuffer, bool IsArray, QualType ElementTy,
180 addCounterHandleMember(ResourceClass RC, bool IsROV, bool RawBuffer,
181 QualType ElementTy,
183 QualType getGatherReturnType();
184 BuiltinTypeDeclBuilder &addDerivativeAvailability(StringRef MethodName);
185 FieldDecl *getResourceHandleField() const;
186 FieldDecl *getResourceCounterHandleField() const;
187 QualType getFirstTemplateTypeParam();
188 QualType getHandleElementType();
189 Expr *getConstantIntExpr(int value);
190 Expr *getConstantUnsignedIntExpr(unsigned value);
191 HLSLAttributedResourceType::Attributes getResourceAttrs() const;
192};
193
194} // namespace hlsl
195
196} // namespace clang
197
198#endif // LLVM_CLANG_SEMA_HLSLBUILTINTYPEDECLBUILDER_H
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:3295
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 & addByteAddressBufferInterlockedMethod(StringRef MethodName, QualType ValueTy, StringRef BuiltinName)
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 & addLoadWithStatusFunction(DeclarationName &Name, QualType ReturnTy=QualType())
BuiltinTypeDeclBuilder & addSampleCmpMethods(ResourceDimension Dim, bool IsArray=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:124
@ AS_public
Definition Specifiers.h:125
@ AS_private
Definition Specifiers.h:127