clang: lib/Sema/HLSLExternalSemaSource.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
24#include "llvm/ADT/SmallVector.h"
25
26using namespace clang;
27using namespace llvm::hlsl;
28
30
32 SemaPtr = &S;
33 ASTContext &AST = SemaPtr->getASTContext();
34
37
46 HLSLNamespace->setImplicit(true);
47 HLSLNamespace->setHasExternalLexicalStorage();
49
50
51 (void)HLSLNamespace->getCanonicalDecl()->decls_begin();
52 defineTrivialHLSLTypes();
53 defineHLSLTypesWithForwardDeclarations();
54
55
56
57
58
59
60
65
67}
68
69void HLSLExternalSemaSource::defineHLSLVectorAlias() {
71
73
76 &AST.Idents.get("element", tok::TokenKind::identifier), false, false);
77 TypeParam->setDefaultArgument(
80
81 TemplateParams.emplace_back(TypeParam);
82
85 &AST.Idents.get("element_count", tok::TokenKind::identifier), AST.IntTy,
89 true);
90 SizeParam->setDefaultArgument(
93 TemplateParams.emplace_back(SizeParam);
94
95 auto *ParamList =
98
100
108
112 Record->setImplicit(true);
113
117
120 Template->setLexicalDeclContext(Record->getDeclContext());
122}
123
124void HLSLExternalSemaSource::defineHLSLMatrixAlias() {
127
130 &AST.Idents.get("element", tok::TokenKind::identifier), false, false);
131 TypeParam->setDefaultArgument(
134
135 TemplateParams.emplace_back(TypeParam);
136
137
140 &AST.Idents.get("rows_count", tok::TokenKind::identifier), AST.IntTy,
144 true);
145 RowsParam->setDefaultArgument(
148 TemplateParams.emplace_back(RowsParam);
149
152 &AST.Idents.get("cols_count", tok::TokenKind::identifier), AST.IntTy,
156 true);
157 ColsParam->setDefaultArgument(
160 TemplateParams.emplace_back(ColsParam);
161
162 const unsigned MaxMatDim = SemaPtr->getLangOpts().MaxMatrixDimension;
163
170
173 false,
178 false,
181
188
192
196
198
210
214 Record->setImplicit(true);
215
219
222 Template->setLexicalDeclContext(Record->getDeclContext());
224}
225
226void HLSLExternalSemaSource::defineTrivialHLSLTypes() {
227 defineHLSLVectorAlias();
228 defineHLSLMatrixAlias();
229}
230
231
234 bool RawBuffer, bool HasCounter) {
241}
242
243
244
245
246
250
251
252 QualType BoolTy = Context.BoolTy;
253
254
255 QualType TType = Context.getTypeDeclType(T);
256
257
259 Context.getTrivialTypeSourceInfo(TType, NameLoc);
260
262 Context, BoolTy, NameLoc, UTT_IsTypedResourceElementCompatible,
263 {TTypeSourceInfo}, NameLoc, true);
264
265 return TypedResExpr;
266}
267
268
269
270
271
276
277
278 QualType BoolTy = Context.BoolTy;
279
280
281 QualType TType = Context.getTypeDeclType(T);
282
283
285 Context.getTrivialTypeSourceInfo(TType, NameLoc);
286
289 {TTypeSourceInfo}, NameLoc, true);
290
291
295
296
298 UETT_SizeOf, TTypeSourceInfo, BoolTy, NameLoc, NameLoc);
299
300
301
303 Context, llvm::APInt(Context.getTypeSize(Context.getSizeType()), 1, true),
304 Context.getSizeType(), NameLoc);
305
309
310
312 Context, NotIntangibleExpr, SizeGEQOneExpr, BO_LAnd, BoolTy, VK_LValue,
314
315 return CombinedExpr;
316}
317
319 bool isTypedBuffer) {
323
324 IdentifierInfo &ElementTypeII = Context.Idents.get("element_type");
327 0,
328 0,
329 &ElementTypeII,
330 true,
331 false);
332
333 T->setDeclContext(DC);
334 T->setReferenced();
335
336
338 Context, DeclLoc, DeclLoc, {T}, DeclLoc, nullptr);
339
341 Expr *ConstraintExpr = nullptr;
342
343 if (isTypedBuffer) {
345 &Context.Idents.get("__is_typed_resource_element_compatible"));
347 } else {
349 &Context.Idents.get("__is_structured_resource_element_compatible"));
351 }
352
353
356 ConceptParams, ConstraintExpr);
357
358
360
361
363
364 return CD;
365}
366
367void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
368 CXXRecordDecl *Decl;
370 *SemaPtr, HLSLNamespace, true);
372 *SemaPtr, HLSLNamespace, false);
373
374 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "Buffer")
375 .addSimpleTemplateParams({"element_type"}, TypedBufferConcept)
376 .finalizeForwardDeclaration();
377
378 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
379 setupBufferType(Decl, *SemaPtr, ResourceClass::SRV, false,
380 false, false)
385 });
386
387 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "RWBuffer")
388 .addSimpleTemplateParams({"element_type"}, TypedBufferConcept)
389 .finalizeForwardDeclaration();
390
391 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
392 setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, false,
393 false, false)
398 });
399
401 BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "RasterizerOrderedBuffer")
402 .addSimpleTemplateParams({"element_type"}, StructuredBufferConcept)
403 .finalizeForwardDeclaration();
404 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
405 setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, true,
406 false, false)
411 });
412
413 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "StructuredBuffer")
414 .addSimpleTemplateParams({"element_type"}, StructuredBufferConcept)
415 .finalizeForwardDeclaration();
416 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
417 setupBufferType(Decl, *SemaPtr, ResourceClass::SRV, false,
418 true, false)
423 });
424
425 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "RWStructuredBuffer")
426 .addSimpleTemplateParams({"element_type"}, StructuredBufferConcept)
427 .finalizeForwardDeclaration();
428 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
429 setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, false,
430 true, true)
437 });
438
440 BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "AppendStructuredBuffer")
441 .addSimpleTemplateParams({"element_type"}, StructuredBufferConcept)
442 .finalizeForwardDeclaration();
443 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
444 setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, false,
445 true, true)
449 });
450
452 BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "ConsumeStructuredBuffer")
453 .addSimpleTemplateParams({"element_type"}, StructuredBufferConcept)
454 .finalizeForwardDeclaration();
455 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
456 setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, false,
457 true, true)
461 });
462
463 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace,
464 "RasterizerOrderedStructuredBuffer")
465 .addSimpleTemplateParams({"element_type"}, StructuredBufferConcept)
466 .finalizeForwardDeclaration();
467 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
468 setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, true,
469 true, true)
476 });
477
478 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "ByteAddressBuffer")
479 .finalizeForwardDeclaration();
480 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
481 setupBufferType(Decl, *SemaPtr, ResourceClass::SRV, false,
482 true, false)
485 });
486 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "RWByteAddressBuffer")
487 .finalizeForwardDeclaration();
488 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
489 setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, false,
490 true, false)
493 });
494 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace,
495 "RasterizerOrderedByteAddressBuffer")
496 .finalizeForwardDeclaration();
497 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
498 setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, true,
499 true, false)
502 });
503}
504
506 CompletionFunction Fn) {
507 if (->isCompleteDefinition())
508 Completions.insert(std::make_pair(Record->getCanonicalDecl(), Fn));
509}
510
513 return;
515
516
517
518 if (auto TDecl = dyn_cast(Record))
519 Record = TDecl->getSpecializedTemplate()->getTemplatedDecl();
521 auto It = Completions.find(Record);
522 if (It == Completions.end())
523 return;
525}
Defines the clang::ASTContext interface.
llvm::dxil::ResourceClass ResourceClass
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S, ResourceClass RC, bool IsROV, bool RawBuffer, bool HasCounter)
Set up common members and attributes for buffer types.
Definition HLSLExternalSemaSource.cpp:232
static ConceptDecl * constructBufferConceptDecl(Sema &S, NamespaceDecl *NSD, bool isTypedBuffer)
Definition HLSLExternalSemaSource.cpp:318
static Expr * constructTypedBufferConstraintExpr(Sema &S, SourceLocation NameLoc, TemplateTypeParmDecl *T)
Definition HLSLExternalSemaSource.cpp:247
static Expr * constructStructuredBufferConstraintExpr(Sema &S, SourceLocation NameLoc, TemplateTypeParmDecl *T)
Definition HLSLExternalSemaSource.cpp:272
llvm::MachO::Record Record
This file declares semantic analysis for HLSL constructs.
Defines the clang::SourceLocation class and associated facilities.
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
TranslationUnitDecl * getTranslationUnitDecl() const
QualType getDependentSizedMatrixType(QualType ElementType, Expr *RowExpr, Expr *ColumnExpr, SourceLocation AttrLoc) const
Return the unique reference to the matrix type of the specified element type and size.
unsigned getIntWidth(QualType T) const
QualType getTemplateTypeParmType(unsigned Depth, unsigned Index, bool ParameterPack, TemplateTypeParmDecl *ParmDecl=nullptr) const
Retrieve the template type parameter type for a template parameter or parameter pack with the given d...
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
QualType getDependentSizedExtVectorType(QualType VectorType, Expr *SizeExpr, SourceLocation AttrLoc) const
A builtin binary operation expression such as "x + y" or "x <= y".
static BinaryOperator * Create(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, FPOptionsOverride FPFeatures)
Represents a C++ struct/union/class.
Declaration of a C++20 concept.
static ConceptDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, Expr *ConstraintExpr=nullptr)
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
void addDecl(Decl *D)
Add the declaration D into this context.
bool hasExternalLexicalStorage() const
Whether this DeclContext has external storage containing additional declarations that are lexically i...
decl_iterator decls_begin() const
static DeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *D, bool RefersToEnclosingVariableOrCapture, SourceLocation NameLoc, QualType T, ExprValueKind VK, NamedDecl *FoundD=nullptr, const TemplateArgumentListInfo *TemplateArgs=nullptr, NonOdrUseReason NOUR=NOUR_None)
Decl - This represents one declaration (or definition), e.g.
DeclContext * getDeclContext()
The name of a declaration.
This represents one expression.
Represents difference between two FPOptions values.
void CompleteType(TagDecl *Tag) override
Complete an incomplete HLSL builtin type.
Definition HLSLExternalSemaSource.cpp:511
void InitializeSema(Sema &S) override
Initialize the semantic source with the Sema instance being used to perform semantic analysis on the ...
Definition HLSLExternalSemaSource.cpp:31
One of these records is kept for each identifier that is lexed.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value 'V' and type 'type'.
Represents the results of name lookup.
Represent a C++ namespace.
static NamespaceDecl * Create(ASTContext &C, DeclContext *DC, bool Inline, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, NamespaceDecl *PrevDecl, bool Nested)
A C++ nested-name-specifier augmented with source location information.
static NonTypeTemplateParmDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, unsigned D, unsigned P, const IdentifierInfo *Id, QualType T, bool ParameterPack, TypeSourceInfo *TInfo)
A (possibly-)qualified type.
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
Sema - This implements semantic analysis and AST building for C.
TemplateArgumentLoc getTrivialTemplateArgumentLoc(const TemplateArgument &Arg, QualType NTTPType, SourceLocation Loc, NamedDecl *TemplateParam=nullptr)
Allocate a TemplateArgumentLoc where all locations have been initialized to the given location.
@ LookupNamespaceName
Look up a namespace name within a C++ using directive or namespace alias definition,...
ASTContext & getASTContext() const
const LangOptions & getLangOpts() const
bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, bool InUnqualifiedLookup=false)
Perform qualified name lookup into a given context.
Encodes a location in the source.
Represents the declaration of a struct/union/class/enum.
Represents a template argument.
void setTemplateParameters(TemplateParameterList *TParams)
Stores a list of template parameters for a TemplateDecl and its derived classes.
static TemplateParameterList * Create(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl * > Params, SourceLocation RAngleLoc, Expr *RequiresClause)
Declaration of a template type parameter.
static TemplateTypeParmDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation KeyLoc, SourceLocation NameLoc, unsigned D, unsigned P, IdentifierInfo *Id, bool Typename, bool ParameterPack, bool HasTypeConstraint=false, UnsignedOrNone NumExpanded=std::nullopt)
static TypeAliasDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, TypeSourceInfo *TInfo)
static TypeAliasTemplateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
Create a function template node.
A container of type source information.
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
static TypeTraitExpr * Create(const ASTContext &C, QualType T, SourceLocation Loc, TypeTrait Kind, ArrayRef< TypeSourceInfo * > Args, SourceLocation RParenLoc, bool Value)
Create a new type trait expression.
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
static UnaryOperator * Create(const ASTContext &C, Expr *input, Opcode opc, QualType type, ExprValueKind VK, ExprObjectKind OK, SourceLocation l, bool CanOverflow, FPOptionsOverride FPFeatures)
Represents a C++ using-declaration.
static UsingDirectiveDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, SourceLocation NamespaceLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation IdentLoc, NamedDecl *Nominated, DeclContext *CommonAncestor)
BuiltinTypeDeclBuilder & addConsumeMethod()
BuiltinTypeDeclBuilder & addGetDimensionsMethodForBuffer()
BuiltinTypeDeclBuilder & addArraySubscriptOperators()
BuiltinTypeDeclBuilder & completeDefinition()
BuiltinTypeDeclBuilder & addBufferHandles(ResourceClass RC, bool IsROV, bool RawBuffer, bool HasCounter, AccessSpecifier Access=AccessSpecifier::AS_private)
BuiltinTypeDeclBuilder & addAppendMethod()
BuiltinTypeDeclBuilder & addIncrementCounterMethod()
BuiltinTypeDeclBuilder & addCopyAssignmentOperator()
BuiltinTypeDeclBuilder & addCopyConstructor()
BuiltinTypeDeclBuilder & addStaticInitializationFunctions(bool HasCounter)
BuiltinTypeDeclBuilder & addDefaultHandleConstructor()
BuiltinTypeDeclBuilder & addDecrementCounterMethod()
BuiltinTypeDeclBuilder & addLoadMethods()
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
@ OK_Ordinary
An ordinary object is located at an address in memory.
@ Result
The result type of a method or function.
const FunctionProtoType * T
@ Template
We are parsing a template declaration.
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
U cast(CodeGen::Address addr)
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...