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 if (SemaPtr->getLangOpts().getHLSLVersion() >= LangOptions::HLSL_202x)
75 return;
76
77 // This adds a `using namespace hlsl` directive. In DXC, we don't put HLSL's
78 // built in types inside a namespace, but we are planning to change that in
79 // the near future. In order to be source compatible, HLSL before 202x
80 // will need to implictly use the hlsl namespace.
83 NestedNameSpecifierLoc(), SourceLocation(), HLSLNamespace,
85
87}
88
89void HLSLExternalSemaSource::defineHLSLVectorAlias() {
90 ASTContext &AST = SemaPtr->getASTContext();
91
92 llvm::SmallVector<NamedDecl *> TemplateParams;
93
94 auto *TypeParam = TemplateTypeParmDecl::Create(
95 AST, HLSLNamespace, SourceLocation(), SourceLocation(), 0, 0,
96 &AST.Idents.get("element", tok::TokenKind::identifier), false, false);
97 TypeParam->setDefaultArgument(
100
101 TemplateParams.emplace_back(TypeParam);
102
103 auto *SizeParam = NonTypeTemplateParmDecl::Create(
104 AST, HLSLNamespace, SourceLocation(), SourceLocation(), 0, 1,
105 &AST.Idents.get("element_count", tok::TokenKind::identifier), AST.IntTy,
106 false, AST.getTrivialTypeSourceInfo(AST.IntTy));
107 llvm::APInt Val(AST.getIntWidth(AST.IntTy), 4);
108 TemplateArgument Default(AST, llvm::APSInt(std::move(Val)), AST.IntTy,
109 /*IsDefaulted=*/true);
110 SizeParam->setDefaultArgument(AST, SemaPtr->getTrivialTemplateArgumentLoc(
111 Default, AST.IntTy, SourceLocation()));
112 TemplateParams.emplace_back(SizeParam);
113
114 auto *ParamList =
116 TemplateParams, SourceLocation(), nullptr);
117
118 IdentifierInfo &II = AST.Idents.get("vector", tok::TokenKind::identifier);
119
121 AST.getTemplateTypeParmType(0, 0, false, TypeParam),
123 AST, NestedNameSpecifierLoc(), SourceLocation(), SizeParam, false,
124 DeclarationNameInfo(SizeParam->getDeclName(), SourceLocation()),
125 AST.IntTy, VK_LValue),
127
128 auto *Record = TypeAliasDecl::Create(AST, HLSLNamespace, SourceLocation(),
129 SourceLocation(), &II,
130 AST.getTrivialTypeSourceInfo(AliasType));
131 Record->setImplicit(true);
132
133 auto *Template =
134 TypeAliasTemplateDecl::Create(AST, HLSLNamespace, SourceLocation(),
135 Record->getIdentifier(), ParamList, Record);
136
137 Record->setDescribedAliasTemplate(Template);
138 Template->setImplicit(true);
139 Template->setLexicalDeclContext(Record->getDeclContext());
140 HLSLNamespace->addDecl(Template);
141}
142
143void HLSLExternalSemaSource::defineHLSLMatrixAlias() {
144 ASTContext &AST = SemaPtr->getASTContext();
145 llvm::SmallVector<NamedDecl *> TemplateParams;
146
147 auto *TypeParam = TemplateTypeParmDecl::Create(
148 AST, HLSLNamespace, SourceLocation(), SourceLocation(), 0, 0,
149 &AST.Idents.get("element", tok::TokenKind::identifier), false, false);
150 TypeParam->setDefaultArgument(
151 AST, SemaPtr->getTrivialTemplateArgumentLoc(
153
154 TemplateParams.emplace_back(TypeParam);
155
156 // these should be 64 bit to be consistent with other clang matrices.
157 auto *RowsParam = NonTypeTemplateParmDecl::Create(
158 AST, HLSLNamespace, SourceLocation(), SourceLocation(), 0, 1,
159 &AST.Idents.get("rows_count", tok::TokenKind::identifier), AST.IntTy,
160 false, AST.getTrivialTypeSourceInfo(AST.IntTy));
161 llvm::APInt RVal(AST.getIntWidth(AST.IntTy), 4);
162 TemplateArgument RDefault(AST, llvm::APSInt(std::move(RVal)), AST.IntTy,
163 /*IsDefaulted=*/true);
164 RowsParam->setDefaultArgument(
165 AST, SemaPtr->getTrivialTemplateArgumentLoc(RDefault, AST.IntTy,
166 SourceLocation()));
167 TemplateParams.emplace_back(RowsParam);
168
169 auto *ColsParam = NonTypeTemplateParmDecl::Create(
170 AST, HLSLNamespace, SourceLocation(), SourceLocation(), 0, 2,
171 &AST.Idents.get("cols_count", tok::TokenKind::identifier), AST.IntTy,
172 false, AST.getTrivialTypeSourceInfo(AST.IntTy));
173 llvm::APInt CVal(AST.getIntWidth(AST.IntTy), 4);
174 TemplateArgument CDefault(AST, llvm::APSInt(std::move(CVal)), AST.IntTy,
175 /*IsDefaulted=*/true);
176 ColsParam->setDefaultArgument(
177 AST, SemaPtr->getTrivialTemplateArgumentLoc(CDefault, AST.IntTy,
178 SourceLocation()));
179 TemplateParams.emplace_back(ColsParam);
180
181 const unsigned MaxMatDim = SemaPtr->getLangOpts().MaxMatrixDimension;
182
183 auto *MaxRow = IntegerLiteral::Create(
184 AST, llvm::APInt(AST.getIntWidth(AST.IntTy), MaxMatDim), AST.IntTy,
186 auto *MaxCol = IntegerLiteral::Create(
187 AST, llvm::APInt(AST.getIntWidth(AST.IntTy), MaxMatDim), AST.IntTy,
189
190 auto *RowsRef = DeclRefExpr::Create(
191 AST, NestedNameSpecifierLoc(), SourceLocation(), RowsParam,
192 /*RefersToEnclosingVariableOrCapture*/ false,
193 DeclarationNameInfo(RowsParam->getDeclName(), SourceLocation()),
194 AST.IntTy, VK_LValue);
195 auto *ColsRef = DeclRefExpr::Create(
196 AST, NestedNameSpecifierLoc(), SourceLocation(), ColsParam,
197 /*RefersToEnclosingVariableOrCapture*/ false,
198 DeclarationNameInfo(ColsParam->getDeclName(), SourceLocation()),
199 AST.IntTy, VK_LValue);
200
201 auto *RowsLE = BinaryOperator::Create(AST, RowsRef, MaxRow, BO_LE, AST.BoolTy,
204 auto *ColsLE = BinaryOperator::Create(AST, ColsRef, MaxCol, BO_LE, AST.BoolTy,
207
209 AST, RowsLE, ColsLE, BO_LAnd, AST.BoolTy, VK_PRValue, OK_Ordinary,
211
212 auto *ParamList = TemplateParameterList::Create(
213 AST, SourceLocation(), SourceLocation(), TemplateParams, SourceLocation(),
215
216 IdentifierInfo &II = AST.Idents.get("matrix", tok::TokenKind::identifier);
217
219 AST.getTemplateTypeParmType(0, 0, false, TypeParam),
221 AST, NestedNameSpecifierLoc(), SourceLocation(), RowsParam, false,
222 DeclarationNameInfo(RowsParam->getDeclName(), SourceLocation()),
223 AST.IntTy, VK_LValue),
225 AST, NestedNameSpecifierLoc(), SourceLocation(), ColsParam, false,
226 DeclarationNameInfo(ColsParam->getDeclName(), SourceLocation()),
227 AST.IntTy, VK_LValue),
229
230 auto *Record = TypeAliasDecl::Create(AST, HLSLNamespace, SourceLocation(),
231 SourceLocation(), &II,
232 AST.getTrivialTypeSourceInfo(AliasType));
233 Record->setImplicit(true);
234
235 auto *Template =
236 TypeAliasTemplateDecl::Create(AST, HLSLNamespace, SourceLocation(),
237 Record->getIdentifier(), ParamList, Record);
238
239 Record->setDescribedAliasTemplate(Template);
240 Template->setImplicit(true);
241 Template->setLexicalDeclContext(Record->getDeclContext());
242 HLSLNamespace->addDecl(Template);
243}
244
245void HLSLExternalSemaSource::defineTrivialHLSLTypes() {
246 defineHLSLVectorAlias();
247 defineHLSLMatrixAlias();
248}
249
250void HLSLExternalSemaSource::defineHeapResourceInfoTypes() {
251 ASTContext &AST = SemaPtr->getASTContext();
252 CXXRecordDecl *ResDecl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLDetailNamespace,
253 "heap_resource_info")
254 .finalizeForwardDeclaration();
255 if (!ResDecl->isCompleteDefinition())
256 BuiltinTypeDeclBuilder(*SemaPtr, ResDecl)
257 .addMemberVariable("Index", AST.UnsignedIntTy, {})
258 .completeDefinition();
259
260 CXXRecordDecl *SampDecl =
261 BuiltinTypeDeclBuilder(*SemaPtr, HLSLDetailNamespace, "heap_sampler_info")
262 .finalizeForwardDeclaration();
263 if (!SampDecl->isCompleteDefinition())
264 BuiltinTypeDeclBuilder(*SemaPtr, SampDecl)
265 .addMemberVariable("Index", AST.UnsignedIntTy, {})
266 .completeDefinition();
267}
268
269void HLSLExternalSemaSource::defineInternalHLSLTypes() {
270 defineHeapResourceInfoTypes();
271}
272
273/// Set up common members and attributes for buffer types
275 ResourceClass RC, bool IsROV,
276 bool RawBuffer, bool HasCounter) {
278 .addBufferHandles(RC, IsROV, RawBuffer, HasCounter)
284}
285
286/// Set up common members and attributes for sampler types
296
297namespace {
299
300/// Which members a texture type has. Overloads within a member family
301/// (e.g., offset overloads for samplers) follow from ResourceDimension.
302enum class TexCap : uint32_t {
303 Load = 1u << 0, // Load(int<N+1>) taking a mip level
304 LoadMS = 1u << 1, // Load(int<N>, int sampleIndex) on a multisampled type
305 LoadRW = 1u << 2, // Load(int<N>) on a writable texture
306 Subscript = 1u << 3, // operator[]
307 Mips = 1u << 4, // mips[]
308 Sample = 1u << 5, // Sample, SampleBias, SampleGrad, SampleLevel
309 SampleCmp = 1u << 6, // SampleCmp, SampleCmpLevelZero
310 Gather = 1u << 7, // Gather*, GatherCmp*
311 CalcLOD = 1u << 8, // CalculateLevelOfDetail, ...Unclamped
312 GetDims = 1u << 9, // GetDimensions
313
314 // TODO: multisampled types need an MS-specific GetDimensions
315 // https://github.com/llvm/wg-hlsl/issues/347
316
317 LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/GetDims)
318};
319
320/// How a type's template parameters are spelled. Independent of its
321/// capabilities; also decides which types get a vector partial specialization.
322enum class TemplateShape {
323 ElementType, // template<typename T = float4>
324 ElementTypeAndSampleCount, // template<typename T, uint N>
325};
326
327struct TextureTypeInfo {
328 const char *Name;
329 ResourceClass RC;
330 ResourceDimension Dim;
331 bool IsArray;
332 bool IsROV;
333 TemplateShape Shape;
334 TexCap Caps;
335
336 bool has(TexCap C) const { return (Caps & C) != TexCap{}; }
337 bool hasSampleCount() const {
338 return Shape == TemplateShape::ElementTypeAndSampleCount;
339 }
340};
341} // namespace
342
343static const TextureTypeInfo TextureTypes[] = {
344 {"Texture1D", ResourceClass::SRV, ResourceDimension::Dim1D,
345 /*IsArray=*/false, /*IsROV=*/false, TemplateShape::ElementType,
346 TexCap::Load | TexCap::Subscript | TexCap::Mips | TexCap::Sample |
347 TexCap::SampleCmp | TexCap::CalcLOD},
348 {"RWTexture1D", ResourceClass::UAV, ResourceDimension::Dim1D,
349 /*IsArray=*/false, /*IsROV=*/false, TemplateShape::ElementType,
350 TexCap::LoadRW | TexCap::Subscript},
351 {"Texture1DArray", ResourceClass::SRV, ResourceDimension::Dim1D,
352 /*IsArray=*/true, /*IsROV=*/false, TemplateShape::ElementType,
353 TexCap::Load | TexCap::Subscript | TexCap::Mips | TexCap::Sample |
354 TexCap::SampleCmp | TexCap::CalcLOD},
355 {"RWTexture1DArray", ResourceClass::UAV, ResourceDimension::Dim1D,
356 /*IsArray=*/true, /*IsROV=*/false, TemplateShape::ElementType,
357 TexCap::LoadRW | TexCap::Subscript},
358 {"Texture2D", ResourceClass::SRV, ResourceDimension::Dim2D,
359 /*IsArray=*/false, /*IsROV=*/false, TemplateShape::ElementType,
360 TexCap::Load | TexCap::Subscript | TexCap::Mips | TexCap::Sample |
361 TexCap::SampleCmp | TexCap::CalcLOD | TexCap::Gather |
362 TexCap::GetDims},
363 {"RWTexture2D", ResourceClass::UAV, ResourceDimension::Dim2D,
364 /*IsArray=*/false, /*IsROV=*/false, TemplateShape::ElementType,
365 TexCap::LoadRW | TexCap::Subscript | TexCap::GetDims},
366 {"Texture2DArray", ResourceClass::SRV, ResourceDimension::Dim2D,
367 /*IsArray=*/true, /*IsROV=*/false, TemplateShape::ElementType,
368 TexCap::Load | TexCap::Subscript | TexCap::Mips | TexCap::Sample |
369 TexCap::SampleCmp | TexCap::CalcLOD | TexCap::Gather |
370 TexCap::GetDims},
371 {"RWTexture2DArray", ResourceClass::UAV, ResourceDimension::Dim2D,
372 /*IsArray=*/true, /*IsROV=*/false, TemplateShape::ElementType,
373 TexCap::LoadRW | TexCap::Subscript | TexCap::GetDims},
374 {"Texture2DMS", ResourceClass::SRV, ResourceDimension::Dim2D,
375 /*IsArray=*/false, /*IsROV=*/false,
376 TemplateShape::ElementTypeAndSampleCount,
377 TexCap::LoadMS | TexCap::Subscript},
378 {"Texture3D", ResourceClass::SRV, ResourceDimension::Dim3D,
379 /*IsArray=*/false, /*IsROV=*/false, TemplateShape::ElementType,
380 TexCap::Load | TexCap::Subscript | TexCap::Mips | TexCap::Sample |
381 TexCap::CalcLOD | TexCap::GetDims},
382 {"RWTexture3D", ResourceClass::UAV, ResourceDimension::Dim3D,
383 /*IsArray=*/false, /*IsROV=*/false, TemplateShape::ElementType,
384 TexCap::LoadRW | TexCap::Subscript | TexCap::GetDims},
385 {"TextureCube", ResourceClass::SRV, ResourceDimension::Cube,
386 /*IsArray=*/false, /*IsROV=*/false, TemplateShape::ElementType,
387 TexCap::Sample | TexCap::SampleCmp | TexCap::CalcLOD | TexCap::Gather |
388 TexCap::GetDims},
389 {"TextureCubeArray", ResourceClass::SRV, ResourceDimension::Cube,
390 /*IsArray=*/true, /*IsROV=*/false, TemplateShape::ElementType,
391 TexCap::Sample | TexCap::SampleCmp | TexCap::CalcLOD | TexCap::Gather |
392 TexCap::GetDims},
393};
394
396 const TextureTypeInfo &T) {
397 const ResourceDimension Dim = T.Dim;
398 const bool IsArray = T.IsArray;
399
400 Expr *SampleCountExpr = nullptr;
401 if (T.hasSampleCount()) {
402 ClassTemplateDecl *CTD = Decl->getDescribedClassTemplate();
403 assert(CTD && "multisampled texture must be a class template");
404 // Parameter 1 is the N in Texture2DMS<T, N>.
407 SampleCountExpr =
408 S.BuildDeclRefExpr(NTTP, NTTP->getType(), VK_PRValue, SourceLocation());
409 }
410
412 B.addTextureHandle(T.RC, T.IsROV, IsArray, Dim, SampleCountExpr);
413
414 // The `mips` member holds a second copy of the resource handle.
415 // addCopyConstructor, addCopyAssignmentOperator and
416 // addStaticInitializationFunctions are what initialize that copy, and they
417 // look the member up by name, so it has to exist before they run.
418 if (T.has(TexCap::Mips))
420
426
427 if (T.has(TexCap::Load))
428 B.addTextureLoadMethods(Dim, IsArray);
429 if (T.has(TexCap::LoadMS))
430 B.addTextureLoadMSMethods(Dim, IsArray);
431 if (T.has(TexCap::LoadRW))
432 B.addRWTextureLoadMethods(Dim, IsArray);
433 if (T.has(TexCap::Subscript))
435
436 if (T.has(TexCap::Sample))
437 B.addSampleMethods(Dim, IsArray)
438 .addSampleBiasMethods(Dim, IsArray)
439 .addSampleGradMethods(Dim, IsArray)
440 .addSampleLevelMethods(Dim, IsArray);
441 if (T.has(TexCap::SampleCmp))
442 B.addSampleCmpMethods(Dim, IsArray)
444 if (T.has(TexCap::CalcLOD))
446 if (T.has(TexCap::GetDims))
448 if (T.has(TexCap::Gather))
449 B.addGatherMethods(Dim, IsArray).addGatherCmpMethods(Dim, IsArray);
450
451 return B;
452}
453
454// Add a partial specialization for a template. The `TextureTemplate` is
455// `Texture<element_type>`, and it will be specialized for vectors:
456// `Texture<vector<element_type, element_count>>`.
459 ClassTemplateDecl *TextureTemplate) {
460 ASTContext &AST = S.getASTContext();
461
462 // Create the template parameters: element_type and element_count.
463 auto *ElementType = TemplateTypeParmDecl::Create(
464 AST, HLSLNamespace, SourceLocation(), SourceLocation(), 0, 0,
465 &AST.Idents.get("element_type"), false, false);
466 auto *ElementCount = NonTypeTemplateParmDecl::Create(
467 AST, HLSLNamespace, SourceLocation(), SourceLocation(), 0, 1,
468 &AST.Idents.get("element_count"), AST.IntTy, false,
470
471 auto *TemplateParams = TemplateParameterList::Create(
472 AST, SourceLocation(), SourceLocation(), {ElementType, ElementCount},
473 SourceLocation(), nullptr);
474
475 // Create the dependent vector type: vector<element_type, element_count>.
477 AST.getTemplateTypeParmType(0, 0, false, ElementType),
479 AST, NestedNameSpecifierLoc(), SourceLocation(), ElementCount, false,
480 DeclarationNameInfo(ElementCount->getDeclName(), SourceLocation()),
481 AST.IntTy, VK_LValue),
483
484 // Create the partial specialization declaration.
485 QualType CanonInjectedTST =
489
491 AST, TagDecl::TagKind::Class, HLSLNamespace, SourceLocation(),
492 SourceLocation(), TemplateParams, TextureTemplate,
494 CanQualType::CreateUnsafe(CanonInjectedTST), nullptr);
495
496 // Set the template arguments as written.
498 TemplateArgumentLoc ArgLoc =
500 TemplateArgumentListInfo ArgsInfo =
502 ArgsInfo.addArgument(ArgLoc);
503 PartialSpec->setTemplateArgsAsWritten(
505
506 PartialSpec->setImplicit(true);
507 PartialSpec->setLexicalDeclContext(HLSLNamespace);
508 PartialSpec->setHasExternalLexicalStorage();
509
510 // Add the partial specialization to the namespace and the class template.
511 HLSLNamespace->addDecl(PartialSpec);
512 TextureTemplate->AddPartialSpecialization(PartialSpec, {});
513
514 return PartialSpec;
515}
516
517// This function is responsible for constructing the constraint expression for
518// this concept:
519// template<typename T> concept is_typed_resource_element_compatible =
520// __is_typed_resource_element_compatible<T>;
523 ASTContext &Context = S.getASTContext();
524
525 // Obtain the QualType for 'bool'
526 QualType BoolTy = Context.BoolTy;
527
528 // Create a QualType that points to this TemplateTypeParmDecl
529 QualType TType = Context.getTypeDeclType(T);
530
531 // Create a TypeSourceInfo for the template type parameter 'T'
532 TypeSourceInfo *TTypeSourceInfo =
533 Context.getTrivialTypeSourceInfo(TType, NameLoc);
534
535 TypeTraitExpr *TypedResExpr = TypeTraitExpr::Create(
536 Context, BoolTy, NameLoc, UTT_IsTypedResourceElementCompatible,
537 {TTypeSourceInfo}, NameLoc, true);
538
539 return TypedResExpr;
540}
541
542// This function is responsible for constructing the constraint expression for
543// this concept:
544// template<typename T> concept is_constant_buffer_element_compatible =
545// std::is_class_v<T> && !__is_intangible(T);
547 SourceLocation NameLoc,
549 ASTContext &Context = S.getASTContext();
550
551 // Obtain the QualType for 'bool'
552 QualType BoolTy = Context.BoolTy;
553
554 // Create a QualType that points to this TemplateTypeParmDecl
555 QualType TType = Context.getTypeDeclType(T);
556
557 // Create a TypeSourceInfo for the template type parameter 'T'
558 TypeSourceInfo *TTypeSourceInfo =
559 Context.getTrivialTypeSourceInfo(TType, NameLoc);
560
562 Context, BoolTy, NameLoc, UTT_IsConstantBufferElementCompatible,
563 {TTypeSourceInfo}, NameLoc, true);
564
565 return ResExpr;
566}
567
568// This function is responsible for constructing the constraint expression for
569// this concept:
570// template<typename T> concept is_structured_resource_element_compatible =
571// !__is_intangible<T> && sizeof(T) >= 1;
573 SourceLocation NameLoc,
575 ASTContext &Context = S.getASTContext();
576
577 // Obtain the QualType for 'bool'
578 QualType BoolTy = Context.BoolTy;
579
580 // Create a QualType that points to this TemplateTypeParmDecl
581 QualType TType = Context.getTypeDeclType(T);
582
583 // Create a TypeSourceInfo for the template type parameter 'T'
584 TypeSourceInfo *TTypeSourceInfo =
585 Context.getTrivialTypeSourceInfo(TType, NameLoc);
586
587 TypeTraitExpr *IsIntangibleExpr =
588 TypeTraitExpr::Create(Context, BoolTy, NameLoc, UTT_IsIntangibleType,
589 {TTypeSourceInfo}, NameLoc, true);
590
591 // negate IsIntangibleExpr
592 UnaryOperator *NotIntangibleExpr = UnaryOperator::Create(
593 Context, IsIntangibleExpr, UO_LNot, BoolTy, VK_LValue, OK_Ordinary,
594 NameLoc, false, FPOptionsOverride());
595
596 // element types also may not be of 0 size
597 UnaryExprOrTypeTraitExpr *SizeOfExpr = new (Context) UnaryExprOrTypeTraitExpr(
598 UETT_SizeOf, TTypeSourceInfo, BoolTy, NameLoc, NameLoc);
599
600 // Create a BinaryOperator that checks if the size of the type is not equal to
601 // 1 Empty structs have a size of 1 in HLSL, so we need to check for that
603 Context, llvm::APInt(Context.getTypeSize(Context.getSizeType()), 1, true),
604 Context.getSizeType(), NameLoc);
605
606 BinaryOperator *SizeGEQOneExpr =
607 BinaryOperator::Create(Context, SizeOfExpr, rhs, BO_GE, BoolTy, VK_LValue,
608 OK_Ordinary, NameLoc, FPOptionsOverride());
609
610 // Combine the two constraints
612 Context, NotIntangibleExpr, SizeGEQOneExpr, BO_LAnd, BoolTy, VK_LValue,
613 OK_Ordinary, NameLoc, FPOptionsOverride());
614
615 return CombinedExpr;
616}
617
619
621 HLSLBufferType BT) {
622 ASTContext &Context = S.getASTContext();
623 DeclContext *DC = NSD->getDeclContext();
624 SourceLocation DeclLoc = SourceLocation();
625
626 IdentifierInfo &ElementTypeII = Context.Idents.get("element_type");
628 Context, NSD->getDeclContext(), DeclLoc, DeclLoc,
629 /*D=*/0,
630 /*P=*/0,
631 /*Id=*/&ElementTypeII,
632 /*Typename=*/true,
633 /*ParameterPack=*/false);
634
635 T->setDeclContext(DC);
636 T->setReferenced();
637
638 // Create and Attach Template Parameter List to ConceptDecl
640 Context, DeclLoc, DeclLoc, {T}, DeclLoc, nullptr);
641
642 DeclarationName DeclName;
643 Expr *ConstraintExpr = nullptr;
644
645 switch (BT) {
647 DeclName = DeclarationName(
648 &Context.Idents.get("__is_typed_resource_element_compatible"));
649 ConstraintExpr = constructTypedBufferConstraintExpr(S, DeclLoc, T);
650 break;
652 DeclName = DeclarationName(
653 &Context.Idents.get("__is_structured_resource_element_compatible"));
654 ConstraintExpr = constructStructuredBufferConstraintExpr(S, DeclLoc, T);
655 break;
657 DeclName = DeclarationName(
658 &Context.Idents.get("__is_constant_buffer_element_compatible"));
659 ConstraintExpr = constructConstantBufferConstraintExpr(S, DeclLoc, T);
660 break;
661 }
662
663 // Create a ConceptDecl
664 ConceptDecl *CD =
665 ConceptDecl::Create(Context, NSD->getDeclContext(), DeclLoc, DeclName,
666 ConceptParams, ConstraintExpr);
667
668 // Attach the template parameter list to the ConceptDecl
669 CD->setTemplateParameters(ConceptParams);
670
671 // Add the concept declaration to the Translation Unit Decl
672 NSD->getDeclContext()->addDecl(CD);
673
674 return CD;
675}
676
677void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
678 ASTContext &AST = SemaPtr->getASTContext();
679 CXXRecordDecl *Decl;
680 ConceptDecl *TypedBufferConcept = constructBufferConceptDecl(
681 *SemaPtr, HLSLNamespace, HLSLBufferType::Typed);
682 ConceptDecl *StructuredBufferConcept = constructBufferConceptDecl(
683 *SemaPtr, HLSLNamespace, HLSLBufferType::Structured);
684 ConceptDecl *ConstantBufferConcept = constructBufferConceptDecl(
685 *SemaPtr, HLSLNamespace, HLSLBufferType::Constant);
686
687 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "ConstantBuffer")
688 .addSimpleTemplateParams({"element_type"}, ConstantBufferConcept)
689 .finalizeForwardDeclaration();
690
691 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
692 setupBufferType(Decl, *SemaPtr, ResourceClass::CBuffer, /*IsROV=*/false,
693 /*RawBuffer=*/false, /*HasCounter=*/false)
696 });
697
698 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "Buffer")
699 .addSimpleTemplateParams({"element_type"}, TypedBufferConcept)
700 .finalizeForwardDeclaration();
701
702 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
703 setupBufferType(Decl, *SemaPtr, ResourceClass::SRV, /*IsROV=*/false,
704 /*RawBuffer=*/false, /*HasCounter=*/false)
709 });
710
711 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "RWBuffer")
712 .addSimpleTemplateParams({"element_type"}, TypedBufferConcept)
713 .finalizeForwardDeclaration();
714
715 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
716 setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, /*IsROV=*/false,
717 /*RawBuffer=*/false, /*HasCounter=*/false)
722 });
723
724 Decl =
725 BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "RasterizerOrderedBuffer")
726 .addSimpleTemplateParams({"element_type"}, StructuredBufferConcept)
727 .finalizeForwardDeclaration();
728 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
729 setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, /*IsROV=*/true,
730 /*RawBuffer=*/false, /*HasCounter=*/false)
735 });
736
737 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "StructuredBuffer")
738 .addSimpleTemplateParams({"element_type"}, StructuredBufferConcept)
739 .finalizeForwardDeclaration();
740 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
741 setupBufferType(Decl, *SemaPtr, ResourceClass::SRV, /*IsROV=*/false,
742 /*RawBuffer=*/true, /*HasCounter=*/false)
747 });
748
749 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "RWStructuredBuffer")
750 .addSimpleTemplateParams({"element_type"}, StructuredBufferConcept)
751 .finalizeForwardDeclaration();
752 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
753 setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, /*IsROV=*/false,
754 /*RawBuffer=*/true, /*HasCounter=*/true)
761 });
762
763 Decl =
764 BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "AppendStructuredBuffer")
765 .addSimpleTemplateParams({"element_type"}, StructuredBufferConcept)
766 .finalizeForwardDeclaration();
767 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
768 setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, /*IsROV=*/false,
769 /*RawBuffer=*/true, /*HasCounter=*/true)
773 });
774
775 Decl =
776 BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "ConsumeStructuredBuffer")
777 .addSimpleTemplateParams({"element_type"}, StructuredBufferConcept)
778 .finalizeForwardDeclaration();
779 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
780 setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, /*IsROV=*/false,
781 /*RawBuffer=*/true, /*HasCounter=*/true)
785 });
786
787 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace,
788 "RasterizerOrderedStructuredBuffer")
789 .addSimpleTemplateParams({"element_type"}, StructuredBufferConcept)
790 .finalizeForwardDeclaration();
791 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
792 setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, /*IsROV=*/true,
793 /*RawBuffer=*/true, /*HasCounter=*/true)
800 });
801
802 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "ByteAddressBuffer")
803 .finalizeForwardDeclaration();
804 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
805 setupBufferType(Decl, *SemaPtr, ResourceClass::SRV, /*IsROV=*/false,
806 /*RawBuffer=*/true, /*HasCounter=*/false)
810 });
811 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "RWByteAddressBuffer")
812 .finalizeForwardDeclaration();
813 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
814 setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, /*IsROV=*/false,
815 /*RawBuffer=*/true, /*HasCounter=*/false)
821 });
822 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace,
823 "RasterizerOrderedByteAddressBuffer")
824 .finalizeForwardDeclaration();
825 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
826 setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, /*IsROV=*/true,
827 /*RawBuffer=*/true, /*HasCounter=*/false)
831 });
832
833 Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "SamplerState")
834 .finalizeForwardDeclaration();
835 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
836 setupSamplerType(Decl, *SemaPtr).completeDefinition();
837 });
838
839 Decl =
840 BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "SamplerComparisonState")
841 .finalizeForwardDeclaration();
842 onCompletion(Decl, [this](CXXRecordDecl *Decl) {
843 setupSamplerType(Decl, *SemaPtr).completeDefinition();
844 });
845
846 QualType Float4Ty = AST.getExtVectorType(AST.FloatTy, 4);
847 for (const TextureTypeInfo &T : TextureTypes) {
848 BuiltinTypeDeclBuilder TexBuilder(*SemaPtr, HLSLNamespace, T.Name);
849 switch (T.Shape) {
850 case TemplateShape::ElementType:
851 TexBuilder.addSimpleTemplateParams({"element_type"}, {Float4Ty},
852 TypedBufferConcept);
853 break;
854 case TemplateShape::ElementTypeAndSampleCount:
855 TexBuilder.addMSTextureTemplateParams("element_type", "sample_count",
856 TypedBufferConcept);
857 break;
858 }
859 Decl = TexBuilder.finalizeForwardDeclaration();
860
861 onCompletion(Decl, [this, &T](CXXRecordDecl *Decl) {
862 setupTextureType(Decl, *SemaPtr, T).completeDefinition();
863 });
864
865 if (T.Shape != TemplateShape::ElementType)
866 continue;
867
868 CXXRecordDecl *PartialSpec = addVectorTexturePartialSpecialization(
869 *SemaPtr, HLSLNamespace, Decl->getDescribedClassTemplate());
870 onCompletion(PartialSpec, [this, &T](CXXRecordDecl *Decl) {
871 setupTextureType(Decl, *SemaPtr, T).completeDefinition();
872 });
873 }
874}
875
876// Shapes of the synthesized atomic overloads. The read-modify-write operations
877// can report the previous value through a trailing reference. Compare-store
878// takes only inputs; compare-exchange adds the trailing reference.
880 Binary, // (dest, value)
881 BinaryWithOriginal, // (dest, value, original_value)
882 CompareStore, // (dest, compare_value, value)
883 CompareExchange, // (dest, compare_value, value, original_value)
884};
885
886// Build a single overload of an HLSL atomic intrinsic in the hlsl namespace.
887// `dest` is an address-space-qualified reference; `original_value` (when
888// present) is an HLSL `out` parameter. The synthesized FunctionDecl aliases
889// the underlying clang builtin via BuiltinAliasAttr.
890static void buildAtomicOverload(Sema &S, NamespaceDecl *NS, StringRef FuncName,
891 StringRef BuiltinName, QualType ElemTy,
892 LangAS DestAS, AtomicOverloadShape Shape) {
893 ASTContext &AST = S.getASTContext();
894
895 QualType DestTy =
896 AST.getLValueReferenceType(AST.getAddrSpaceQualType(ElemTy, DestAS));
897 QualType OrigRefTy = S.HLSL().getInoutParameterType(ElemTy);
898
899 SmallVector<QualType, 4> ParamTypes = {DestTy, ElemTy};
900 switch (Shape) {
902 break;
904 ParamTypes.push_back(OrigRefTy);
905 break;
907 ParamTypes.push_back(ElemTy);
908 break;
910 ParamTypes.push_back(ElemTy);
911 ParamTypes.push_back(OrigRefTy);
912 break;
913 }
914
915 // The loop below stops at the end of ParamTypes, so a shorter overload
916 // ignores the trailing names.
917 constexpr const char *BinaryNames[] = {"dest", "value", "original_value"};
918 constexpr const char *CompareNames[] = {"dest", "compare_value", "value",
919 "original_value"};
920 const bool IsCompare = Shape == AtomicOverloadShape::CompareStore ||
922 const bool HasOriginalValue =
925 ArrayRef<const char *> ParamNames = IsCompare
926 ? ArrayRef<const char *>(CompareNames)
927 : ArrayRef<const char *>(BinaryNames);
928
931 ParamTypes.size());
932 if (HasOriginalValue) {
933 ParamExtInfos.back() = ParamExtInfos.back().withABI(ParameterABI::HLSLOut);
934 EPI.ExtParameterInfos = ParamExtInfos.data();
935 }
936 QualType FuncTy = AST.getFunctionType(AST.VoidTy, ParamTypes, EPI);
937 auto *TSInfo = AST.getTrivialTypeSourceInfo(FuncTy, SourceLocation());
938
939 IdentifierInfo &FuncII = AST.Idents.get(FuncName, tok::TokenKind::identifier);
940 DeclarationName FuncDeclName(&FuncII);
941
943 AST, NS, SourceLocation(), SourceLocation(), FuncDeclName, FuncTy, TSInfo,
944 SC_Extern, /*UsesFPIntrin=*/false, /*isInlineSpecified=*/false,
945 /*hasWrittenPrototype=*/true);
946
948 unsigned I = 0;
949 for (auto [ParamType, ParamName] : llvm::zip(ParamTypes, ParamNames)) {
950 IdentifierInfo &PII = AST.Idents.get(ParamName, tok::TokenKind::identifier);
952 AST, FD, SourceLocation(), SourceLocation(), &PII, ParamType,
954 nullptr);
955 if (HasOriginalValue && I == ParamTypes.size() - 1)
956 Parm->addAttr(HLSLParamModifierAttr::Create(
957 AST, SourceRange(), HLSLParamModifierAttr::Keyword_out));
958 Parm->setScopeInfo(0, I++);
959 ParmDecls.push_back(Parm);
960 }
961 FD->setParams(ParmDecls);
962
963 IdentifierInfo &BuiltinII =
964 S.getPreprocessor().getIdentifierTable().get(BuiltinName);
965 FD->addAttr(BuiltinAliasAttr::CreateImplicit(AST, &BuiltinII));
966 FD->setImplicit();
967 NS->addDecl(FD);
968}
969
970// Synthesize the InterlockedFunc overload set: {int, uint, int64_t, uint64_t}
971// x {groupshared, device} x {2-arg, 3-arg}. Operations that always report the
972// previous value, such as InterlockedExchange, only get the 3-arg form.
973// InterlockedExchange also accepts float, which lowers to a bitwise exchange
974// of the 32-bit pattern.
976 StringRef FuncName, StringRef BuiltinName,
977 bool RequiresOriginalValue = false,
978 bool SupportsFloat = false) {
979 ASTContext &AST = S.getASTContext();
980 // HLSL: int64_t == long, uint64_t == unsigned long (see hlsl_basic_types.h).
981 SmallVector<QualType, 5> Elems = {AST.IntTy, AST.UnsignedIntTy, AST.LongTy,
982 AST.UnsignedLongTy};
983 if (SupportsFloat)
984 Elems.push_back(AST.FloatTy);
986
987 for (QualType ElemTy : Elems)
988 for (LangAS AS : AddrSpaces) {
989 if (!RequiresOriginalValue)
990 buildAtomicOverload(S, NS, FuncName, BuiltinName, ElemTy, AS,
992 buildAtomicOverload(S, NS, FuncName, BuiltinName, ElemTy, AS,
994 }
995}
996
997// Synthesize the compare-and-swap overload sets: {int, uint, int64_t,
998// uint64_t} x {groupshared, device}. Each function has one form only.
1000 StringRef FuncName,
1001 StringRef BuiltinName,
1002 AtomicOverloadShape Shape) {
1003 ASTContext &AST = S.getASTContext();
1004 QualType Elems[] = {AST.IntTy, AST.UnsignedIntTy, AST.LongTy,
1005 AST.UnsignedLongTy};
1006
1007 for (QualType ElemTy : Elems)
1009 buildAtomicOverload(S, NS, FuncName, BuiltinName, ElemTy, AS, Shape);
1010}
1011
1012// The float-bitwise compare-and-swap functions have their own names and take
1013// float only.
1015 StringRef FuncName,
1016 StringRef BuiltinName,
1017 AtomicOverloadShape Shape) {
1018 ASTContext &AST = S.getASTContext();
1019 buildAtomicOverload(S, NS, FuncName, BuiltinName, AST.FloatTy,
1021 buildAtomicOverload(S, NS, FuncName, BuiltinName, AST.FloatTy,
1022 LangAS::hlsl_device, Shape);
1023}
1024
1025void HLSLExternalSemaSource::defineHLSLAtomicIntrinsics() {
1026 defineHLSLInterlockedFunc(*SemaPtr, HLSLNamespace, "InterlockedAdd",
1027 "__builtin_hlsl_interlocked_add");
1028 defineHLSLInterlockedFunc(*SemaPtr, HLSLNamespace, "InterlockedAnd",
1029 "__builtin_hlsl_interlocked_and");
1031 *SemaPtr, HLSLNamespace, "InterlockedCompareExchange",
1032 "__builtin_hlsl_interlocked_compare_exchange",
1035 *SemaPtr, HLSLNamespace, "InterlockedCompareExchangeFloatBitwise",
1036 "__builtin_hlsl_interlocked_compare_exchange_float_bitwise",
1038 defineHLSLInterlockedCompareFunc(*SemaPtr, HLSLNamespace,
1039 "InterlockedCompareStore",
1040 "__builtin_hlsl_interlocked_compare_store",
1043 *SemaPtr, HLSLNamespace, "InterlockedCompareStoreFloatBitwise",
1044 "__builtin_hlsl_interlocked_compare_store_float_bitwise",
1046 defineHLSLInterlockedFunc(*SemaPtr, HLSLNamespace, "InterlockedExchange",
1047 "__builtin_hlsl_interlocked_exchange",
1048 /*RequiresOriginalValue=*/true,
1049 /*SupportsFloat=*/true);
1050 defineHLSLInterlockedFunc(*SemaPtr, HLSLNamespace, "InterlockedMax",
1051 "__builtin_hlsl_interlocked_max");
1052 defineHLSLInterlockedFunc(*SemaPtr, HLSLNamespace, "InterlockedMin",
1053 "__builtin_hlsl_interlocked_min");
1054 defineHLSLInterlockedFunc(*SemaPtr, HLSLNamespace, "InterlockedOr",
1055 "__builtin_hlsl_interlocked_or");
1056 defineHLSLInterlockedFunc(*SemaPtr, HLSLNamespace, "InterlockedXor",
1057 "__builtin_hlsl_interlocked_xor");
1058}
1059
1060void HLSLExternalSemaSource::onCompletion(CXXRecordDecl *Record,
1061 CompletionFunction Fn) {
1062 if (!Record->isCompleteDefinition())
1063 Completions.insert(std::make_pair(Record->getCanonicalDecl(), Fn));
1064}
1065
1067 if (!isa<CXXRecordDecl>(Tag))
1068 return;
1069 auto *Record = cast<CXXRecordDecl>(Tag);
1070 Record = Record->getCanonicalDecl();
1071 auto It = Completions.find(Record);
1072 if (It == Completions.end())
1073 return;
1074 // Move out the callback and erase before invoking it: the callback can
1075 // re-enter CompleteType and mutate Completions, which invalidates It under
1076 // backward-shift deletion.
1077 CompletionFunction Fn = std::move(It->second);
1078 Completions.erase(It);
1079 Fn(Record);
1080}
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 void defineHLSLInterlockedCompareFuncFloat(Sema &S, NamespaceDecl *NS, StringRef FuncName, StringRef BuiltinName, AtomicOverloadShape Shape)
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 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 void defineHLSLInterlockedCompareFunc(Sema &S, NamespaceDecl *NS, StringRef FuncName, StringRef BuiltinName, AtomicOverloadShape Shape)
static Expr * constructConstantBufferConstraintExpr(Sema &S, SourceLocation NameLoc, TemplateTypeParmDecl *T)
static void buildAtomicOverload(Sema &S, NamespaceDecl *NS, StringRef FuncName, StringRef BuiltinName, QualType ElemTy, LangAS DestAS, AtomicOverloadShape Shape)
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:245
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:855
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:4107
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:5144
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:1467
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:2708
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:498
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:603
DeclContext * getDeclContext()
Definition DeclBase.h:457
The name of a declaration.
This represents one expression.
Definition Expr.h:114
Represents difference between two FPOptions values.
Represents a function declaration or definition.
Definition Decl.h:2082
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:2345
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:985
Represents the results of name lookup.
Definition Lookup.h:147
Represent a C++ namespace.
Definition Decl.h:594
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:1832
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition Decl.h:1865
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:2963
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...
QualType getInoutParameterType(QualType Ty)
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:9591
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
SemaHLSL & HLSL()
Definition Sema.h:1528
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.
A trivial tuple used to represent a source range.
Represents the declaration of a struct/union/class/enum.
Definition Decl.h:3898
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition Decl.h:3999
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:5925
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:8549
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
Definition ExprCXX.h:2901
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:1937
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition Expr.h:2694
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition Expr.h:2313
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:5201
Represents a C++ using-declaration.
Definition DeclCXX.h:3638
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:4398
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:2189
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:155
LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE()
@ SC_Extern
Definition Specifiers.h:255
@ SC_None
Definition Specifiers.h:254
@ 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:139
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
Definition Specifiers.h:143
U cast(CodeGen::Address addr)
Definition Address.h:327
@ Class
The "class" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:6157
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:5633
const ExtParameterInfo * ExtParameterInfos
Definition TypeBase.h:5638