clang 24.0.0git
HLSLExternalSemaSource.cpp
Go to the documentation of this file.
1//===--- HLSLExternalSemaSource.cpp - HLSL Sema Source --------------------===//
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//
10//===----------------------------------------------------------------------===//
11
15#include "clang/AST/Attr.h"
16#include "clang/AST/Decl.h"
17#include "clang/AST/DeclCXX.h"
19#include "clang/AST/Expr.h"
20#include "clang/AST/Type.h"
24#include "clang/Sema/Lookup.h"
25#include "clang/Sema/Sema.h"
26#include "clang/Sema/SemaHLSL.h"
27#include "llvm/ADT/BitmaskEnum.h"
28#include "llvm/ADT/STLExtras.h"
29#include "llvm/ADT/SmallVector.h"
30
31using namespace clang;
32using namespace llvm::hlsl;
33
35
36static NamespaceDecl *createImplicitNamespace(Sema &S, StringRef Name,
37 DeclContext *DC) {
38 ASTContext &AST = S.getASTContext();
39 IdentifierInfo &II = AST.Idents.get(Name, tok::TokenKind::identifier);
41 NamespaceDecl *PrevDecl = nullptr;
42 if (S.LookupQualifiedName(Result, DC))
43 PrevDecl = Result.getAsSingle<NamespaceDecl>();
44
45 NamespaceDecl *NS =
46 NamespaceDecl::Create(AST, DC, /*Inline=*/false, SourceLocation(),
47 SourceLocation(), &II, PrevDecl, /*Nested=*/false);
48 NS->setImplicit(true);
49 NS->setHasExternalLexicalStorage();
50 DC->addDecl(NS);
51
52 // Force external decls in the namespace to load from the PCH.
53 (void)NS->getCanonicalDecl()->decls_begin();
54
55 return NS;
56}
57
59 SemaPtr = &S;
60 ASTContext &AST = SemaPtr->getASTContext();
61 // If the translation unit has external storage force external decls to load.
64
65 HLSLNamespace = createImplicitNamespace(
67 HLSLDetailNamespace = createImplicitNamespace(S, "__detail", HLSLNamespace);
68
69 defineTrivialHLSLTypes();
70 defineInternalHLSLTypes();
71 defineHLSLTypesWithForwardDeclarations();
72 defineHLSLAtomicIntrinsics();
73
74 // This adds a `using namespace hlsl` directive. In DXC, we don't put HLSL's
75 // built in types inside a namespace, but we are planning to change that in
76 // the near future. In order to be source compatible older versions of HLSL
77 // will need to implicitly use the hlsl namespace. For now in clang everything
78 // will get added to the namespace, and we can remove the using directive for
79 // future language versions to match HLSL's evolution.
82 NestedNameSpecifierLoc(), SourceLocation(), HLSLNamespace,
84
86}
87
88void HLSLExternalSemaSource::defineHLSLVectorAlias() {
89 ASTContext &AST = SemaPtr->getASTContext();
90
91 llvm::SmallVector<NamedDecl *> TemplateParams;
92
93 auto *TypeParam = TemplateTypeParmDecl::Create(
94 AST, HLSLNamespace, SourceLocation(), SourceLocation(), 0, 0,
95 &AST.Idents.get("element", tok::TokenKind::identifier), false, false);
96 TypeParam->setDefaultArgument(
99
100 TemplateParams.emplace_back(TypeParam);
101
102 auto *SizeParam = NonTypeTemplateParmDecl::Create(
103 AST, HLSLNamespace, SourceLocation(), SourceLocation(), 0, 1,
104 &AST.Idents.get("element_count", tok::TokenKind::identifier), AST.IntTy,
105 false, AST.getTrivialTypeSourceInfo(AST.IntTy));
106 llvm::APInt Val(AST.getIntWidth(AST.IntTy), 4);
107 TemplateArgument Default(AST, llvm::APSInt(std::move(Val)), AST.IntTy,
108 /*IsDefaulted=*/true);
109 SizeParam->setDefaultArgument(AST, SemaPtr->getTrivialTemplateArgumentLoc(
110 Default, AST.IntTy, SourceLocation()));
111 TemplateParams.emplace_back(SizeParam);
112
113 auto *ParamList =
115 TemplateParams, SourceLocation(), nullptr);
116
117 IdentifierInfo &II = AST.Idents.get("vector", tok::TokenKind::identifier);
118
120 AST.getTemplateTypeParmType(0, 0, false, TypeParam),
122 AST, NestedNameSpecifierLoc(), SourceLocation(), SizeParam, false,
123 DeclarationNameInfo(SizeParam->getDeclName(), SourceLocation()),
124 AST.IntTy, VK_LValue),
126
127 auto *Record = TypeAliasDecl::Create(AST, HLSLNamespace, SourceLocation(),
128 SourceLocation(), &II,
129 AST.getTrivialTypeSourceInfo(AliasType));
130 Record->setImplicit(true);
131
132 auto *Template =
133 TypeAliasTemplateDecl::Create(AST, HLSLNamespace, SourceLocation(),
134 Record->getIdentifier(), ParamList, Record);
135
136 Record->setDescribedAliasTemplate(Template);
137 Template->setImplicit(true);
138 Template->setLexicalDeclContext(Record->getDeclContext());
139 HLSLNamespace->addDecl(Template);
140}
141
142void HLSLExternalSemaSource::defineHLSLMatrixAlias() {
143 ASTContext &AST = SemaPtr->getASTContext();
144 llvm::SmallVector<NamedDecl *> TemplateParams;
145
146 auto *TypeParam = TemplateTypeParmDecl::Create(
147 AST, HLSLNamespace, SourceLocation(), SourceLocation(), 0, 0,
148 &AST.Idents.get("element", tok::TokenKind::identifier), false, false);
149 TypeParam->setDefaultArgument(
150 AST, SemaPtr->getTrivialTemplateArgumentLoc(
152
153 TemplateParams.emplace_back(TypeParam);
154
155 // these should be 64 bit to be consistent with other clang matrices.
156 auto *RowsParam = NonTypeTemplateParmDecl::Create(
157 AST, HLSLNamespace, SourceLocation(), SourceLocation(), 0, 1,
158 &AST.Idents.get("rows_count", tok::TokenKind::identifier), AST.IntTy,
159 false, AST.getTrivialTypeSourceInfo(AST.IntTy));
160 llvm::APInt RVal(AST.getIntWidth(AST.IntTy), 4);
161 TemplateArgument RDefault(AST, llvm::APSInt(std::move(RVal)), AST.IntTy,
162 /*IsDefaulted=*/true);
163 RowsParam->setDefaultArgument(
164 AST, SemaPtr->getTrivialTemplateArgumentLoc(RDefault, AST.IntTy,
165 SourceLocation()));
166 TemplateParams.emplace_back(RowsParam);
167
168 auto *ColsParam = NonTypeTemplateParmDecl::Create(
169 AST, HLSLNamespace, SourceLocation(), SourceLocation(), 0, 2,
170 &AST.Idents.get("cols_count", tok::TokenKind::identifier), AST.IntTy,
171 false, AST.getTrivialTypeSourceInfo(AST.IntTy));
172 llvm::APInt CVal(AST.getIntWidth(AST.IntTy), 4);
173 TemplateArgument CDefault(AST, llvm::APSInt(std::move(CVal)), AST.IntTy,
174 /*IsDefaulted=*/true);
175 ColsParam->setDefaultArgument(
176 AST, SemaPtr->getTrivialTemplateArgumentLoc(CDefault, AST.IntTy,
177 SourceLocation()));
178 TemplateParams.emplace_back(ColsParam);
179
180 const unsigned MaxMatDim = SemaPtr->getLangOpts().MaxMatrixDimension;
181
182 auto *MaxRow = IntegerLiteral::Create(
183 AST, llvm::APInt(AST.getIntWidth(AST.IntTy), MaxMatDim), AST.IntTy,
185 auto *MaxCol = IntegerLiteral::Create(
186 AST, llvm::APInt(AST.getIntWidth(AST.IntTy), MaxMatDim), AST.IntTy,
188
189 auto *RowsRef = DeclRefExpr::Create(
190 AST, NestedNameSpecifierLoc(), SourceLocation(), RowsParam,
191 /*RefersToEnclosingVariableOrCapture*/ false,
192 DeclarationNameInfo(RowsParam->getDeclName(), SourceLocation()),
193 AST.IntTy, VK_LValue);
194 auto *ColsRef = DeclRefExpr::Create(
195 AST, NestedNameSpecifierLoc(), SourceLocation(), ColsParam,
196 /*RefersToEnclosingVariableOrCapture*/ false,
197 DeclarationNameInfo(ColsParam->getDeclName(), SourceLocation()),
198 AST.IntTy, VK_LValue);
199
200 auto *RowsLE = BinaryOperator::Create(AST, RowsRef, MaxRow, BO_LE, AST.BoolTy,
203 auto *ColsLE = BinaryOperator::Create(AST, ColsRef, MaxCol, BO_LE, AST.BoolTy,
206
208 AST, RowsLE, ColsLE, BO_LAnd, AST.BoolTy, VK_PRValue, OK_Ordinary,
210
211 auto *ParamList = TemplateParameterList::Create(
212 AST, SourceLocation(), SourceLocation(), TemplateParams, SourceLocation(),
214
215 IdentifierInfo &II = AST.Idents.get("matrix", tok::TokenKind::identifier);
216
218 AST.getTemplateTypeParmType(0, 0, false, TypeParam),
220 AST, NestedNameSpecifierLoc(), SourceLocation(), RowsParam, false,
221 DeclarationNameInfo(RowsParam->getDeclName(), SourceLocation()),
222 AST.IntTy, VK_LValue),
224 AST, NestedNameSpecifierLoc(), SourceLocation(), ColsParam, false,
225 DeclarationNameInfo(ColsParam->getDeclName(), SourceLocation()),
226 AST.IntTy, VK_LValue),
228
229 auto *Record = TypeAliasDecl::Create(AST, HLSLNamespace, SourceLocation(),
230 SourceLocation(), &II,
231 AST.getTrivialTypeSourceInfo(AliasType));
232 Record->setImplicit(true);
233
234 auto *Template =
235 TypeAliasTemplateDecl::Create(AST, HLSLNamespace, SourceLocation(),
236 Record->getIdentifier(), ParamList, Record);
237
238 Record->setDescribedAliasTemplate(Template);
239 Template->setImplicit(true);
240 Template->setLexicalDeclContext(Record->getDeclContext());
241 HLSLNamespace->addDecl(Template);
242}
243
244void HLSLExternalSemaSource::defineTrivialHLSLTypes() {
245 defineHLSLVectorAlias();
246 defineHLSLMatrixAlias();
247}
248
249void HLSLExternalSemaSource::defineHeapResourceInfoTypes() {
250 ASTContext &AST = SemaPtr->getASTContext();
251 CXXRecordDecl *ResDecl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLDetailNamespace,
252 "heap_resource_info")
253 .finalizeForwardDeclaration();
254 if (!ResDecl->isCompleteDefinition())
255 BuiltinTypeDeclBuilder(*SemaPtr, ResDecl)
256 .addMemberVariable("Index", AST.UnsignedIntTy, {})
257 .completeDefinition();
258
259 CXXRecordDecl *SampDecl =
260 BuiltinTypeDeclBuilder(*SemaPtr, HLSLDetailNamespace, "heap_sampler_info")
261 .finalizeForwardDeclaration();
262 if (!SampDecl->isCompleteDefinition())
263 BuiltinTypeDeclBuilder(*SemaPtr, SampDecl)
264 .addMemberVariable("Index", AST.UnsignedIntTy, {})
265 .completeDefinition();
266}
267
268void HLSLExternalSemaSource::defineInternalHLSLTypes() {
269 defineHeapResourceInfoTypes();
270}
271
272/// Set up common members and attributes for buffer types
274 ResourceClass RC, bool IsROV,
275 bool RawBuffer, bool HasCounter) {
277 .addBufferHandles(RC, IsROV, RawBuffer, HasCounter)
283}
284
285/// Set up common members and attributes for sampler types
295
296namespace {
298
299/// Which members a texture type has. Overloads within a member family
300/// (e.g., offset overloads for samplers) follow from ResourceDimension.
301enum class TexCap : uint32_t {
302 Load = 1u << 0, // Load(int<N+1>) taking a mip level
303 LoadMS = 1u << 1, // Load(int<N>, int sampleIndex) on a multisampled type
304 LoadRW = 1u << 2, // Load(int<N>) on a writable texture
305 Subscript = 1u << 3, // operator[]
306 Mips = 1u << 4, // mips[]
307 Sample = 1u << 5, // Sample, SampleBias, SampleGrad, SampleLevel
308 SampleCmp = 1u << 6, // SampleCmp, SampleCmpLevelZero
309 Gather = 1u << 7, // Gather*, GatherCmp*
310 CalcLOD = 1u << 8, // CalculateLevelOfDetail, ...Unclamped
311 GetDims = 1u << 9, // GetDimensions
312
313 // TODO: multisampled types need an MS-specific GetDimensions
314 // https://github.com/llvm/wg-hlsl/issues/347
315
316 LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/GetDims)
317};
318
319/// How a type's template parameters are spelled. Independent of its
320/// capabilities; also decides which types get a vector partial specialization.
321enum class TemplateShape {
322 ElementType, // template<typename T = float4>
323 ElementTypeAndSampleCount, // template<typename T, uint N>
324};
325
326struct TextureTypeInfo {
327 const char *Name;
328 ResourceClass RC;
329 ResourceDimension Dim;
330 bool IsArray;
331 bool IsROV;
332 TemplateShape Shape;
333 TexCap Caps;
334
335 bool has(TexCap C) const { return (Caps & C) != TexCap{}; }
336 bool hasSampleCount() const {
337 return Shape == TemplateShape::ElementTypeAndSampleCount;
338 }
339};
340} // namespace
341
342static const TextureTypeInfo TextureTypes[] = {
343 {"Texture1D", ResourceClass::SRV, ResourceDimension::Dim1D,
344 /*IsArray=*/false, /*IsROV=*/false, TemplateShape::ElementType,
345 TexCap::Load | TexCap::Subscript | TexCap::Mips | TexCap::Sample |
346 TexCap::SampleCmp | TexCap::CalcLOD},
347 {"RWTexture1D", ResourceClass::UAV, ResourceDimension::Dim1D,
348 /*IsArray=*/false, /*IsROV=*/false, TemplateShape::ElementType,
349 TexCap::LoadRW | TexCap::Subscript},
350 {"Texture1DArray", ResourceClass::SRV, ResourceDimension::Dim1D,
351 /*IsArray=*/true, /*IsROV=*/false, TemplateShape::ElementType,
352 TexCap::Load | TexCap::Subscript | TexCap::Mips | TexCap::Sample |
353 TexCap::SampleCmp | TexCap::CalcLOD},
354 {"RWTexture1DArray", ResourceClass::UAV, ResourceDimension::Dim1D,
355 /*IsArray=*/true, /*IsROV=*/false, TemplateShape::ElementType,
356 TexCap::LoadRW | TexCap::Subscript},
357 {"Texture2D", ResourceClass::SRV, ResourceDimension::Dim2D,
358 /*IsArray=*/false, /*IsROV=*/false, TemplateShape::ElementType,
359 TexCap::Load | TexCap::Subscript | TexCap::Mips | TexCap::Sample |
360 TexCap::SampleCmp | TexCap::CalcLOD | TexCap::Gather |
361 TexCap::GetDims},
362 {"RWTexture2D", ResourceClass::UAV, ResourceDimension::Dim2D,
363 /*IsArray=*/false, /*IsROV=*/false, TemplateShape::ElementType,
364 TexCap::LoadRW | TexCap::Subscript | TexCap::GetDims},
365 {"Texture2DArray", ResourceClass::SRV, ResourceDimension::Dim2D,
366 /*IsArray=*/true, /*IsROV=*/false, TemplateShape::ElementType,
367 TexCap::Load | TexCap::Subscript | TexCap::Mips | TexCap::Sample |
368 TexCap::SampleCmp | TexCap::CalcLOD | TexCap::Gather |
369 TexCap::GetDims},
370 {"RWTexture2DArray", ResourceClass::UAV, ResourceDimension::Dim2D,
371 /*IsArray=*/true, /*IsROV=*/false, TemplateShape::ElementType,
372 TexCap::LoadRW | TexCap::Subscript | TexCap::GetDims},
373 {"Texture2DMS", ResourceClass::SRV, ResourceDimension::Dim2D,
374 /*IsArray=*/false, /*IsROV=*/false,
375 TemplateShape::ElementTypeAndSampleCount,
376 TexCap::LoadMS | TexCap::Subscript},
377 {"Texture3D", ResourceClass::SRV, ResourceDimension::Dim3D,
378 /*IsArray=*/false, /*IsROV=*/false, TemplateShape::ElementType,
379 TexCap::Load | TexCap::Subscript | TexCap::Mips | TexCap::Sample |
380 TexCap::CalcLOD | TexCap::GetDims},
381 {"RWTexture3D", ResourceClass::UAV, ResourceDimension::Dim3D,
382 /*IsArray=*/false, /*IsROV=*/false, TemplateShape::ElementType,
383 TexCap::LoadRW | TexCap::Subscript | TexCap::GetDims},
384 {"TextureCube", ResourceClass::SRV, ResourceDimension::Cube,
385 /*IsArray=*/false, /*IsROV=*/false, TemplateShape::ElementType,
386 TexCap::Sample | TexCap::SampleCmp | TexCap::CalcLOD | TexCap::Gather |
387 TexCap::GetDims},
388 {"TextureCubeArray", ResourceClass::SRV, ResourceDimension::Cube,
389 /*IsArray=*/true, /*IsROV=*/false, TemplateShape::ElementType,
390 TexCap::Sample | TexCap::SampleCmp | TexCap::CalcLOD | TexCap::Gather |
391 TexCap::GetDims},
392};
393
395 const TextureTypeInfo &T) {
396 const ResourceDimension Dim = T.Dim;
397 const bool IsArray = T.IsArray;
398
399 Expr *SampleCountExpr = nullptr;
400 if (T.hasSampleCount()) {
401 ClassTemplateDecl *CTD = Decl->getDescribedClassTemplate();
402 assert(CTD && "multisampled texture must be a class template");
403 // Parameter 1 is the N in Texture2DMS<T, N>.
406 SampleCountExpr =
407 S.BuildDeclRefExpr(NTTP, NTTP->getType(), VK_PRValue, SourceLocation());
408 }
409
411 B.addTextureHandle(T.RC, T.IsROV, IsArray, Dim, SampleCountExpr);
412
413 // The `mips` member holds a second copy of the resource handle.
414 // addCopyConstructor, addCopyAssignmentOperator and
415 // addStaticInitializationFunctions are what initialize that copy, and they
416 // look the member up by name, so it has to exist before they run.
417 if (T.has(TexCap::Mips))
419
425
426 if (T.has(TexCap::Load))
427 B.addTextureLoadMethods(Dim, IsArray);
428 if (T.has(TexCap::LoadMS))
429 B.addTextureLoadMSMethods(Dim, IsArray);
430 if (T.has(TexCap::LoadRW))
431 B.addRWTextureLoadMethods(Dim, IsArray);
432 if (T.has(TexCap::Subscript))
434
435 if (T.has(TexCap::Sample))
436 B.addSampleMethods(Dim, IsArray)
437 .addSampleBiasMethods(Dim, IsArray)
438 .addSampleGradMethods(Dim, IsArray)
439 .addSampleLevelMethods(Dim, IsArray);
440 if (T.has(TexCap::SampleCmp))
441 B.addSampleCmpMethods(Dim, IsArray)
443 if (T.has(TexCap::CalcLOD))
445 if (T.has(TexCap::GetDims))
447 if (T.has(TexCap::Gather))
448 B.addGatherMethods(Dim, IsArray).addGatherCmpMethods(Dim, IsArray);
449
450 return B;
451}
452
453// Add a partial specialization for a template. The `TextureTemplate` is
454// `Texture<element_type>`, and it will be specialized for vectors:
455// `Texture<vector<element_type, element_count>>`.
458 ClassTemplateDecl *TextureTemplate) {
459 ASTContext &AST = S.getASTContext();
460
461 // Create the template parameters: element_type and element_count.
462 auto *ElementType = TemplateTypeParmDecl::Create(
463 AST, HLSLNamespace, SourceLocation(), SourceLocation(), 0, 0,
464 &AST.Idents.get("element_type"), false, false);
465 auto *ElementCount = NonTypeTemplateParmDecl::Create(
466 AST, HLSLNamespace, SourceLocation(), SourceLocation(), 0, 1,
467 &AST.Idents.get("element_count"), AST.IntTy, false,
469
470 auto *TemplateParams = TemplateParameterList::Create(
471 AST, SourceLocation(), SourceLocation(), {ElementType, ElementCount},
472 SourceLocation(), nullptr);
473
474 // Create the dependent vector type: vector<element_type, element_count>.
476 AST.getTemplateTypeParmType(0, 0, false, ElementType),
478 AST, NestedNameSpecifierLoc(), SourceLocation(), ElementCount, false,
479 DeclarationNameInfo(ElementCount->getDeclName(), SourceLocation()),
480 AST.IntTy, VK_LValue),
482
483 // Create the partial specialization declaration.
484 QualType CanonInjectedTST =
488
490 AST, TagDecl::TagKind::Class, HLSLNamespace, SourceLocation(),
491 SourceLocation(), TemplateParams, TextureTemplate,
493 CanQualType::CreateUnsafe(CanonInjectedTST), nullptr);
494
495 // Set the template arguments as written.
497 TemplateArgumentLoc ArgLoc =
499 TemplateArgumentListInfo ArgsInfo =
501 ArgsInfo.addArgument(ArgLoc);
502 PartialSpec->setTemplateArgsAsWritten(
504
505 PartialSpec->setImplicit(true);
506 PartialSpec->setLexicalDeclContext(HLSLNamespace);
507 PartialSpec->setHasExternalLexicalStorage();
508
509 // Add the partial specialization to the namespace and the class template.
510 HLSLNamespace->addDecl(PartialSpec);
511 TextureTemplate->AddPartialSpecialization(PartialSpec, {});
512
513 return PartialSpec;
514}
515
516// This function is responsible for constructing the constraint expression for
517// this concept:
518// template<typename T> concept is_typed_resource_element_compatible =
519// __is_typed_resource_element_compatible<T>;
522 ASTContext &Context = S.getASTContext();
523
524 // Obtain the QualType for 'bool'
525 QualType BoolTy = Context.BoolTy;
526
527 // Create a QualType that points to this TemplateTypeParmDecl
528 QualType TType = Context.getTypeDeclType(T);
529
530 // Create a TypeSourceInfo for the template type parameter 'T'
531 TypeSourceInfo *TTypeSourceInfo =
532 Context.getTrivialTypeSourceInfo(TType, NameLoc);
533
534 TypeTraitExpr *TypedResExpr = TypeTraitExpr::Create(
535 Context, BoolTy, NameLoc, UTT_IsTypedResourceElementCompatible,
536 {TTypeSourceInfo}, NameLoc, true);
537
538 return TypedResExpr;
539}
540
541// This function is responsible for constructing the constraint expression for
542// this concept:
543// template<typename T> concept is_constant_buffer_element_compatible =
544// std::is_class_v<T> && !__is_intangible(T);
546 SourceLocation NameLoc,
548 ASTContext &Context = S.getASTContext();
549
550 // Obtain the QualType for 'bool'
551 QualType BoolTy = Context.BoolTy;
552
553 // Create a QualType that points to this TemplateTypeParmDecl
554 QualType TType = Context.getTypeDeclType(T);
555
556 // Create a TypeSourceInfo for the template type parameter 'T'
557 TypeSourceInfo *TTypeSourceInfo =
558 Context.getTrivialTypeSourceInfo(TType, NameLoc);
559
561 Context, BoolTy, NameLoc, UTT_IsConstantBufferElementCompatible,
562 {TTypeSourceInfo}, NameLoc, true);
563
564 return ResExpr;
565}
566
567// This function is responsible for constructing the constraint expression for
568// this concept:
569// template<typename T> concept is_structured_resource_element_compatible =
570// !__is_intangible<T> && sizeof(T) >= 1;
572 SourceLocation NameLoc,
574 ASTContext &Context = S.getASTContext();
575
576 // Obtain the QualType for 'bool'
577 QualType BoolTy = Context.BoolTy;
578
579 // Create a QualType that points to this TemplateTypeParmDecl
580 QualType TType = Context.getTypeDeclType(T);
581
582 // Create a TypeSourceInfo for the template type parameter 'T'
583 TypeSourceInfo *TTypeSourceInfo =
584 Context.getTrivialTypeSourceInfo(TType, NameLoc);
585
586 TypeTraitExpr *IsIntangibleExpr =
587 TypeTraitExpr::Create(Context, BoolTy, NameLoc, UTT_IsIntangibleType,
588 {TTypeSourceInfo}, NameLoc, true);
589
590 // negate IsIntangibleExpr
591 UnaryOperator *NotIntangibleExpr = UnaryOperator::Create(
592 Context, IsIntangibleExpr, UO_LNot, BoolTy, VK_LValue, OK_Ordinary,
593 NameLoc, false, FPOptionsOverride());
594
595 // element types also may not be of 0 size
596 UnaryExprOrTypeTraitExpr *SizeOfExpr = new (Context) UnaryExprOrTypeTraitExpr(
597 UETT_SizeOf, TTypeSourceInfo, BoolTy, NameLoc, NameLoc);
598
599 // Create a BinaryOperator that checks if the size of the type is not equal to
600 // 1 Empty structs have a size of 1 in HLSL, so we need to check for that
602 Context, llvm::APInt(Context.getTypeSize(Context.getSizeType()), 1, true),
603 Context.getSizeType(), NameLoc);
604
605 BinaryOperator *SizeGEQOneExpr =
606 BinaryOperator::Create(Context, SizeOfExpr, rhs, BO_GE, BoolTy, VK_LValue,
607 OK_Ordinary, NameLoc, FPOptionsOverride());
608
609 // Combine the two constraints
611 Context, NotIntangibleExpr, SizeGEQOneExpr, BO_LAnd, BoolTy, VK_LValue,
612 OK_Ordinary, NameLoc, FPOptionsOverride());
613
614 return CombinedExpr;
615}
616
618
620 HLSLBufferType BT) {
621 ASTContext &Context = S.getASTContext();
622 DeclContext *DC = NSD->getDeclContext();
623 SourceLocation DeclLoc = SourceLocation();
624
625 IdentifierInfo &ElementTypeII = Context.Idents.get("element_type");
627 Context, NSD->getDeclContext(), DeclLoc, DeclLoc,
628 /*D=*/0,
629 /*P=*/0,
630 /*Id=*/&ElementTypeII,
631 /*Typename=*/true,
632 /*ParameterPack=*/false);
633
634 T->setDeclContext(DC);
635 T->setReferenced();
636
637 // Create and Attach Template Parameter List to ConceptDecl
639 Context, DeclLoc, DeclLoc, {T}, DeclLoc, nullptr);
640
641 DeclarationName DeclName;
642 Expr *ConstraintExpr = nullptr;
643
644 switch (BT) {
646 DeclName = DeclarationName(
647 &Context.Idents.get("__is_typed_resource_element_compatible"));
648 ConstraintExpr = constructTypedBufferConstraintExpr(S, DeclLoc, T);
649 break;
651 DeclName = DeclarationName(
652 &Context.Idents.get("__is_structured_resource_element_compatible"));
653 ConstraintExpr = constructStructuredBufferConstraintExpr(S, DeclLoc, T);
654 break;
656 DeclName = DeclarationName(
657 &Context.Idents.get("__is_constant_buffer_element_compatible"));
658 ConstraintExpr = constructConstantBufferConstraintExpr(S, DeclLoc, T);
659 break;
660 }
661
662 // Create a ConceptDecl
663 ConceptDecl *CD =
664 ConceptDecl::Create(Context, NSD->getDeclContext(), DeclLoc, DeclName,
665 ConceptParams, ConstraintExpr);
666
667 // Attach the template parameter list to the ConceptDecl
668 CD->setTemplateParameters(ConceptParams);
669
670 // Add the concept declaration to the Translation Unit Decl
671 NSD->getDeclContext()->addDecl(CD);
672
673 return CD;
674}
675
676void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
677 ASTContext &AST = SemaPtr->getASTContext();
678 CXXRecordDecl *Decl;
679 ConceptDecl *TypedBufferConcept = constructBufferConceptDecl(
680 *SemaPtr, HLSLNamespace, HLSLBufferType::Typed);
681 ConceptDecl *StructuredBufferConcept = constructBufferConceptDecl(
682 *SemaPtr, HLSLNamespace, HLSLBufferType::Structured);
683 ConceptDecl *ConstantBufferConcept = constructBufferConceptDecl(
684 *SemaPtr, HLSLNamespace, HLSLBufferType::Constant);
685
686 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "ConstantBuffer")
687 .addSimpleTemplateParams({"element_type"}, ConstantBufferConcept)
688 .finalizeForwardDeclaration();
689
690 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
691 setupBufferType(Decl, *SemaPtr, ResourceClass::CBuffer, /*IsROV=*/false,
692 /*RawBuffer=*/false, /*HasCounter=*/false)
695 });
696
697 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "Buffer")
698 .addSimpleTemplateParams({"element_type"}, TypedBufferConcept)
699 .finalizeForwardDeclaration();
700
701 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
702 setupBufferType(Decl, *SemaPtr, ResourceClass::SRV, /*IsROV=*/false,
703 /*RawBuffer=*/false, /*HasCounter=*/false)
708 });
709
710 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "RWBuffer")
711 .addSimpleTemplateParams({"element_type"}, TypedBufferConcept)
712 .finalizeForwardDeclaration();
713
714 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
715 setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, /*IsROV=*/false,
716 /*RawBuffer=*/false, /*HasCounter=*/false)
721 });
722
723 Decl =
724 BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "RasterizerOrderedBuffer")
725 .addSimpleTemplateParams({"element_type"}, StructuredBufferConcept)
726 .finalizeForwardDeclaration();
727 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
728 setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, /*IsROV=*/true,
729 /*RawBuffer=*/false, /*HasCounter=*/false)
734 });
735
736 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "StructuredBuffer")
737 .addSimpleTemplateParams({"element_type"}, StructuredBufferConcept)
738 .finalizeForwardDeclaration();
739 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
740 setupBufferType(Decl, *SemaPtr, ResourceClass::SRV, /*IsROV=*/false,
741 /*RawBuffer=*/true, /*HasCounter=*/false)
746 });
747
748 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "RWStructuredBuffer")
749 .addSimpleTemplateParams({"element_type"}, StructuredBufferConcept)
750 .finalizeForwardDeclaration();
751 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
752 setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, /*IsROV=*/false,
753 /*RawBuffer=*/true, /*HasCounter=*/true)
760 });
761
762 Decl =
763 BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "AppendStructuredBuffer")
764 .addSimpleTemplateParams({"element_type"}, StructuredBufferConcept)
765 .finalizeForwardDeclaration();
766 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
767 setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, /*IsROV=*/false,
768 /*RawBuffer=*/true, /*HasCounter=*/true)
772 });
773
774 Decl =
775 BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "ConsumeStructuredBuffer")
776 .addSimpleTemplateParams({"element_type"}, StructuredBufferConcept)
777 .finalizeForwardDeclaration();
778 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
779 setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, /*IsROV=*/false,
780 /*RawBuffer=*/true, /*HasCounter=*/true)
784 });
785
786 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace,
787 "RasterizerOrderedStructuredBuffer")
788 .addSimpleTemplateParams({"element_type"}, StructuredBufferConcept)
789 .finalizeForwardDeclaration();
790 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
791 setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, /*IsROV=*/true,
792 /*RawBuffer=*/true, /*HasCounter=*/true)
799 });
800
801 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "ByteAddressBuffer")
802 .finalizeForwardDeclaration();
803 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
804 setupBufferType(Decl, *SemaPtr, ResourceClass::SRV, /*IsROV=*/false,
805 /*RawBuffer=*/true, /*HasCounter=*/false)
809 });
810 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "RWByteAddressBuffer")
811 .finalizeForwardDeclaration();
812 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
813 setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, /*IsROV=*/false,
814 /*RawBuffer=*/true, /*HasCounter=*/false)
820 });
821 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace,
822 "RasterizerOrderedByteAddressBuffer")
823 .finalizeForwardDeclaration();
824 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
825 setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, /*IsROV=*/true,
826 /*RawBuffer=*/true, /*HasCounter=*/false)
830 });
831
832 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "SamplerState")
833 .finalizeForwardDeclaration();
834 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
835 setupSamplerType(Decl, *SemaPtr).completeDefinition();
836 });
837
838 Decl =
839 BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "SamplerComparisonState")
840 .finalizeForwardDeclaration();
841 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
842 setupSamplerType(Decl, *SemaPtr).completeDefinition();
843 });
844
845 QualType Float4Ty = AST.getExtVectorType(AST.FloatTy, 4);
846 for (const TextureTypeInfo &T : TextureTypes) {
847 BuiltinTypeDeclBuilder TexBuilder(*SemaPtr, HLSLNamespace, T.Name);
848 switch (T.Shape) {
849 case TemplateShape::ElementType:
850 TexBuilder.addSimpleTemplateParams({"element_type"}, {Float4Ty},
851 TypedBufferConcept);
852 break;
853 case TemplateShape::ElementTypeAndSampleCount:
854 TexBuilder.addMSTextureTemplateParams("element_type", "sample_count",
855 TypedBufferConcept);
856 break;
857 }
858 Decl = TexBuilder.finalizeForwardDeclaration();
859
860 onCompletion(Decl, [this, &T](CXXRecordDecl *Decl) {
861 setupTextureType(Decl, *SemaPtr, T).completeDefinition();
862 });
863
864 if (T.Shape != TemplateShape::ElementType)
865 continue;
866
867 CXXRecordDecl *PartialSpec = addVectorTexturePartialSpecialization(
868 *SemaPtr, HLSLNamespace, Decl->getDescribedClassTemplate());
869 onCompletion(PartialSpec, [this, &T](CXXRecordDecl *Decl) {
870 setupTextureType(Decl, *SemaPtr, T).completeDefinition();
871 });
872 }
873}
874
875// Build a single overload of an HLSL atomic intrinsic in the hlsl namespace.
876// `dest` is an address-space-qualified reference; `original_value` (when
877// present) is a plain reference. The synthesized FunctionDecl aliases the
878// underlying clang builtin via BuiltinAliasAttr.
879static void buildAtomicOverload(Sema &S, NamespaceDecl *NS, StringRef FuncName,
880 StringRef BuiltinName, QualType ElemTy,
881 LangAS DestAS, bool ThreeArg) {
882 ASTContext &AST = S.getASTContext();
883
884 QualType DestTy =
885 AST.getLValueReferenceType(AST.getAddrSpaceQualType(ElemTy, DestAS));
886 QualType OrigRefTy = AST.getLValueReferenceType(ElemTy);
887
888 SmallVector<QualType, 3> ParamTypes;
889 ParamTypes.push_back(DestTy);
890 ParamTypes.push_back(ElemTy);
891 if (ThreeArg)
892 ParamTypes.push_back(OrigRefTy);
893
895 QualType FuncTy = AST.getFunctionType(AST.VoidTy, ParamTypes, EPI);
896 auto *TSInfo = AST.getTrivialTypeSourceInfo(FuncTy, SourceLocation());
897
898 IdentifierInfo &FuncII = AST.Idents.get(FuncName, tok::TokenKind::identifier);
899 DeclarationName FuncDeclName(&FuncII);
900
902 AST, NS, SourceLocation(), SourceLocation(), FuncDeclName, FuncTy, TSInfo,
903 SC_Extern, /*UsesFPIntrin=*/false, /*isInlineSpecified=*/false,
904 /*hasWrittenPrototype=*/true);
905
906 constexpr const char *ParamNames[] = {"dest", "value", "original_value"};
908 unsigned I = 0;
909 for (auto [ParamType, ParamName] : llvm::zip(ParamTypes, ParamNames)) {
910 IdentifierInfo &PII = AST.Idents.get(ParamName, tok::TokenKind::identifier);
912 AST, FD, SourceLocation(), SourceLocation(), &PII, ParamType,
914 nullptr);
915 Parm->setScopeInfo(0, I++);
916 ParmDecls.push_back(Parm);
917 }
918 FD->setParams(ParmDecls);
919
920 IdentifierInfo &BuiltinII =
921 S.getPreprocessor().getIdentifierTable().get(BuiltinName);
922 FD->addAttr(BuiltinAliasAttr::CreateImplicit(AST, &BuiltinII));
923 FD->setImplicit();
924 NS->addDecl(FD);
925}
926
927// Synthesize the InterlockedFunc overload set: {int, uint, int64_t, uint64_t}
928// x {groupshared, device} x {2-arg, 3-arg}. Operations that always report the
929// previous value, such as InterlockedExchange, only get the 3-arg form.
930// InterlockedExchange also accepts float, which lowers to a bitwise exchange
931// of the 32-bit pattern.
933 StringRef FuncName, StringRef BuiltinName,
934 bool RequiresOriginalValue = false,
935 bool SupportsFloat = false) {
936 ASTContext &AST = S.getASTContext();
937 // HLSL: int64_t == long, uint64_t == unsigned long (see hlsl_basic_types.h).
938 SmallVector<QualType, 5> Elems = {AST.IntTy, AST.UnsignedIntTy, AST.LongTy,
939 AST.UnsignedLongTy};
940 if (SupportsFloat)
941 Elems.push_back(AST.FloatTy);
943
944 for (QualType ElemTy : Elems)
945 for (LangAS AS : AddrSpaces) {
946 if (!RequiresOriginalValue)
947 buildAtomicOverload(S, NS, FuncName, BuiltinName, ElemTy, AS,
948 /*ThreeArg=*/false);
949 buildAtomicOverload(S, NS, FuncName, BuiltinName, ElemTy, AS,
950 /*ThreeArg=*/true);
951 }
952}
953
954void HLSLExternalSemaSource::defineHLSLAtomicIntrinsics() {
955 defineHLSLInterlockedFunc(*SemaPtr, HLSLNamespace, "InterlockedAdd",
956 "__builtin_hlsl_interlocked_add");
957 defineHLSLInterlockedFunc(*SemaPtr, HLSLNamespace, "InterlockedAnd",
958 "__builtin_hlsl_interlocked_and");
959 defineHLSLInterlockedFunc(*SemaPtr, HLSLNamespace, "InterlockedExchange",
960 "__builtin_hlsl_interlocked_exchange",
961 /*RequiresOriginalValue=*/true,
962 /*SupportsFloat=*/true);
963 defineHLSLInterlockedFunc(*SemaPtr, HLSLNamespace, "InterlockedMax",
964 "__builtin_hlsl_interlocked_max");
965 defineHLSLInterlockedFunc(*SemaPtr, HLSLNamespace, "InterlockedMin",
966 "__builtin_hlsl_interlocked_min");
967 defineHLSLInterlockedFunc(*SemaPtr, HLSLNamespace, "InterlockedOr",
968 "__builtin_hlsl_interlocked_or");
969 defineHLSLInterlockedFunc(*SemaPtr, HLSLNamespace, "InterlockedXor",
970 "__builtin_hlsl_interlocked_xor");
971}
972
973void HLSLExternalSemaSource::onCompletion(CXXRecordDecl *Record,
974 CompletionFunction Fn) {
975 if (!Record->isCompleteDefinition())
976 Completions.insert(std::make_pair(Record->getCanonicalDecl(), Fn));
977}
978
980 if (!isa<CXXRecordDecl>(Tag))
981 return;
982 auto *Record = cast<CXXRecordDecl>(Tag);
983 Record = Record->getCanonicalDecl();
984 auto It = Completions.find(Record);
985 if (It == Completions.end())
986 return;
987 // Move out the callback and erase before invoking it: the callback can
988 // re-enter CompleteType and mutate Completions, which invalidates It under
989 // backward-shift deletion.
990 CompletionFunction Fn = std::move(It->second);
991 Completions.erase(It);
992 Fn(Record);
993}
Defines the clang::ASTContext interface.
Provides definitions for the various language-specific address spaces.
llvm::dxil::ResourceClass ResourceClass
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S, ResourceClass RC, bool IsROV, bool RawBuffer, bool HasCounter)
Set up common members and attributes for buffer types.
static BuiltinTypeDeclBuilder setupTextureType(CXXRecordDecl *Decl, Sema &S, const TextureTypeInfo &T)
static NamespaceDecl * createImplicitNamespace(Sema &S, StringRef Name, DeclContext *DC)
static BuiltinTypeDeclBuilder setupSamplerType(CXXRecordDecl *Decl, Sema &S)
Set up common members and attributes for sampler types.
static void buildAtomicOverload(Sema &S, NamespaceDecl *NS, StringRef FuncName, StringRef BuiltinName, QualType ElemTy, LangAS DestAS, bool ThreeArg)
static Expr * constructTypedBufferConstraintExpr(Sema &S, SourceLocation NameLoc, TemplateTypeParmDecl *T)
static ConceptDecl * constructBufferConceptDecl(Sema &S, NamespaceDecl *NSD, HLSLBufferType BT)
static void defineHLSLInterlockedFunc(Sema &S, NamespaceDecl *NS, StringRef FuncName, StringRef BuiltinName, bool RequiresOriginalValue=false, bool SupportsFloat=false)
static const TextureTypeInfo TextureTypes[]
static Expr * constructConstantBufferConstraintExpr(Sema &S, SourceLocation NameLoc, TemplateTypeParmDecl *T)
static ClassTemplatePartialSpecializationDecl * addVectorTexturePartialSpecialization(Sema &S, NamespaceDecl *HLSLNamespace, ClassTemplateDecl *TextureTemplate)
static Expr * constructStructuredBufferConstraintExpr(Sema &S, SourceLocation NameLoc, TemplateTypeParmDecl *T)
Result
Implement __builtin_bit_cast and related operations.
llvm::MachO::Record Record
Definition MachO.h:31
Defines the clang::Preprocessor interface.
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 ...
Definition ASTContext.h:239
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.
CanQualType LongTy
unsigned getIntWidth(QualType T) const
static CanQualType getCanonicalType(QualType T)
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
CanQualType FloatTy
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const
Return the uniqued reference to the type for an lvalue reference to the specified type.
IdentifierTable & Idents
Definition ASTContext.h:846
CanQualType BoolTy
CanQualType UnsignedLongTy
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
CanQualType IntTy
CanQualType VoidTy
CanQualType UnsignedIntTy
QualType getTemplateSpecializationType(ElaboratedTypeKeyword Keyword, TemplateName T, ArrayRef< TemplateArgument > SpecifiedArgs, ArrayRef< TemplateArgument > CanonicalArgs, QualType Underlying=QualType()) const
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
QualType getTemplateTypeParmType(int Depth, int Index, bool ParameterPack, TemplateTypeParmDecl *ParmDecl=nullptr) const
Retrieve the template type parameter type for a template parameter or parameter pack with the given d...
QualType getExtVectorType(QualType VectorType, unsigned NumElts) const
Return the unique reference to an extended vector type of the specified element type and size.
QualType getAddrSpaceQualType(QualType T, LangAS AddressSpace) const
Return the uniqued reference to the type for an address space qualified type with the specified type ...
QualType getDependentSizedExtVectorType(QualType VectorType, Expr *SizeExpr, SourceLocation AttrLoc) const
A builtin binary operation expression such as "x + y" or "x <= y".
Definition Expr.h:4082
static BinaryOperator * Create(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, FPOptionsOverride FPFeatures)
Definition Expr.cpp:5138
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
static CanQual< Type > CreateUnsafe(QualType Other)
Declaration of a class template.
void AddPartialSpecialization(ClassTemplatePartialSpecializationDecl *D, llvm::FoldingSetInsertToken InsertToken)
Insert the specified partial specialization knowing that it is not already in.
static ClassTemplatePartialSpecializationDecl * Create(ASTContext &Context, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, TemplateParameterList *Params, ClassTemplateDecl *SpecializedTemplate, ArrayRef< TemplateArgument > Args, CanQualType CanonInjectedTST, ClassTemplatePartialSpecializationDecl *PrevDecl)
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...
Definition DeclBase.h:1466
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...
Definition DeclBase.h:2738
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)
Definition Expr.cpp:494
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
void addAttr(Attr *A)
void setImplicit(bool I=true)
Definition DeclBase.h:602
DeclContext * getDeclContext()
Definition DeclBase.h:456
The name of a declaration.
This represents one expression.
Definition Expr.h:113
Represents difference between two FPOptions values.
Represents a function declaration or definition.
Definition Decl.h:2059
static FunctionDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation NLoc, DeclarationName N, QualType T, TypeSourceInfo *TInfo, StorageClass SC, bool UsesFPIntrin=false, bool isInlineSpecified=false, bool hasWrittenPrototype=true, ConstexprSpecKind ConstexprKind=ConstexprSpecKind::Unspecified, const AssociatedConstraint &TrailingRequiresClause={})
Definition Decl.h:2303
void CompleteType(TagDecl *Tag) override
Complete an incomplete HLSL builtin type.
void InitializeSema(Sema &S) override
Initialize the semantic source with the Sema instance being used to perform semantic analysis on the ...
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'.
Definition Expr.cpp:981
Represents the results of name lookup.
Definition Lookup.h:147
Represent a C++ namespace.
Definition Decl.h:593
static NamespaceDecl * Create(ASTContext &C, DeclContext *DC, bool Inline, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, NamespaceDecl *PrevDecl, bool Nested)
Definition DeclCXX.cpp:3374
A C++ nested-name-specifier augmented with source location information.
static NonTypeTemplateParmDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, int D, int P, const IdentifierInfo *Id, QualType T, bool ParameterPack, TypeSourceInfo *TInfo)
Represents a parameter to a function.
Definition Decl.h:1820
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition Decl.h:1853
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
Definition Decl.cpp:2943
IdentifierTable & getIdentifierTable()
A (possibly-)qualified type.
Definition TypeBase.h:938
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.
Definition Sema.h:863
@ LookupNamespaceName
Look up a namespace name within a C++ using directive or namespace alias definition,...
Definition Sema.h:9417
Preprocessor & getPreprocessor() const
Definition Sema.h:934
ASTContext & getASTContext() const
Definition Sema.h:935
DeclRefExpr * BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, SourceLocation Loc, const CXXScopeSpec *SS=nullptr)
const LangOptions & getLangOpts() const
Definition Sema.h:928
TemplateArgumentLoc getTrivialTemplateArgumentLoc(const TemplateArgument &Arg, QualType NTTPType, SourceLocation Loc)
Allocate a TemplateArgumentLoc where all locations have been initialized to the given location.
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.
Definition Decl.h:3852
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition Decl.h:3953
A convenient class for passing around template argument information.
void addArgument(const TemplateArgumentLoc &Loc)
Location wrapper for a TemplateArgument.
Represents a template argument.
void setTemplateParameters(TemplateParameterList *TParams)
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Represents a C++ template name within the type system.
Stores a list of template parameters for a TemplateDecl and its derived classes.
NamedDecl * getParam(unsigned Idx)
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, int D, int 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)
Definition Decl.cpp:5882
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.
Definition TypeBase.h:8399
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
Definition ExprCXX.h:2900
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.
Definition ExprCXX.cpp:1939
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition Expr.h:2669
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition Expr.h:2288
static UnaryOperator * Create(const ASTContext &C, Expr *input, Opcode opc, QualType type, ExprValueKind VK, ExprObjectKind OK, SourceLocation l, bool CanOverflow, FPOptionsOverride FPFeatures)
Definition Expr.cpp:5195
Represents a C++ using-declaration.
Definition DeclCXX.h:3621
static UsingDirectiveDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, SourceLocation NamespaceLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation IdentLoc, NamedDecl *Nominated, DeclContext *CommonAncestor)
Definition DeclCXX.cpp:3330
Represents a GCC generic vector type.
Definition TypeBase.h:4266
BuiltinTypeDeclBuilder & addRWTextureLoadMethods(ResourceDimension Dim, bool IsArray=false)
BuiltinTypeDeclBuilder & addDefaultHandleConstructor(AccessSpecifier Access=AccessSpecifier::AS_public)
BuiltinTypeDeclBuilder & addSampleGradMethods(ResourceDimension Dim, bool IsArray=false)
BuiltinTypeDeclBuilder & addCopyAssignmentOperator(AccessSpecifier Access=AccessSpecifier::AS_public)
BuiltinTypeDeclBuilder & addGatherCmpMethods(ResourceDimension Dim, bool IsArray=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 & addHeapResourceInfoConstructor(bool HasCounter=false)
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 & addTextureHandle(ResourceClass RC, bool IsROV, bool IsArray, ResourceDimension RD, Expr *SampleCountExpr=nullptr, AccessSpecifier Access=AccessSpecifier::AS_private)
BuiltinTypeDeclBuilder & addSampleCmpLevelZeroMethods(ResourceDimension Dim, bool IsArray=false)
MIPS builtins.
const internal::ArgumentAdaptingMatcherFunc< internal::HasMatcher > has
Matches AST nodes that have child AST nodes that match the provided matcher.
bool Load(InterpState &S, CodePtr OpPC)
Definition Interp.h:2219
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.
Top level wrappers for InstallAPI frontend operations.
bool isa(CodeGen::Address addr)
Definition Address.h:330
@ OK_Ordinary
An ordinary object is located at an address in memory.
Definition Specifiers.h:152
LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE()
@ SC_Extern
Definition Specifiers.h:252
@ SC_None
Definition Specifiers.h:251
@ Default
Set to the current date and time.
@ Result
The result type of a method or function.
Definition TypeBase.h:906
const FunctionProtoType * T
@ Template
We are parsing a template declaration.
Definition Parser.h:81
LangAS
Defines the address space values used by the address space qualifier of QualType.
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
Definition Specifiers.h:136
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
Definition Specifiers.h:140
U cast(CodeGen::Address addr)
Definition Address.h:327
@ Class
The "class" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:6007
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 uint32_t
static const ASTTemplateArgumentListInfo * Create(const ASTContext &C, const TemplateArgumentListInfo &List)
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
Extra information about a function prototype.
Definition TypeBase.h:5483