37#include "llvm/ADT/ArrayRef.h"
38#include "llvm/ADT/STLExtras.h"
39#include "llvm/ADT/SmallVector.h"
40#include "llvm/ADT/StringExtras.h"
41#include "llvm/ADT/StringRef.h"
42#include "llvm/ADT/Twine.h"
43#include "llvm/Frontend/HLSL/HLSLBinding.h"
44#include "llvm/Frontend/HLSL/RootSignatureValidations.h"
45#include "llvm/Support/Casting.h"
46#include "llvm/Support/DXILABI.h"
47#include "llvm/Support/ErrorHandling.h"
48#include "llvm/Support/FormatVariadic.h"
49#include "llvm/TargetParser/Triple.h"
64 case ResourceClass::SRV:
65 return RegisterType::SRV;
66 case ResourceClass::UAV:
67 return RegisterType::UAV;
68 case ResourceClass::CBuffer:
69 return RegisterType::CBuffer;
70 case ResourceClass::Sampler:
71 return RegisterType::Sampler;
73 llvm_unreachable(
"unexpected ResourceClass value");
83 assert(RT !=
nullptr);
87 *RT = RegisterType::SRV;
91 *RT = RegisterType::UAV;
95 *RT = RegisterType::CBuffer;
99 *RT = RegisterType::Sampler;
103 *RT = RegisterType::C;
107 *RT = RegisterType::I;
116 case RegisterType::SRV:
118 case RegisterType::UAV:
120 case RegisterType::CBuffer:
122 case RegisterType::Sampler:
124 case RegisterType::C:
126 case RegisterType::I:
129 llvm_unreachable(
"unexpected RegisterType value");
134 case RegisterType::SRV:
135 return ResourceClass::SRV;
136 case RegisterType::UAV:
137 return ResourceClass::UAV;
138 case RegisterType::CBuffer:
139 return ResourceClass::CBuffer;
140 case RegisterType::Sampler:
141 return ResourceClass::Sampler;
142 case RegisterType::C:
143 case RegisterType::I:
147 llvm_unreachable(
"unexpected RegisterType value");
151 const auto *BT = dyn_cast<BuiltinType>(
Type);
155 return Builtin::BI__builtin_get_spirv_spec_constant_int;
158 switch (BT->getKind()) {
159 case BuiltinType::Bool:
160 return Builtin::BI__builtin_get_spirv_spec_constant_bool;
161 case BuiltinType::Short:
162 return Builtin::BI__builtin_get_spirv_spec_constant_short;
163 case BuiltinType::Int:
164 return Builtin::BI__builtin_get_spirv_spec_constant_int;
165 case BuiltinType::LongLong:
166 return Builtin::BI__builtin_get_spirv_spec_constant_longlong;
167 case BuiltinType::UShort:
168 return Builtin::BI__builtin_get_spirv_spec_constant_ushort;
169 case BuiltinType::UInt:
170 return Builtin::BI__builtin_get_spirv_spec_constant_uint;
171 case BuiltinType::ULongLong:
172 return Builtin::BI__builtin_get_spirv_spec_constant_ulonglong;
173 case BuiltinType::Half:
174 return Builtin::BI__builtin_get_spirv_spec_constant_half;
175 case BuiltinType::Float:
176 return Builtin::BI__builtin_get_spirv_spec_constant_float;
177 case BuiltinType::Double:
178 return Builtin::BI__builtin_get_spirv_spec_constant_double;
187 llvm::raw_svector_ostream OS(Buffer);
194 ResourceClass ResClass) {
196 "DeclBindingInfo already added");
202 DeclToBindingListIndex.try_emplace(VD, BindingsList.size());
203 return &BindingsList.emplace_back(VD, ResClass);
207 ResourceClass ResClass) {
208 auto Entry = DeclToBindingListIndex.find(VD);
209 if (Entry != DeclToBindingListIndex.end()) {
210 for (
unsigned Index = Entry->getSecond();
211 Index < BindingsList.size() && BindingsList[Index].Decl == VD;
213 if (BindingsList[Index].ResClass == ResClass)
214 return &BindingsList[Index];
221 return DeclToBindingListIndex.contains(VD);
233 getASTContext(), LexicalParent, CBuffer, KwLoc, Ident, IdentLoc, LBrace);
236 auto RC = CBuffer ? llvm::hlsl::ResourceClass::CBuffer
237 : llvm::hlsl::ResourceClass::SRV;
249 if (T->isArrayType() || T->isStructureType() || T->isConstantMatrixType())
256 assert(Context.getTypeSize(T) <= 64 &&
257 "Scalar bit widths larger than 64 not supported");
260 return Context.getTypeSize(T) / 8;
267 constexpr unsigned CBufferAlign = 16;
268 if (
const auto *RD = T->getAsRecordDecl()) {
270 for (
const FieldDecl *Field : RD->fields()) {
277 unsigned AlignSize = llvm::alignTo(Size, FieldAlign);
278 if ((AlignSize % CBufferAlign) + FieldSize > CBufferAlign) {
279 FieldAlign = CBufferAlign;
282 Size = llvm::alignTo(Size, FieldAlign);
289 unsigned ElementCount = AT->getSize().getZExtValue();
290 if (ElementCount == 0)
293 unsigned ElementSize =
295 unsigned AlignedElementSize = llvm::alignTo(ElementSize, CBufferAlign);
296 return AlignedElementSize * (ElementCount - 1) + ElementSize;
300 unsigned ElementCount = VT->getNumElements();
301 unsigned ElementSize =
303 return ElementSize * ElementCount;
306 return Context.getTypeSize(T) / 8;
317 bool HasPackOffset =
false;
318 bool HasNonPackOffset =
false;
320 VarDecl *Var = dyn_cast<VarDecl>(Field);
323 if (Field->hasAttr<HLSLPackOffsetAttr>()) {
324 PackOffsetVec.emplace_back(Var, Field->
getAttr<HLSLPackOffsetAttr>());
325 HasPackOffset =
true;
327 HasNonPackOffset =
true;
334 if (HasNonPackOffset)
341 std::sort(PackOffsetVec.begin(), PackOffsetVec.end(),
342 [](
const std::pair<VarDecl *, HLSLPackOffsetAttr *> &LHS,
343 const std::pair<VarDecl *, HLSLPackOffsetAttr *> &RHS) {
344 return LHS.second->getOffsetInBytes() <
345 RHS.second->getOffsetInBytes();
347 for (
unsigned i = 0; i < PackOffsetVec.size() - 1; i++) {
348 VarDecl *Var = PackOffsetVec[i].first;
349 HLSLPackOffsetAttr *
Attr = PackOffsetVec[i].second;
351 unsigned Begin =
Attr->getOffsetInBytes();
352 unsigned End = Begin + Size;
353 unsigned NextBegin = PackOffsetVec[i + 1].second->getOffsetInBytes();
354 if (End > NextBegin) {
355 VarDecl *NextVar = PackOffsetVec[i + 1].first;
367 CAT = dyn_cast<ConstantArrayType>(
369 return CAT !=
nullptr;
380static const HLSLAttributedResourceType *
383 "expected array of resource records");
385 while (
const ArrayType *AT = dyn_cast<ArrayType>(Ty))
387 return HLSLAttributedResourceType::findHandleTypeOnResource(Ty);
390static const HLSLAttributedResourceType *
404 return RD->isEmpty();
433 Base.getType()->castAsCXXRecordDecl()))
444 assert(RD ==
nullptr &&
445 "there should be at most 1 record by a given name in a scope");
462 Name.append(NameBaseII->
getName());
469 size_t NameLength = Name.size();
478 Name.append(llvm::Twine(suffix).str());
479 II = &AST.
Idents.
get(Name, tok::TokenKind::identifier);
486 Name.truncate(NameLength);
501 if (
const auto *CAT = dyn_cast<ConstantArrayType>(Ty)) {
503 S, CAT->getElementType()->getUnqualifiedDesugaredType());
508 CAT->getSizeModifier(),
509 CAT->getIndexTypeCVRQualifiers())
547 "struct is already HLSL buffer compatible");
561 LS->
addAttr(PackedAttr::CreateImplicit(AST));
565 if (
unsigned NumBases = StructDecl->
getNumBases()) {
566 assert(NumBases == 1 &&
"HLSL supports only one base type");
616 LS->
addAttr(PackedAttr::CreateImplicit(AST));
621 VarDecl *VD = dyn_cast<VarDecl>(D);
637 "host layout field for $Globals decl failed to be created");
654 uint32_t ImplicitBindingOrderID) {
656 HLSLResourceBindingAttr::CreateImplicit(S.
getASTContext(),
"",
"0", {});
657 Attr->setBinding(RT, std::nullopt, 0);
658 Attr->setImplicitBindingOrderID(ImplicitBindingOrderID);
665 BufDecl->setRBraceLoc(RBrace);
682 BufDecl->isCBuffer() ? RegisterType::CBuffer
692 int X,
int Y,
int Z) {
693 if (HLSLNumThreadsAttr *NT = D->
getAttr<HLSLNumThreadsAttr>()) {
694 if (NT->getX() !=
X || NT->getY() != Y || NT->getZ() != Z) {
695 Diag(NT->getLocation(), diag::err_hlsl_attribute_param_mismatch) << AL;
696 Diag(AL.
getLoc(), diag::note_conflicting_attribute);
706 int Min,
int Max,
int Preferred,
707 int SpelledArgsCount) {
708 if (HLSLWaveSizeAttr *WS = D->
getAttr<HLSLWaveSizeAttr>()) {
709 if (WS->getMin() !=
Min || WS->getMax() !=
Max ||
710 WS->getPreferred() != Preferred ||
711 WS->getSpelledArgsCount() != SpelledArgsCount) {
712 Diag(WS->getLocation(), diag::err_hlsl_attribute_param_mismatch) << AL;
713 Diag(AL.
getLoc(), diag::note_conflicting_attribute);
719 Result->setSpelledArgsCount(SpelledArgsCount);
723HLSLVkConstantIdAttr *
729 Diag(AL.
getLoc(), diag::warn_attribute_ignored) << AL;
737 Diag(VD->getLocation(), diag::err_specialization_const);
741 if (!VD->getType().isConstQualified()) {
742 Diag(VD->getLocation(), diag::err_specialization_const);
746 if (HLSLVkConstantIdAttr *CI = D->
getAttr<HLSLVkConstantIdAttr>()) {
747 if (CI->getId() != Id) {
748 Diag(CI->getLocation(), diag::err_hlsl_attribute_param_mismatch) << AL;
749 Diag(AL.
getLoc(), diag::note_conflicting_attribute);
754 HLSLVkConstantIdAttr *
Result =
761 llvm::Triple::EnvironmentType ShaderType) {
762 if (HLSLShaderAttr *NT = D->
getAttr<HLSLShaderAttr>()) {
763 if (NT->getType() != ShaderType) {
764 Diag(NT->getLocation(), diag::err_hlsl_attribute_param_mismatch) << AL;
765 Diag(AL.
getLoc(), diag::note_conflicting_attribute);
769 return HLSLShaderAttr::Create(
getASTContext(), ShaderType, AL);
772HLSLParamModifierAttr *
774 HLSLParamModifierAttr::Spelling Spelling) {
777 if (HLSLParamModifierAttr *PA = D->
getAttr<HLSLParamModifierAttr>()) {
778 if ((PA->isIn() && Spelling == HLSLParamModifierAttr::Keyword_out) ||
779 (PA->isOut() && Spelling == HLSLParamModifierAttr::Keyword_in)) {
780 D->
dropAttr<HLSLParamModifierAttr>();
782 return HLSLParamModifierAttr::Create(
784 HLSLParamModifierAttr::Keyword_inout);
786 Diag(AL.
getLoc(), diag::err_hlsl_duplicate_parameter_modifier) << AL;
787 Diag(PA->getLocation(), diag::note_conflicting_attribute);
813 if (HLSLShaderAttr::isValidShaderType(Env) && Env != llvm::Triple::Library) {
814 if (
const auto *Shader = FD->
getAttr<HLSLShaderAttr>()) {
817 if (Shader->getType() != Env) {
818 Diag(Shader->getLocation(), diag::err_hlsl_entry_shader_attr_mismatch)
830 case llvm::Triple::UnknownEnvironment:
831 case llvm::Triple::Library:
833 case llvm::Triple::RootSignature:
834 llvm_unreachable(
"rootsig environment has no functions");
836 llvm_unreachable(
"Unhandled environment in triple");
842 HLSLAppliedSemanticAttr *Semantic,
847 const auto *ShaderAttr = FD->
getAttr<HLSLShaderAttr>();
848 assert(ShaderAttr &&
"Entry point has no shader attribute");
849 llvm::Triple::EnvironmentType ST = ShaderAttr->getType();
850 auto SemanticName = Semantic->getSemanticName().upper();
855 if (SemanticName ==
"SV_POSITION") {
856 return (ST == llvm::Triple::Vertex && !IsInput) ||
857 (ST == llvm::Triple::Pixel && IsInput);
859 if (SemanticName ==
"SV_VERTEXID")
865bool SemaHLSL::determineActiveSemanticOnScalar(
FunctionDecl *FD,
868 SemanticInfo &ActiveSemantic,
869 SemaHLSL::SemanticContext &SC) {
870 if (ActiveSemantic.Semantic ==
nullptr) {
871 ActiveSemantic.Semantic = D->
getAttr<HLSLParsedSemanticAttr>();
872 if (ActiveSemantic.Semantic)
873 ActiveSemantic.Index = ActiveSemantic.Semantic->getSemanticIndex();
876 if (!ActiveSemantic.Semantic) {
882 HLSLAppliedSemanticAttr(
getASTContext(), *ActiveSemantic.Semantic,
883 ActiveSemantic.Semantic->getAttrName()->getName(),
884 ActiveSemantic.Index.value_or(0));
888 checkSemanticAnnotation(FD, D, A, SC);
889 OutputDecl->addAttr(A);
891 unsigned Location = ActiveSemantic.Index.value_or(0);
894 SC.CurrentIOType & IOType::In)) {
895 bool HasVkLocation =
false;
896 if (
auto *A = D->getAttr<HLSLVkLocationAttr>()) {
897 HasVkLocation = true;
898 Location = A->getLocation();
901 if (SC.UsesExplicitVkLocations.value_or(HasVkLocation) != HasVkLocation) {
902 Diag(D->getLocation(), diag::err_hlsl_semantic_partial_explicit_indexing);
905 SC.UsesExplicitVkLocations = HasVkLocation;
908 const ConstantArrayType *AT = dyn_cast<ConstantArrayType>(D->getType());
909 unsigned ElementCount = AT ? AT->
getZExtSize() : 1;
910 ActiveSemantic.Index = Location + ElementCount;
912 Twine BaseName = Twine(ActiveSemantic.Semantic->getAttrName()->getName());
913 for (
unsigned I = 0; I < ElementCount; ++I) {
914 Twine VariableName = BaseName.concat(Twine(Location + I));
916 auto [_, Inserted] = SC.ActiveSemantics.insert(VariableName.str());
918 Diag(D->getLocation(), diag::err_hlsl_semantic_index_overlap)
919 << VariableName.str();
930 SemanticInfo &ActiveSemantic,
931 SemaHLSL::SemanticContext &SC) {
932 if (ActiveSemantic.Semantic ==
nullptr) {
933 ActiveSemantic.Semantic = D->
getAttr<HLSLParsedSemanticAttr>();
934 if (ActiveSemantic.Semantic)
935 ActiveSemantic.Index = ActiveSemantic.Semantic->getSemanticIndex();
941 const RecordType *RT = dyn_cast<RecordType>(T);
943 return determineActiveSemanticOnScalar(FD, OutputDecl, D, ActiveSemantic,
946 const RecordDecl *RD = RT->getDecl();
947 for (FieldDecl *Field : RD->
fields()) {
948 SemanticInfo Info = ActiveSemantic;
949 if (!determineActiveSemantic(FD, OutputDecl, Field, Info, SC)) {
950 Diag(
Field->getLocation(), diag::note_hlsl_semantic_used_here) <<
Field;
953 if (ActiveSemantic.Semantic)
954 ActiveSemantic = Info;
961 const auto *ShaderAttr = FD->
getAttr<HLSLShaderAttr>();
962 assert(ShaderAttr &&
"Entry point has no shader attribute");
963 llvm::Triple::EnvironmentType ST = ShaderAttr->getType();
967 case llvm::Triple::Pixel:
968 case llvm::Triple::Vertex:
969 case llvm::Triple::Geometry:
970 case llvm::Triple::Hull:
971 case llvm::Triple::Domain:
972 case llvm::Triple::RayGeneration:
973 case llvm::Triple::Intersection:
974 case llvm::Triple::AnyHit:
975 case llvm::Triple::ClosestHit:
976 case llvm::Triple::Miss:
977 case llvm::Triple::Callable:
978 if (
const auto *NT = FD->
getAttr<HLSLNumThreadsAttr>()) {
979 diagnoseAttrStageMismatch(NT, ST,
980 {llvm::Triple::Compute,
981 llvm::Triple::Amplification,
982 llvm::Triple::Mesh});
985 if (
const auto *WS = FD->
getAttr<HLSLWaveSizeAttr>()) {
986 diagnoseAttrStageMismatch(WS, ST,
987 {llvm::Triple::Compute,
988 llvm::Triple::Amplification,
989 llvm::Triple::Mesh});
994 case llvm::Triple::Compute:
995 case llvm::Triple::Amplification:
996 case llvm::Triple::Mesh:
997 if (!FD->
hasAttr<HLSLNumThreadsAttr>()) {
999 << llvm::Triple::getEnvironmentTypeName(ST);
1002 if (
const auto *WS = FD->
getAttr<HLSLWaveSizeAttr>()) {
1003 if (Ver < VersionTuple(6, 6)) {
1004 Diag(WS->getLocation(), diag::err_hlsl_attribute_in_wrong_shader_model)
1007 }
else if (WS->getSpelledArgsCount() > 1 && Ver < VersionTuple(6, 8)) {
1010 diag::err_hlsl_attribute_number_arguments_insufficient_shader_model)
1011 << WS << WS->getSpelledArgsCount() <<
"6.8";
1016 case llvm::Triple::RootSignature:
1017 llvm_unreachable(
"rootsig environment has no function entry point");
1019 llvm_unreachable(
"Unhandled environment in triple");
1022 SemaHLSL::SemanticContext InputSC = {};
1023 InputSC.CurrentIOType = IOType::In;
1026 SemanticInfo ActiveSemantic;
1027 ActiveSemantic.Semantic = Param->getAttr<HLSLParsedSemanticAttr>();
1028 if (ActiveSemantic.Semantic)
1029 ActiveSemantic.Index = ActiveSemantic.Semantic->getSemanticIndex();
1032 if (!determineActiveSemantic(FD, Param, Param, ActiveSemantic, InputSC)) {
1033 Diag(Param->getLocation(), diag::note_previous_decl) << Param;
1038 SemanticInfo ActiveSemantic;
1039 SemaHLSL::SemanticContext OutputSC = {};
1040 OutputSC.CurrentIOType = IOType::Out;
1041 ActiveSemantic.Semantic = FD->
getAttr<HLSLParsedSemanticAttr>();
1042 if (ActiveSemantic.Semantic)
1043 ActiveSemantic.Index = ActiveSemantic.Semantic->getSemanticIndex();
1045 determineActiveSemantic(FD, FD, FD, ActiveSemantic, OutputSC);
1048void SemaHLSL::checkSemanticAnnotation(
1050 const HLSLAppliedSemanticAttr *SemanticAttr,
const SemanticContext &SC) {
1051 auto *ShaderAttr = EntryPoint->
getAttr<HLSLShaderAttr>();
1052 assert(ShaderAttr &&
"Entry point has no shader attribute");
1053 llvm::Triple::EnvironmentType ST = ShaderAttr->getType();
1055 auto SemanticName = SemanticAttr->getSemanticName().upper();
1056 if (SemanticName ==
"SV_DISPATCHTHREADID" ||
1057 SemanticName ==
"SV_GROUPINDEX" || SemanticName ==
"SV_GROUPTHREADID" ||
1058 SemanticName ==
"SV_GROUPID") {
1060 if (ST != llvm::Triple::Compute)
1061 diagnoseSemanticStageMismatch(SemanticAttr, ST, SC.CurrentIOType,
1062 {{llvm::Triple::Compute, IOType::In}});
1064 if (SemanticAttr->getSemanticIndex() != 0) {
1065 std::string PrettyName =
1066 "'" + SemanticAttr->getSemanticName().str() +
"'";
1067 Diag(SemanticAttr->getLoc(),
1068 diag::err_hlsl_semantic_indexing_not_supported)
1074 if (SemanticName ==
"SV_POSITION") {
1077 diagnoseSemanticStageMismatch(SemanticAttr, ST, SC.CurrentIOType,
1078 {{llvm::Triple::Vertex, IOType::InOut},
1079 {llvm::Triple::Pixel, IOType::In}});
1082 if (SemanticName ==
"SV_VERTEXID") {
1083 diagnoseSemanticStageMismatch(SemanticAttr, ST, SC.CurrentIOType,
1084 {{llvm::Triple::Vertex, IOType::In}});
1088 if (SemanticName ==
"SV_TARGET") {
1089 diagnoseSemanticStageMismatch(SemanticAttr, ST, SC.CurrentIOType,
1090 {{llvm::Triple::Pixel, IOType::Out}});
1096 if (SemanticAttr->getAttrName()->getName().starts_with_insensitive(
"SV_"))
1097 llvm_unreachable(
"Unknown SemanticAttr");
1100void SemaHLSL::diagnoseAttrStageMismatch(
1101 const Attr *A, llvm::Triple::EnvironmentType Stage,
1102 std::initializer_list<llvm::Triple::EnvironmentType> AllowedStages) {
1103 SmallVector<StringRef, 8> StageStrings;
1104 llvm::transform(AllowedStages, std::back_inserter(StageStrings),
1105 [](llvm::Triple::EnvironmentType ST) {
1107 HLSLShaderAttr::ConvertEnvironmentTypeToStr(ST));
1109 Diag(A->
getLoc(), diag::err_hlsl_attr_unsupported_in_stage)
1110 << A->
getAttrName() << llvm::Triple::getEnvironmentTypeName(Stage)
1111 << (AllowedStages.size() != 1) << join(StageStrings,
", ");
1114void SemaHLSL::diagnoseSemanticStageMismatch(
1115 const Attr *A, llvm::Triple::EnvironmentType Stage, IOType CurrentIOType,
1116 std::initializer_list<SemanticStageInfo> Allowed) {
1118 for (
auto &Case : Allowed) {
1119 if (Case.Stage != Stage)
1122 if (CurrentIOType & Case.AllowedIOTypesMask)
1125 SmallVector<std::string, 8> ValidCases;
1127 Allowed, std::back_inserter(ValidCases), [](SemanticStageInfo Case) {
1128 SmallVector<std::string, 2> ValidType;
1129 if (Case.AllowedIOTypesMask & IOType::In)
1130 ValidType.push_back(
"input");
1131 if (Case.AllowedIOTypesMask & IOType::Out)
1132 ValidType.push_back(
"output");
1134 HLSLShaderAttr::ConvertEnvironmentTypeToStr(Case.Stage)) +
1135 " " + join(ValidType,
"/");
1137 Diag(A->
getLoc(), diag::err_hlsl_semantic_unsupported_iotype_for_stage)
1138 << A->
getAttrName() << (CurrentIOType & IOType::In ?
"input" :
"output")
1139 << llvm::Triple::getEnvironmentTypeName(Case.Stage)
1140 << join(ValidCases,
", ");
1144 SmallVector<StringRef, 8> StageStrings;
1146 Allowed, std::back_inserter(StageStrings), [](SemanticStageInfo Case) {
1148 HLSLShaderAttr::ConvertEnvironmentTypeToStr(Case.Stage));
1151 Diag(A->
getLoc(), diag::err_hlsl_attr_unsupported_in_stage)
1152 << A->
getAttrName() << llvm::Triple::getEnvironmentTypeName(Stage)
1153 << (Allowed.size() != 1) << join(StageStrings,
", ");
1156template <CastKind Kind>
1159 Ty = VTy->getElementType();
1164template <CastKind Kind>
1176 if (LHSFloat && RHSFloat) {
1204 if (LHSSigned == RHSSigned) {
1205 if (IsCompAssign || IntOrder >= 0)
1213 if (IntOrder != (LHSSigned ? 1 : -1)) {
1214 if (IsCompAssign || RHSSigned)
1222 if (Ctx.getIntWidth(LElTy) != Ctx.getIntWidth(RElTy)) {
1223 if (IsCompAssign || LHSSigned)
1239 QualType ElTy = Ctx.getCorrespondingUnsignedType(LHSSigned ? LElTy : RElTy);
1240 QualType NewTy = Ctx.getExtVectorType(
1250 return CK_FloatingCast;
1252 return CK_IntegralCast;
1254 return CK_IntegralToFloating;
1256 return CK_FloatingToIntegral;
1262 bool IsCompAssign) {
1269 if (!LVecTy && IsCompAssign) {
1271 RHS =
SemaRef.ImpCastExprToType(RHS.
get(), RElTy, CK_HLSLVectorTruncation);
1273 if (Ctx.hasSameUnqualifiedType(LHSType, RHSType))
1275 RHS =
SemaRef.ImpCastExprToType(RHS.
get(), LHSType,
1280 unsigned EndSz = std::numeric_limits<unsigned>::max();
1283 LSz = EndSz = LVecTy->getNumElements();
1286 assert(EndSz != std::numeric_limits<unsigned>::max() &&
1287 "one of the above should have had a value");
1291 if (IsCompAssign && LSz != EndSz) {
1293 diag::err_hlsl_vector_compound_assignment_truncation)
1294 << LHSType << RHSType;
1300 if (!IsCompAssign && LVecTy && LVecTy->getNumElements() > EndSz)
1305 if (!IsCompAssign && !LVecTy)
1309 if (Ctx.hasSameUnqualifiedType(LHSType, RHSType))
1310 return Ctx.getCommonSugaredType(LHSType, RHSType);
1318 LElTy, RElTy, IsCompAssign);
1321 "HLSL Vectors can only contain integer or floating point types");
1323 LElTy, RElTy, IsCompAssign);
1328 assert((Opc == BO_LOr || Opc == BO_LAnd) &&
1329 "Called with non-logical operator");
1331 llvm::raw_svector_ostream OS(Buff);
1333 StringRef NewFnName = Opc == BO_LOr ?
"or" :
"and";
1334 OS << NewFnName <<
"(";
1344std::pair<IdentifierInfo *, bool>
1347 std::string IdStr =
"__hlsl_rootsig_decl_" + std::to_string(Hash);
1354 return {DeclIdent,
Found};
1365 for (
auto &RootSigElement : RootElements)
1366 Elements.push_back(RootSigElement.getElement());
1370 DeclIdent,
SemaRef.getLangOpts().HLSLRootSigVer, Elements);
1372 SignatureDecl->setImplicit();
1378 if (RootSigOverrideIdent) {
1381 if (
SemaRef.LookupQualifiedName(R, DC))
1382 return dyn_cast<HLSLRootSignatureDecl>(R.getFoundDecl());
1390struct PerVisibilityBindingChecker {
1393 std::array<llvm::hlsl::BindingInfoBuilder, 8> Builders;
1397 llvm::dxbc::ShaderVisibility Vis;
1402 PerVisibilityBindingChecker(
SemaHLSL *S) : S(S) {}
1404 void trackBinding(llvm::dxbc::ShaderVisibility
Visibility,
1405 llvm::dxil::ResourceClass RC, uint32_t Space,
1406 uint32_t LowerBound, uint32_t UpperBound,
1407 const hlsl::RootSignatureElement *Elem) {
1409 assert(BuilderIndex < Builders.size() &&
1410 "Not enough builders for visibility type");
1411 Builders[BuilderIndex].trackBinding(RC, Space, LowerBound, UpperBound,
1412 static_cast<const void *
>(Elem));
1414 static_assert(llvm::to_underlying(llvm::dxbc::ShaderVisibility::All) == 0,
1415 "'All' visibility must come first");
1416 if (
Visibility == llvm::dxbc::ShaderVisibility::All)
1417 for (
size_t I = 1, E = Builders.size(); I < E; ++I)
1418 Builders[I].trackBinding(RC, Space, LowerBound, UpperBound,
1419 static_cast<const void *
>(Elem));
1421 ElemInfoMap.push_back({Elem,
Visibility,
false});
1424 ElemInfo &
getInfo(
const hlsl::RootSignatureElement *Elem) {
1425 auto It = llvm::lower_bound(
1427 [](
const auto &LHS,
const auto &RHS) {
return LHS.Elem < RHS; });
1428 assert(It->Elem == Elem &&
"Element not in map");
1432 bool checkOverlap() {
1433 llvm::sort(ElemInfoMap, [](
const auto &LHS,
const auto &RHS) {
1434 return LHS.Elem < RHS.Elem;
1437 bool HadOverlap =
false;
1439 using llvm::hlsl::BindingInfoBuilder;
1440 auto ReportOverlap = [
this,
1441 &HadOverlap](
const BindingInfoBuilder &Builder,
1442 const llvm::hlsl::Binding &Reported) {
1446 static_cast<const hlsl::RootSignatureElement *
>(Reported.Cookie);
1447 const llvm::hlsl::Binding &
Previous = Builder.findOverlapping(Reported);
1448 const auto *PrevElem =
1449 static_cast<const hlsl::RootSignatureElement *
>(
Previous.Cookie);
1451 ElemInfo &Info =
getInfo(Elem);
1456 Info.Diagnosed =
true;
1458 ElemInfo &PrevInfo =
getInfo(PrevElem);
1459 llvm::dxbc::ShaderVisibility CommonVis =
1460 Info.Vis == llvm::dxbc::ShaderVisibility::All ? PrevInfo.Vis
1463 this->S->
Diag(Elem->
getLocation(), diag::err_hlsl_resource_range_overlap)
1464 << llvm::to_underlying(Reported.RC) << Reported.LowerBound
1465 << Reported.isUnbounded() << Reported.UpperBound
1470 this->S->
Diag(PrevElem->getLocation(),
1471 diag::note_hlsl_resource_range_here);
1474 for (BindingInfoBuilder &Builder : Builders)
1475 Builder.calculateBindingInfo(ReportOverlap);
1499 if (
const auto *ResTy =
1500 SecondField->
getType()->
getAs<HLSLAttributedResourceType>()) {
1501 return ResTy->getAttrs().IsCounter;
1509 bool HadError =
false;
1510 auto ReportError = [
this, &HadError](
SourceLocation Loc, uint32_t LowerBound,
1511 uint32_t UpperBound) {
1513 this->
Diag(Loc, diag::err_hlsl_invalid_rootsig_value)
1514 << LowerBound << UpperBound;
1521 this->
Diag(Loc, diag::err_hlsl_invalid_rootsig_value)
1522 << llvm::formatv(
"{0:f}", LowerBound).sstr<6>()
1523 << llvm::formatv(
"{0:f}", UpperBound).sstr<6>();
1526 auto VerifyRegister = [ReportError](
SourceLocation Loc, uint32_t Register) {
1527 if (!llvm::hlsl::rootsig::verifyRegisterValue(Register))
1528 ReportError(Loc, 0, 0xfffffffe);
1531 auto VerifySpace = [ReportError](
SourceLocation Loc, uint32_t Space) {
1532 if (!llvm::hlsl::rootsig::verifyRegisterSpace(Space))
1533 ReportError(Loc, 0, 0xffffffef);
1536 const uint32_t Version =
1537 llvm::to_underlying(
SemaRef.getLangOpts().HLSLRootSigVer);
1538 const uint32_t VersionEnum = Version - 1;
1539 auto ReportFlagError = [
this, &HadError, VersionEnum](
SourceLocation Loc) {
1541 this->
Diag(Loc, diag::err_hlsl_invalid_rootsig_flag)
1548 const llvm::hlsl::rootsig::RootElement &Elem = RootSigElem.
getElement();
1549 if (
const auto *Descriptor =
1550 std::get_if<llvm::hlsl::rootsig::RootDescriptor>(&Elem)) {
1551 VerifyRegister(Loc, Descriptor->Reg.Number);
1552 VerifySpace(Loc, Descriptor->Space);
1554 if (!llvm::hlsl::rootsig::verifyRootDescriptorFlag(Version,
1556 ReportFlagError(Loc);
1557 }
else if (
const auto *Constants =
1558 std::get_if<llvm::hlsl::rootsig::RootConstants>(&Elem)) {
1559 VerifyRegister(Loc, Constants->Reg.Number);
1560 VerifySpace(Loc, Constants->Space);
1561 }
else if (
const auto *Sampler =
1562 std::get_if<llvm::hlsl::rootsig::StaticSampler>(&Elem)) {
1563 VerifyRegister(Loc, Sampler->Reg.Number);
1564 VerifySpace(Loc, Sampler->Space);
1567 "By construction, parseFloatParam can't produce a NaN from a "
1568 "float_literal token");
1570 if (!llvm::hlsl::rootsig::verifyMaxAnisotropy(Sampler->MaxAnisotropy))
1571 ReportError(Loc, 0, 16);
1572 if (!llvm::hlsl::rootsig::verifyMipLODBias(Sampler->MipLODBias))
1573 ReportFloatError(Loc, -16.f, 15.99f);
1574 }
else if (
const auto *Clause =
1575 std::get_if<llvm::hlsl::rootsig::DescriptorTableClause>(
1577 VerifyRegister(Loc, Clause->Reg.Number);
1578 VerifySpace(Loc, Clause->Space);
1580 if (!llvm::hlsl::rootsig::verifyNumDescriptors(Clause->NumDescriptors)) {
1584 ReportError(Loc, 1, 0xfffffffe);
1587 if (!llvm::hlsl::rootsig::verifyDescriptorRangeFlag(Version, Clause->Type,
1589 ReportFlagError(Loc);
1593 PerVisibilityBindingChecker BindingChecker(
this);
1594 SmallVector<std::pair<
const llvm::hlsl::rootsig::DescriptorTableClause *,
1599 const llvm::hlsl::rootsig::RootElement &Elem = RootSigElem.
getElement();
1600 if (
const auto *Descriptor =
1601 std::get_if<llvm::hlsl::rootsig::RootDescriptor>(&Elem)) {
1602 uint32_t LowerBound(Descriptor->Reg.Number);
1603 uint32_t UpperBound(LowerBound);
1605 BindingChecker.trackBinding(
1606 Descriptor->Visibility,
1607 static_cast<llvm::dxil::ResourceClass
>(Descriptor->Type),
1608 Descriptor->Space, LowerBound, UpperBound, &RootSigElem);
1609 }
else if (
const auto *Constants =
1610 std::get_if<llvm::hlsl::rootsig::RootConstants>(&Elem)) {
1611 uint32_t LowerBound(Constants->Reg.Number);
1612 uint32_t UpperBound(LowerBound);
1614 BindingChecker.trackBinding(
1615 Constants->Visibility, llvm::dxil::ResourceClass::CBuffer,
1616 Constants->Space, LowerBound, UpperBound, &RootSigElem);
1617 }
else if (
const auto *Sampler =
1618 std::get_if<llvm::hlsl::rootsig::StaticSampler>(&Elem)) {
1619 uint32_t LowerBound(Sampler->Reg.Number);
1620 uint32_t UpperBound(LowerBound);
1622 BindingChecker.trackBinding(
1623 Sampler->Visibility, llvm::dxil::ResourceClass::Sampler,
1624 Sampler->Space, LowerBound, UpperBound, &RootSigElem);
1625 }
else if (
const auto *Clause =
1626 std::get_if<llvm::hlsl::rootsig::DescriptorTableClause>(
1629 UnboundClauses.emplace_back(Clause, &RootSigElem);
1630 }
else if (
const auto *Table =
1631 std::get_if<llvm::hlsl::rootsig::DescriptorTable>(&Elem)) {
1632 assert(UnboundClauses.size() == Table->NumClauses &&
1633 "Number of unbound elements must match the number of clauses");
1634 bool HasAnySampler =
false;
1635 bool HasAnyNonSampler =
false;
1636 uint64_t Offset = 0;
1637 bool IsPrevUnbound =
false;
1638 for (
const auto &[Clause, ClauseElem] : UnboundClauses) {
1640 if (Clause->Type == llvm::dxil::ResourceClass::Sampler)
1641 HasAnySampler =
true;
1643 HasAnyNonSampler =
true;
1645 if (HasAnySampler && HasAnyNonSampler)
1646 Diag(Loc, diag::err_hlsl_invalid_mixed_resources);
1651 if (Clause->NumDescriptors == 0)
1655 Clause->Offset == llvm::hlsl::rootsig::DescriptorTableOffsetAppend;
1657 Offset = Clause->Offset;
1659 uint64_t RangeBound = llvm::hlsl::rootsig::computeRangeBound(
1660 Offset, Clause->NumDescriptors);
1662 if (IsPrevUnbound && IsAppending)
1663 Diag(Loc, diag::err_hlsl_appending_onto_unbound);
1664 else if (!llvm::hlsl::rootsig::verifyNoOverflowedOffset(RangeBound))
1665 Diag(Loc, diag::err_hlsl_offset_overflow) << Offset << RangeBound;
1668 Offset = RangeBound + 1;
1669 IsPrevUnbound = Clause->NumDescriptors ==
1670 llvm::hlsl::rootsig::NumDescriptorsUnbounded;
1673 uint32_t LowerBound(Clause->Reg.Number);
1674 uint32_t UpperBound = llvm::hlsl::rootsig::computeRangeBound(
1675 LowerBound, Clause->NumDescriptors);
1677 BindingChecker.trackBinding(
1679 static_cast<llvm::dxil::ResourceClass
>(Clause->Type), Clause->Space,
1680 LowerBound, UpperBound, ClauseElem);
1682 UnboundClauses.clear();
1686 return BindingChecker.checkOverlap();
1691 Diag(AL.
getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
1696 if (
auto *RS = D->
getAttr<RootSignatureAttr>()) {
1697 if (RS->getSignatureIdent() != Ident) {
1698 Diag(AL.
getLoc(), diag::err_disallowed_duplicate_attribute) << RS;
1702 Diag(AL.
getLoc(), diag::warn_duplicate_attribute_exact) << RS;
1708 if (
auto *SignatureDecl =
1709 dyn_cast<HLSLRootSignatureDecl>(R.getFoundDecl())) {
1716 llvm::VersionTuple SMVersion =
1721 uint32_t ZMax = 1024;
1722 uint32_t ThreadMax = 1024;
1723 if (IsDXIL && SMVersion.getMajor() <= 4) {
1726 }
else if (IsDXIL && SMVersion.getMajor() == 5) {
1736 diag::err_hlsl_numthreads_argument_oor)
1745 diag::err_hlsl_numthreads_argument_oor)
1754 diag::err_hlsl_numthreads_argument_oor)
1759 if (
X * Y * Z > ThreadMax) {
1760 Diag(AL.
getLoc(), diag::err_hlsl_numthreads_invalid) << ThreadMax;
1777 if (SpelledArgsCount == 0 || SpelledArgsCount > 3)
1785 if (SpelledArgsCount > 1 &&
1789 uint32_t Preferred = 0;
1790 if (SpelledArgsCount > 2 &&
1794 if (SpelledArgsCount > 2) {
1797 diag::err_attribute_power_of_two_in_range)
1798 << AL << llvm::dxil::MinWaveSize << llvm::dxil::MaxWaveSize
1803 if (Preferred < Min || Preferred >
Max) {
1805 diag::err_attribute_power_of_two_in_range)
1806 << AL <<
Min <<
Max << Preferred;
1809 }
else if (SpelledArgsCount > 1) {
1812 diag::err_attribute_power_of_two_in_range)
1813 << AL << llvm::dxil::MinWaveSize << llvm::dxil::MaxWaveSize <<
Max;
1817 Diag(AL.
getLoc(), diag::err_attribute_argument_invalid) << AL << 1;
1820 Diag(AL.
getLoc(), diag::warn_attr_min_eq_max) << AL;
1825 diag::err_attribute_power_of_two_in_range)
1826 << AL << llvm::dxil::MinWaveSize << llvm::dxil::MaxWaveSize <<
Min;
1831 HLSLWaveSizeAttr *NewAttr =
1860 uint32_t Binding = 0;
1884 if (!T->hasUnsignedIntegerRepresentation() ||
1885 (VT && VT->getNumElements() > 3)) {
1886 Diag(AL.
getLoc(), diag::err_hlsl_attr_invalid_type)
1887 << AL <<
"uint/uint2/uint3";
1896 if (!T->hasFloatingRepresentation() || (VT && VT->getNumElements() > 4)) {
1897 Diag(AL.
getLoc(), diag::err_hlsl_attr_invalid_type)
1898 << AL <<
"float/float1/float2/float3/float4";
1906 std::optional<unsigned> Index) {
1910 QualType ValueType = VD->getType();
1911 if (
auto *FD = dyn_cast<FunctionDecl>(D))
1914 bool IsOutput =
false;
1915 if (HLSLParamModifierAttr *MA = D->
getAttr<HLSLParamModifierAttr>()) {
1922 if (SemanticName ==
"SV_DISPATCHTHREADID") {
1925 Diag(AL.
getLoc(), diag::err_hlsl_semantic_output_not_supported) << AL;
1926 if (Index.has_value())
1927 Diag(AL.
getLoc(), diag::err_hlsl_semantic_indexing_not_supported) << AL;
1932 if (SemanticName ==
"SV_GROUPINDEX") {
1934 Diag(AL.
getLoc(), diag::err_hlsl_semantic_output_not_supported) << AL;
1935 if (Index.has_value())
1936 Diag(AL.
getLoc(), diag::err_hlsl_semantic_indexing_not_supported) << AL;
1941 if (SemanticName ==
"SV_GROUPTHREADID") {
1944 Diag(AL.
getLoc(), diag::err_hlsl_semantic_output_not_supported) << AL;
1945 if (Index.has_value())
1946 Diag(AL.
getLoc(), diag::err_hlsl_semantic_indexing_not_supported) << AL;
1951 if (SemanticName ==
"SV_GROUPID") {
1954 Diag(AL.
getLoc(), diag::err_hlsl_semantic_output_not_supported) << AL;
1955 if (Index.has_value())
1956 Diag(AL.
getLoc(), diag::err_hlsl_semantic_indexing_not_supported) << AL;
1961 if (SemanticName ==
"SV_POSITION") {
1962 const auto *VT = ValueType->getAs<
VectorType>();
1963 if (!ValueType->hasFloatingRepresentation() ||
1964 (VT && VT->getNumElements() > 4))
1965 Diag(AL.
getLoc(), diag::err_hlsl_attr_invalid_type)
1966 << AL <<
"float/float1/float2/float3/float4";
1971 if (SemanticName ==
"SV_VERTEXID") {
1972 uint64_t SizeInBits =
SemaRef.Context.getTypeSize(ValueType);
1973 if (!ValueType->isUnsignedIntegerType() || SizeInBits != 32)
1974 Diag(AL.
getLoc(), diag::err_hlsl_attr_invalid_type) << AL <<
"uint";
1979 if (SemanticName ==
"SV_TARGET") {
1980 const auto *VT = ValueType->getAs<
VectorType>();
1981 if (!ValueType->hasFloatingRepresentation() ||
1982 (VT && VT->getNumElements() > 4))
1983 Diag(AL.
getLoc(), diag::err_hlsl_attr_invalid_type)
1984 << AL <<
"float/float1/float2/float3/float4";
1989 Diag(AL.
getLoc(), diag::err_hlsl_unknown_semantic) << AL;
1993 uint32_t IndexValue(0), ExplicitIndex(0);
1996 assert(0 &&
"HLSLUnparsedSemantic is expected to have 2 int arguments.");
1998 assert(IndexValue > 0 ? ExplicitIndex :
true);
1999 std::optional<unsigned> Index =
2000 ExplicitIndex ? std::optional<unsigned>(IndexValue) : std::nullopt;
2010 Diag(AL.
getLoc(), diag::err_hlsl_attr_invalid_ast_node)
2011 << AL <<
"shader constant in a constant buffer";
2015 uint32_t SubComponent;
2025 bool IsAggregateTy = (T->isArrayType() || T->isStructureType());
2030 if (IsAggregateTy) {
2031 Diag(AL.
getLoc(), diag::err_hlsl_invalid_register_or_packoffset);
2035 if ((Component * 32 + Size) > 128) {
2036 Diag(AL.
getLoc(), diag::err_hlsl_packoffset_cross_reg_boundary);
2041 EltTy = VT->getElementType();
2043 if (Align > 32 && Component == 1) {
2046 Diag(AL.
getLoc(), diag::err_hlsl_packoffset_alignment_mismatch)
2060 if (!
SemaRef.checkStringLiteralArgumentAttr(AL, 0, Str, &ArgLoc))
2063 llvm::Triple::EnvironmentType ShaderType;
2064 if (!HLSLShaderAttr::ConvertStrToEnvironmentType(Str, ShaderType)) {
2065 Diag(AL.
getLoc(), diag::warn_attribute_type_not_supported)
2066 << AL << Str << ArgLoc;
2080 assert(AttrList.size() &&
"expected list of resource attributes");
2087 HLSLAttributedResourceType::Attributes ResAttrs;
2089 bool HasResourceClass =
false;
2090 bool HasResourceDimension =
false;
2091 for (
const Attr *A : AttrList) {
2096 case attr::HLSLResourceClass: {
2098 if (HasResourceClass) {
2100 ? diag::warn_duplicate_attribute_exact
2101 : diag::warn_duplicate_attribute)
2105 ResAttrs.ResourceClass = RC;
2106 HasResourceClass =
true;
2109 case attr::HLSLResourceDimension: {
2110 llvm::dxil::ResourceDimension RD =
2112 if (HasResourceDimension) {
2114 ? diag::warn_duplicate_attribute_exact
2115 : diag::warn_duplicate_attribute)
2119 ResAttrs.ResourceDimension = RD;
2120 HasResourceDimension =
true;
2124 if (ResAttrs.IsROV) {
2128 ResAttrs.IsROV =
true;
2130 case attr::HLSLRawBuffer:
2131 if (ResAttrs.RawBuffer) {
2135 ResAttrs.RawBuffer =
true;
2137 case attr::HLSLIsCounter:
2138 if (ResAttrs.IsCounter) {
2142 ResAttrs.IsCounter =
true;
2144 case attr::HLSLContainedType: {
2147 if (!ContainedTy.
isNull()) {
2149 ? diag::warn_duplicate_attribute_exact
2150 : diag::warn_duplicate_attribute)
2159 llvm_unreachable(
"unhandled resource attribute type");
2163 if (!HasResourceClass) {
2164 S.
Diag(AttrList.back()->getRange().getEnd(),
2165 diag::err_hlsl_missing_resource_class);
2170 Wrapped, ContainedTy, ResAttrs);
2172 if (LocInfo && ContainedTyInfo) {
2185 if (!T->isHLSLResourceType()) {
2186 Diag(AL.
getLoc(), diag::err_hlsl_attribute_needs_intangible_type)
2201 AttributeCommonInfo::AS_CXX11, 0, false ,
2206 case ParsedAttr::AT_HLSLResourceClass: {
2208 Diag(AL.
getLoc(), diag::err_attribute_argument_type)
2219 if (!HLSLResourceClassAttr::ConvertStrToResourceClass(Identifier, RC)) {
2220 Diag(ArgLoc, diag::warn_attribute_type_not_supported)
2221 <<
"ResourceClass" << Identifier;
2224 A = HLSLResourceClassAttr::Create(
getASTContext(), RC, ACI);
2228 case ParsedAttr::AT_HLSLResourceDimension: {
2229 StringRef Identifier;
2231 if (!
SemaRef.checkStringLiteralArgumentAttr(AL, 0, Identifier, &ArgLoc))
2235 llvm::dxil::ResourceDimension RD;
2236 if (!HLSLResourceDimensionAttr::ConvertStrToResourceDimension(Identifier,
2238 Diag(ArgLoc, diag::warn_attribute_type_not_supported)
2239 <<
"ResourceDimension" << Identifier;
2242 A = HLSLResourceDimensionAttr::Create(
getASTContext(), RD, ACI);
2246 case ParsedAttr::AT_HLSLROV:
2250 case ParsedAttr::AT_HLSLRawBuffer:
2254 case ParsedAttr::AT_HLSLIsCounter:
2258 case ParsedAttr::AT_HLSLContainedType: {
2260 Diag(AL.
getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
2266 assert(TSI &&
"no type source info for attribute argument");
2268 diag::err_incomplete_type))
2270 A = HLSLContainedTypeAttr::Create(
getASTContext(), TSI, ACI);
2275 llvm_unreachable(
"unhandled HLSL attribute");
2278 HLSLResourcesTypeAttrs.emplace_back(A);
2284 if (!HLSLResourcesTypeAttrs.size())
2290 HLSLResourcesTypeAttrs, QT, &LocInfo)) {
2291 const HLSLAttributedResourceType *RT =
2298 LocsForHLSLAttributedResources.insert(std::pair(RT, LocInfo));
2300 HLSLResourcesTypeAttrs.clear();
2308 auto I = LocsForHLSLAttributedResources.find(RT);
2309 if (I != LocsForHLSLAttributedResources.end()) {
2310 LocInfo = I->second;
2311 LocsForHLSLAttributedResources.erase(I);
2320void SemaHLSL::collectResourceBindingsOnUserRecordDecl(
const VarDecl *VD,
2321 const RecordType *RT) {
2322 const RecordDecl *RD = RT->getDecl()->getDefinitionOrSelf();
2329 "incomplete arrays inside user defined types are not supported");
2338 if (
const HLSLAttributedResourceType *AttrResType =
2339 HLSLAttributedResourceType::findHandleTypeOnResource(Ty)) {
2344 Bindings.addDeclBindingInfo(VD, RC);
2345 }
else if (
const RecordType *RT = dyn_cast<RecordType>(Ty)) {
2351 collectResourceBindingsOnUserRecordDecl(VD, RT);
2363 bool SpecifiedSpace) {
2364 int RegTypeNum =
static_cast<int>(RegType);
2367 if (D->
hasAttr<HLSLGroupSharedAddressSpaceAttr>()) {
2368 S.
Diag(ArgLoc, diag::err_hlsl_binding_type_mismatch) << RegTypeNum;
2373 if (
HLSLBufferDecl *CBufferOrTBuffer = dyn_cast<HLSLBufferDecl>(D)) {
2374 ResourceClass RC = CBufferOrTBuffer->isCBuffer() ? ResourceClass::CBuffer
2375 : ResourceClass::SRV;
2385 assert(
isa<VarDecl>(D) &&
"D is expected to be VarDecl or HLSLBufferDecl");
2389 if (
const HLSLAttributedResourceType *AttrResType =
2390 HLSLAttributedResourceType::findHandleTypeOnResource(
2407 if (SpecifiedSpace && !DeclaredInCOrTBuffer)
2408 S.
Diag(ArgLoc, diag::err_hlsl_space_on_global_constant);
2413 if (RegType == RegisterType::CBuffer)
2414 S.
Diag(ArgLoc, diag::warn_hlsl_deprecated_register_type_b);
2415 else if (RegType != RegisterType::C)
2416 S.
Diag(ArgLoc, diag::err_hlsl_binding_type_mismatch) << RegTypeNum;
2420 if (RegType == RegisterType::C)
2421 S.
Diag(ArgLoc, diag::warn_hlsl_register_type_c_packoffset);
2423 S.
Diag(ArgLoc, diag::err_hlsl_binding_type_mismatch) << RegTypeNum;
2433 S.
Diag(ArgLoc, diag::err_hlsl_binding_type_mismatch) << RegTypeNum;
2441 bool RegisterTypesDetected[5] = {
false};
2442 RegisterTypesDetected[
static_cast<int>(regType)] =
true;
2445 if (HLSLResourceBindingAttr *
attr =
2446 dyn_cast<HLSLResourceBindingAttr>(*it)) {
2449 if (RegisterTypesDetected[
static_cast<int>(otherRegType)]) {
2450 int otherRegTypeNum =
static_cast<int>(otherRegType);
2452 diag::err_hlsl_duplicate_register_annotation)
2456 RegisterTypesDetected[
static_cast<int>(otherRegType)] =
true;
2464 bool SpecifiedSpace) {
2469 "expecting VarDecl or HLSLBufferDecl");
2481 const uint64_t &Limit,
2484 uint64_t ArrayCount = 1) {
2489 if (StartSlot > Limit)
2493 if (
const auto *AT = dyn_cast<ArrayType>(T)) {
2496 if (
const auto *CAT = dyn_cast<ConstantArrayType>(AT))
2497 Count = CAT->
getSize().getZExtValue();
2501 ArrayCount * Count);
2505 if (
auto ResTy = dyn_cast<HLSLAttributedResourceType>(T)) {
2508 if (ResTy->getAttrs().ResourceClass != ResClass)
2512 uint64_t EndSlot = StartSlot + ArrayCount - 1;
2513 if (EndSlot > Limit)
2517 StartSlot = EndSlot + 1;
2522 if (
const auto *RT = dyn_cast<RecordType>(T)) {
2525 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
2528 ResClass, Ctx, ArrayCount))
2535 ResClass, Ctx, ArrayCount))
2549 const uint64_t Limit = UINT32_MAX;
2550 if (SlotNum > Limit)
2555 if (RegTy == RegisterType::C || RegTy == RegisterType::I)
2558 if (
VarDecl *VD = dyn_cast<VarDecl>(TheDecl)) {
2559 uint64_t BaseSlot = SlotNum;
2567 return (BaseSlot > Limit);
2574 return (SlotNum > Limit);
2577 llvm_unreachable(
"unexpected decl type");
2581 if (
VarDecl *VD = dyn_cast<VarDecl>(TheDecl)) {
2583 if (
const auto *IAT = dyn_cast<IncompleteArrayType>(Ty))
2584 Ty = IAT->getElementType();
2586 diag::err_incomplete_type))
2590 StringRef Slot =
"";
2591 StringRef Space =
"";
2595 Diag(AL.
getLoc(), diag::err_attribute_argument_type)
2605 Diag(AL.
getLoc(), diag::err_attribute_argument_type)
2611 SpaceLoc = Loc->
getLoc();
2614 if (Str.starts_with(
"space")) {
2616 SpaceLoc = Loc->
getLoc();
2625 std::optional<unsigned> SlotNum;
2626 unsigned SpaceNum = 0;
2629 if (!Slot.empty()) {
2631 Diag(SlotLoc, diag::err_hlsl_binding_type_invalid) << Slot.substr(0, 1);
2634 if (RegType == RegisterType::I) {
2635 Diag(SlotLoc, diag::warn_hlsl_deprecated_register_type_i);
2638 const StringRef SlotNumStr = Slot.substr(1);
2643 if (SlotNumStr.getAsInteger(10, N)) {
2644 Diag(SlotLoc, diag::err_hlsl_unsupported_register_number);
2652 Diag(SlotLoc, diag::err_hlsl_register_number_too_large);
2661 if (!Space.starts_with(
"space")) {
2662 Diag(SpaceLoc, diag::err_hlsl_expected_space) << Space;
2665 StringRef SpaceNumStr = Space.substr(5);
2666 if (SpaceNumStr.getAsInteger(10, SpaceNum)) {
2667 Diag(SpaceLoc, diag::err_hlsl_expected_space) << Space;
2672 if (SlotNum.has_value())
2677 HLSLResourceBindingAttr *NewAttr =
2678 HLSLResourceBindingAttr::Create(
getASTContext(), Slot, Space, AL);
2680 NewAttr->setBinding(RegType, SlotNum, SpaceNum);
2735 llvm::DenseMap<const FunctionDecl *, unsigned> ScannedDecls;
2739 llvm::Triple::EnvironmentType CurrentShaderEnvironment;
2740 unsigned CurrentShaderStageBit;
2745 bool ReportOnlyShaderStageIssues;
2748 void SetShaderStageContext(llvm::Triple::EnvironmentType ShaderType) {
2749 static_assert(
sizeof(
unsigned) >= 4);
2750 assert(HLSLShaderAttr::isValidShaderType(ShaderType));
2751 assert((
unsigned)(ShaderType - llvm::Triple::Pixel) < 31 &&
2752 "ShaderType is too big for this bitmap");
2755 unsigned bitmapIndex = ShaderType - llvm::Triple::Pixel;
2756 CurrentShaderEnvironment = ShaderType;
2757 CurrentShaderStageBit = (1 << bitmapIndex);
2760 void SetUnknownShaderStageContext() {
2761 CurrentShaderEnvironment = llvm::Triple::UnknownEnvironment;
2762 CurrentShaderStageBit = (1 << 31);
2765 llvm::Triple::EnvironmentType GetCurrentShaderEnvironment()
const {
2766 return CurrentShaderEnvironment;
2769 bool InUnknownShaderStageContext()
const {
2770 return CurrentShaderEnvironment == llvm::Triple::UnknownEnvironment;
2774 void AddToScannedFunctions(
const FunctionDecl *FD) {
2775 unsigned &ScannedStages = ScannedDecls[FD];
2776 ScannedStages |= CurrentShaderStageBit;
2779 unsigned GetScannedStages(
const FunctionDecl *FD) {
return ScannedDecls[FD]; }
2781 bool WasAlreadyScannedInCurrentStage(
const FunctionDecl *FD) {
2782 return WasAlreadyScannedInCurrentStage(GetScannedStages(FD));
2785 bool WasAlreadyScannedInCurrentStage(
unsigned ScannerStages) {
2786 return ScannerStages & CurrentShaderStageBit;
2789 static bool NeverBeenScanned(
unsigned ScannedStages) {
2790 return ScannedStages == 0;
2794 void HandleFunctionOrMethodRef(FunctionDecl *FD, Expr *RefExpr);
2795 void CheckDeclAvailability(NamedDecl *D,
const AvailabilityAttr *AA,
2797 const AvailabilityAttr *FindAvailabilityAttr(
const Decl *D);
2798 bool HasMatchingEnvironmentOrNone(
const AvailabilityAttr *AA);
2801 DiagnoseHLSLAvailability(Sema &SemaRef)
2803 CurrentShaderEnvironment(llvm::Triple::UnknownEnvironment),
2804 CurrentShaderStageBit(0), ReportOnlyShaderStageIssues(
false) {}
2807 void RunOnTranslationUnit(
const TranslationUnitDecl *TU);
2808 void RunOnFunction(
const FunctionDecl *FD);
2810 bool VisitDeclRefExpr(DeclRefExpr *DRE)
override {
2811 FunctionDecl *FD = llvm::dyn_cast<FunctionDecl>(DRE->
getDecl());
2813 HandleFunctionOrMethodRef(FD, DRE);
2817 bool VisitMemberExpr(MemberExpr *ME)
override {
2818 FunctionDecl *FD = llvm::dyn_cast<FunctionDecl>(ME->
getMemberDecl());
2820 HandleFunctionOrMethodRef(FD, ME);
2825void DiagnoseHLSLAvailability::HandleFunctionOrMethodRef(
FunctionDecl *FD,
2828 "expected DeclRefExpr or MemberExpr");
2832 if (FD->
hasBody(FDWithBody)) {
2833 if (!WasAlreadyScannedInCurrentStage(FDWithBody))
2834 DeclsToScan.push_back(FDWithBody);
2839 const AvailabilityAttr *AA = FindAvailabilityAttr(FD);
2841 CheckDeclAvailability(
2845void DiagnoseHLSLAvailability::RunOnTranslationUnit(
2854 DeclContextsToScan.push_back(TU);
2856 while (!DeclContextsToScan.empty()) {
2857 const DeclContext *DC = DeclContextsToScan.pop_back_val();
2858 for (
auto &D : DC->
decls()) {
2865 if (llvm::dyn_cast<NamespaceDecl>(D) || llvm::dyn_cast<ExportDecl>(D)) {
2866 DeclContextsToScan.push_back(llvm::dyn_cast<DeclContext>(D));
2871 const FunctionDecl *FD = llvm::dyn_cast<FunctionDecl>(D);
2876 if (HLSLShaderAttr *ShaderAttr = FD->
getAttr<HLSLShaderAttr>()) {
2877 SetShaderStageContext(ShaderAttr->getType());
2886 for (
const auto *Redecl : FD->
redecls()) {
2887 if (Redecl->isInExportDeclContext()) {
2894 SetUnknownShaderStageContext();
2902void DiagnoseHLSLAvailability::RunOnFunction(
const FunctionDecl *FD) {
2903 assert(DeclsToScan.empty() &&
"DeclsToScan should be empty");
2904 DeclsToScan.push_back(FD);
2906 while (!DeclsToScan.empty()) {
2914 const unsigned ScannedStages = GetScannedStages(FD);
2915 if (WasAlreadyScannedInCurrentStage(ScannedStages))
2918 ReportOnlyShaderStageIssues = !NeverBeenScanned(ScannedStages);
2920 AddToScannedFunctions(FD);
2925bool DiagnoseHLSLAvailability::HasMatchingEnvironmentOrNone(
2926 const AvailabilityAttr *AA) {
2931 llvm::Triple::EnvironmentType CurrentEnv = GetCurrentShaderEnvironment();
2932 if (CurrentEnv == llvm::Triple::UnknownEnvironment)
2935 llvm::Triple::EnvironmentType AttrEnv =
2936 AvailabilityAttr::getEnvironmentType(IIEnvironment->
getName());
2938 return CurrentEnv == AttrEnv;
2941const AvailabilityAttr *
2942DiagnoseHLSLAvailability::FindAvailabilityAttr(
const Decl *D) {
2943 AvailabilityAttr
const *PartialMatch =
nullptr;
2947 for (
const auto *A : D->
attrs()) {
2948 if (
const auto *Avail = dyn_cast<AvailabilityAttr>(A)) {
2949 StringRef AttrPlatform = Avail->getPlatform()->getName();
2950 StringRef TargetPlatform =
2954 if (AttrPlatform == TargetPlatform) {
2956 if (HasMatchingEnvironmentOrNone(Avail))
2958 PartialMatch = Avail;
2962 return PartialMatch;
2967void DiagnoseHLSLAvailability::CheckDeclAvailability(
NamedDecl *D,
2968 const AvailabilityAttr *AA,
2987 if (ReportOnlyShaderStageIssues)
2993 if (InUnknownShaderStageContext())
2998 bool EnvironmentMatches = HasMatchingEnvironmentOrNone(AA);
2999 VersionTuple Introduced = AA->getIntroduced();
3008 llvm::StringRef PlatformName(
3011 llvm::StringRef CurrentEnvStr =
3012 llvm::Triple::getEnvironmentTypeName(GetCurrentShaderEnvironment());
3014 llvm::StringRef AttrEnvStr =
3015 AA->getEnvironment() ? AA->getEnvironment()->getName() :
"";
3016 bool UseEnvironment = !AttrEnvStr.empty();
3018 if (EnvironmentMatches) {
3019 SemaRef.
Diag(
Range.getBegin(), diag::warn_hlsl_availability)
3020 <<
Range << D << PlatformName << Introduced.getAsString()
3021 << UseEnvironment << CurrentEnvStr;
3023 SemaRef.
Diag(
Range.getBegin(), diag::warn_hlsl_availability_unavailable)
3027 SemaRef.
Diag(D->
getLocation(), diag::note_partial_availability_specified_here)
3028 << D << PlatformName << Introduced.getAsString()
3030 << UseEnvironment << AttrEnvStr << CurrentEnvStr;
3037 if (!DefaultCBufferDecls.empty()) {
3040 DefaultCBufferDecls);
3043 SemaRef.getCurLexicalContext()->addDecl(DefaultCBuffer);
3047 for (
const Decl *VD : DefaultCBufferDecls) {
3048 const HLSLResourceBindingAttr *RBA =
3049 VD->
getAttr<HLSLResourceBindingAttr>();
3050 if (RBA && RBA->hasRegisterSlot() &&
3051 RBA->getRegisterType() == HLSLResourceBindingAttr::RegisterType::C) {
3058 SemaRef.Consumer.HandleTopLevelDecl(DG);
3060 diagnoseAvailabilityViolations(TU);
3070 TI.
getTriple().getEnvironment() != llvm::Triple::EnvironmentType::Library)
3073 DiagnoseHLSLAvailability(
SemaRef).RunOnTranslationUnit(TU);
3080 for (
unsigned I = 1, N = TheCall->
getNumArgs(); I < N; ++I) {
3083 S->
Diag(TheCall->
getBeginLoc(), diag::err_vec_builtin_incompatible_vector)
3108 for (
unsigned I = 0; I < TheCall->
getNumArgs(); ++I) {
3123 if (!BaseType->isFloat32Type())
3124 return S->
Diag(Loc, diag::err_builtin_invalid_arg_type)
3125 << ArgOrdinal << 5 << 0
3137 if (!BaseType->isHalfType() && !BaseType->isFloat32Type())
3138 return S->
Diag(Loc, diag::err_builtin_invalid_arg_type)
3139 << ArgOrdinal << 5 << 0
3145 unsigned ArgIndex) {
3146 auto *Arg = TheCall->
getArg(ArgIndex);
3148 if (Arg->IgnoreCasts()->isModifiableLvalue(S->
Context, &OrigLoc) ==
3151 S->
Diag(OrigLoc, diag::error_hlsl_inout_lvalue) << Arg << 0;
3161 if (VecTy->getElementType()->isDoubleType())
3162 return S->
Diag(Loc, diag::err_builtin_invalid_arg_type)
3163 << ArgOrdinal << 1 << 0 << 1
3173 return S->
Diag(Loc, diag::err_builtin_invalid_arg_type)
3174 << ArgOrdinal << 5 << 1
3183 if (VecTy->getElementType()->isUnsignedIntegerType())
3186 return S->
Diag(Loc, diag::err_builtin_invalid_arg_type)
3187 << ArgOrdinal << 4 << 3 << 0
3196 return S->
Diag(Loc, diag::err_builtin_invalid_arg_type)
3197 << ArgOrdinal << 5 << 3
3203 unsigned ArgOrdinal,
unsigned Width) {
3206 ArgTy = VTy->getElementType();
3208 uint64_t ElementBitCount =
3210 if (ElementBitCount != Width) {
3212 diag::err_integer_incorrect_bit_count)
3213 << Width << ElementBitCount;
3230 unsigned ArgIndex) {
3239 diag::err_typecheck_expect_scalar_or_vector)
3240 << ArgType << Scalar;
3247 QualType Scalar,
unsigned ArgIndex) {
3258 if (
const auto *VTy = ArgType->getAs<
VectorType>()) {
3271 diag::err_typecheck_expect_scalar_or_vector_or_matrix)
3272 << ArgType << Scalar;
3277 unsigned ArgIndex) {
3282 if (!(ArgType->isScalarType() ||
3283 (VTy && VTy->getElementType()->isScalarType()))) {
3285 diag::err_typecheck_expect_any_scalar_or_vector)
3295 unsigned ArgIndex) {
3297 assert(ArgIndex < TheCall->getNumArgs());
3305 diag::err_typecheck_expect_any_scalar_or_vector)
3330 diag::err_typecheck_call_different_arg_types)
3349 Arg1ScalarTy = VTy->getElementType();
3353 Arg2ScalarTy = VTy->getElementType();
3356 S->
Diag(Arg1->
getBeginLoc(), diag::err_hlsl_builtin_scalar_vector_mismatch)
3357 << 1 << TheCall->
getCallee() << Arg1Ty << Arg2Ty;
3367 if (Arg1Length > 0 && Arg0Length != Arg1Length) {
3369 diag::err_typecheck_vector_lengths_not_equal)
3375 if (Arg2Length > 0 && Arg0Length != Arg2Length) {
3377 diag::err_typecheck_vector_lengths_not_equal)
3390 llvm::function_ref<
bool(
const HLSLAttributedResourceType *ResType)> Check =
3394 const HLSLAttributedResourceType *ResTy =
3398 diag::err_typecheck_expect_hlsl_resource)
3402 if (Check && Check(ResTy)) {
3404 diag::err_invalid_hlsl_resource_type)
3412 QualType BaseType,
unsigned ExpectedCount,
3414 unsigned PassedCount = 1;
3416 PassedCount = VecTy->getNumElements();
3418 if (PassedCount != ExpectedCount) {
3421 S->
Diag(Loc, diag::err_typecheck_convert_incompatible)
3433 [](
const HLSLAttributedResourceType *ResType) {
3434 return ResType->getAttrs().ResourceDimension ==
3435 llvm::dxil::ResourceDimension::Unknown;
3441 [](
const HLSLAttributedResourceType *ResType) {
3442 return ResType->getAttrs().ResourceClass !=
3443 llvm::hlsl::ResourceClass::Sampler;
3451 unsigned ExpectedDim =
3468 unsigned NextIdx = 3;
3474 diag::err_typecheck_convert_incompatible)
3482 Expr *ComponentArg = TheCall->
getArg(NextIdx);
3486 diag::err_typecheck_convert_incompatible)
3493 std::optional<llvm::APSInt> ComponentOpt =
3496 int64_t ComponentVal = ComponentOpt->getSExtValue();
3497 if (ComponentVal != 0) {
3500 assert(ComponentVal >= 0 && ComponentVal <= 3 &&
3501 "The component is not in the expected range.");
3503 diag::err_hlsl_gathercmp_invalid_component)
3513 const HLSLAttributedResourceType *ResourceTy =
3516 unsigned ExpectedDim =
3525 assert(ResourceTy->hasContainedType() &&
3526 "Expecting a contained type for resource with a dimension "
3528 QualType ReturnType = ResourceTy->getContainedType();
3532 S.
Diag(TheCall->
getBeginLoc(), diag::err_hlsl_samplecmp_requires_float);
3538 ReturnType = VecTy->getElementType();
3551 [](
const HLSLAttributedResourceType *ResType) {
3552 return ResType->getAttrs().ResourceDimension ==
3553 llvm::dxil::ResourceDimension::Unknown;
3561 unsigned ExpectedDim =
3570 EltTy = VTy->getElementType();
3585 TheCall->
setType(ResourceTy->getContainedType());
3590 unsigned MinArgs, MaxArgs;
3618 const HLSLAttributedResourceType *ResourceTy =
3620 unsigned ExpectedDim =
3623 unsigned NextIdx = 3;
3632 diag::err_typecheck_convert_incompatible)
3667 diag::err_typecheck_convert_incompatible)
3673 assert(ResourceTy->hasContainedType() &&
3674 "Expecting a contained type for resource with a dimension "
3676 QualType ReturnType = ResourceTy->getContainedType();
3679 S.
Diag(TheCall->
getBeginLoc(), diag::err_hlsl_samplecmp_requires_float);
3692 switch (BuiltinID) {
3693 case Builtin::BI__builtin_hlsl_adduint64: {
3694 if (
SemaRef.checkArgCount(TheCall, 2))
3708 if (NumElementsArg != 2 && NumElementsArg != 4) {
3710 << 1 << 64 << NumElementsArg * 32;
3724 case Builtin::BI__builtin_hlsl_resource_getpointer: {
3725 if (
SemaRef.checkArgCount(TheCall, 2) ||
3728 SemaRef.getASTContext().UnsignedIntTy))
3733 QualType ContainedTy = ResourceTy->getContainedType();
3736 ReturnType =
SemaRef.Context.getPointerType(ReturnType);
3742 case Builtin::BI__builtin_hlsl_resource_getpointer_typed: {
3743 if (
SemaRef.checkArgCount(TheCall, 3) ||
3746 SemaRef.getASTContext().UnsignedIntTy))
3751 "expected pointer type for second argument");
3758 diag::err_invalid_use_of_array_type);
3762 ReturnType =
SemaRef.Context.getPointerType(ReturnType);
3767 case Builtin::BI__builtin_hlsl_resource_load_with_status: {
3768 if (
SemaRef.checkArgCount(TheCall, 3) ||
3771 SemaRef.getASTContext().UnsignedIntTy) ||
3773 SemaRef.getASTContext().UnsignedIntTy) ||
3779 QualType ReturnType = ResourceTy->getContainedType();
3784 case Builtin::BI__builtin_hlsl_resource_load_with_status_typed: {
3785 if (
SemaRef.checkArgCount(TheCall, 4) ||
3788 SemaRef.getASTContext().UnsignedIntTy) ||
3790 SemaRef.getASTContext().UnsignedIntTy) ||
3796 "expected pointer type for second argument");
3803 diag::err_invalid_use_of_array_type);
3809 case Builtin::BI__builtin_hlsl_resource_load_level:
3811 case Builtin::BI__builtin_hlsl_resource_sample:
3813 case Builtin::BI__builtin_hlsl_resource_sample_bias:
3815 case Builtin::BI__builtin_hlsl_resource_sample_grad:
3817 case Builtin::BI__builtin_hlsl_resource_sample_level:
3819 case Builtin::BI__builtin_hlsl_resource_sample_cmp:
3821 case Builtin::BI__builtin_hlsl_resource_sample_cmp_level_zero:
3823 case Builtin::BI__builtin_hlsl_resource_gather:
3825 case Builtin::BI__builtin_hlsl_resource_gather_cmp:
3827 case Builtin::BI__builtin_hlsl_resource_uninitializedhandle: {
3828 assert(TheCall->
getNumArgs() == 1 &&
"expected 1 arg");
3834 case Builtin::BI__builtin_hlsl_resource_handlefrombinding: {
3835 assert(TheCall->
getNumArgs() == 6 &&
"expected 6 args");
3841 case Builtin::BI__builtin_hlsl_resource_handlefromimplicitbinding: {
3842 assert(TheCall->
getNumArgs() == 6 &&
"expected 6 args");
3848 case Builtin::BI__builtin_hlsl_resource_counterhandlefromimplicitbinding: {
3849 assert(TheCall->
getNumArgs() == 3 &&
"expected 3 args");
3852 auto *MainResType = MainHandleTy->
getAs<HLSLAttributedResourceType>();
3853 auto MainAttrs = MainResType->getAttrs();
3854 assert(!MainAttrs.IsCounter &&
"cannot create a counter from a counter");
3855 MainAttrs.IsCounter =
true;
3857 MainResType->getWrappedType(), MainResType->getContainedType(),
3861 TheCall->
setType(CounterHandleTy);
3864 case Builtin::BI__builtin_hlsl_and:
3865 case Builtin::BI__builtin_hlsl_or: {
3866 if (
SemaRef.checkArgCount(TheCall, 2))
3880 case Builtin::BI__builtin_hlsl_all:
3881 case Builtin::BI__builtin_hlsl_any: {
3882 if (
SemaRef.checkArgCount(TheCall, 1))
3888 case Builtin::BI__builtin_hlsl_asdouble: {
3889 if (
SemaRef.checkArgCount(TheCall, 2))
3893 SemaRef.Context.UnsignedIntTy,
3898 SemaRef.Context.UnsignedIntTy,
3907 case Builtin::BI__builtin_hlsl_elementwise_clamp: {
3908 if (
SemaRef.BuiltinElementwiseTernaryMath(
3914 case Builtin::BI__builtin_hlsl_dot: {
3916 if (
SemaRef.BuiltinVectorToScalarMath(TheCall))
3922 case Builtin::BI__builtin_hlsl_elementwise_firstbithigh:
3923 case Builtin::BI__builtin_hlsl_elementwise_firstbitlow: {
3924 if (
SemaRef.PrepareBuiltinElementwiseMathOneArgCall(TheCall))
3934 EltTy = VecTy->getElementType();
3935 ResTy =
SemaRef.Context.getExtVectorType(ResTy, VecTy->getNumElements());
3948 case Builtin::BI__builtin_hlsl_select: {
3949 if (
SemaRef.checkArgCount(TheCall, 3))
3957 if (VTy && VTy->getElementType()->isBooleanType() &&
3962 case Builtin::BI__builtin_hlsl_elementwise_saturate:
3963 case Builtin::BI__builtin_hlsl_elementwise_rcp: {
3964 if (
SemaRef.checkArgCount(TheCall, 1))
3970 diag::err_builtin_invalid_arg_type)
3973 if (
SemaRef.PrepareBuiltinElementwiseMathOneArgCall(TheCall))
3977 case Builtin::BI__builtin_hlsl_elementwise_degrees:
3978 case Builtin::BI__builtin_hlsl_elementwise_radians:
3979 case Builtin::BI__builtin_hlsl_elementwise_rsqrt:
3980 case Builtin::BI__builtin_hlsl_elementwise_frac:
3981 case Builtin::BI__builtin_hlsl_elementwise_ddx_coarse:
3982 case Builtin::BI__builtin_hlsl_elementwise_ddy_coarse:
3983 case Builtin::BI__builtin_hlsl_elementwise_ddx_fine:
3984 case Builtin::BI__builtin_hlsl_elementwise_ddy_fine: {
3985 if (
SemaRef.checkArgCount(TheCall, 1))
3990 if (
SemaRef.PrepareBuiltinElementwiseMathOneArgCall(TheCall))
3994 case Builtin::BI__builtin_hlsl_elementwise_isinf:
3995 case Builtin::BI__builtin_hlsl_elementwise_isnan: {
3996 if (
SemaRef.checkArgCount(TheCall, 1))
4001 if (
SemaRef.PrepareBuiltinElementwiseMathOneArgCall(TheCall))
4006 case Builtin::BI__builtin_hlsl_lerp: {
4007 if (
SemaRef.checkArgCount(TheCall, 3))
4014 if (
SemaRef.BuiltinElementwiseTernaryMath(TheCall))
4018 case Builtin::BI__builtin_hlsl_mad: {
4019 if (
SemaRef.BuiltinElementwiseTernaryMath(
4025 case Builtin::BI__builtin_hlsl_mul: {
4026 if (
SemaRef.checkArgCount(TheCall, 2))
4035 if (
const auto *VTy = T->getAs<
VectorType>())
4036 return VTy->getElementType();
4038 return MTy->getElementType();
4042 QualType EltTy0 = getElemType(Ty0);
4051 if (IsVec0 && IsMat1) {
4054 }
else if (IsMat0 && IsVec1) {
4058 assert(IsMat0 && IsMat1);
4068 case Builtin::BI__builtin_hlsl_normalize: {
4069 if (
SemaRef.checkArgCount(TheCall, 1))
4080 case Builtin::BI__builtin_hlsl_transpose: {
4081 if (
SemaRef.checkArgCount(TheCall, 1))
4090 << 1 << 3 << 0 << 0 << ArgTy;
4095 MatTy->getElementType(), MatTy->getNumColumns(), MatTy->getNumRows());
4099 case Builtin::BI__builtin_hlsl_elementwise_sign: {
4100 if (
SemaRef.PrepareBuiltinElementwiseMathOneArgCall(TheCall))
4108 case Builtin::BI__builtin_hlsl_step: {
4109 if (
SemaRef.checkArgCount(TheCall, 2))
4121 case Builtin::BI__builtin_hlsl_wave_active_all_equal: {
4122 if (
SemaRef.checkArgCount(TheCall, 1))
4136 unsigned NumElts = VecTy->getNumElements();
4146 case Builtin::BI__builtin_hlsl_wave_active_max:
4147 case Builtin::BI__builtin_hlsl_wave_active_min:
4148 case Builtin::BI__builtin_hlsl_wave_active_sum:
4149 case Builtin::BI__builtin_hlsl_wave_active_product: {
4150 if (
SemaRef.checkArgCount(TheCall, 1))
4163 case Builtin::BI__builtin_hlsl_wave_active_bit_xor:
4164 case Builtin::BI__builtin_hlsl_wave_active_bit_or: {
4165 if (
SemaRef.checkArgCount(TheCall, 1))
4180 (VTy && VTy->getElementType()->isIntegerType()))) {
4182 diag::err_builtin_invalid_arg_type)
4183 << ArgTyExpr <<
SemaRef.Context.UnsignedIntTy << 1 << 0 << 0;
4193 case Builtin::BI__builtin_elementwise_bitreverse: {
4201 case Builtin::BI__builtin_hlsl_wave_prefix_count_bits: {
4202 if (
SemaRef.checkArgCount(TheCall, 1))
4207 if (!(
ArgType->isScalarType())) {
4209 diag::err_typecheck_expect_any_scalar_or_vector)
4214 if (!(
ArgType->isBooleanType())) {
4216 diag::err_typecheck_expect_any_scalar_or_vector)
4223 case Builtin::BI__builtin_hlsl_wave_read_lane_at: {
4224 if (
SemaRef.checkArgCount(TheCall, 2))
4232 diag::err_typecheck_convert_incompatible)
4233 << ArgTyIndex <<
SemaRef.Context.UnsignedIntTy << 1 << 0 << 0;
4246 case Builtin::BI__builtin_hlsl_wave_get_lane_index: {
4247 if (
SemaRef.checkArgCount(TheCall, 0))
4251 case Builtin::BI__builtin_hlsl_wave_prefix_sum:
4252 case Builtin::BI__builtin_hlsl_wave_prefix_product: {
4253 if (
SemaRef.checkArgCount(TheCall, 1))
4266 case Builtin::BI__builtin_hlsl_quad_read_across_x: {
4267 if (
SemaRef.checkArgCount(TheCall, 1))
4279 case Builtin::BI__builtin_hlsl_elementwise_splitdouble: {
4280 if (
SemaRef.checkArgCount(TheCall, 3))
4295 case Builtin::BI__builtin_hlsl_elementwise_clip: {
4296 if (
SemaRef.checkArgCount(TheCall, 1))
4303 case Builtin::BI__builtin_elementwise_acos:
4304 case Builtin::BI__builtin_elementwise_asin:
4305 case Builtin::BI__builtin_elementwise_atan:
4306 case Builtin::BI__builtin_elementwise_atan2:
4307 case Builtin::BI__builtin_elementwise_ceil:
4308 case Builtin::BI__builtin_elementwise_cos:
4309 case Builtin::BI__builtin_elementwise_cosh:
4310 case Builtin::BI__builtin_elementwise_exp:
4311 case Builtin::BI__builtin_elementwise_exp2:
4312 case Builtin::BI__builtin_elementwise_exp10:
4313 case Builtin::BI__builtin_elementwise_floor:
4314 case Builtin::BI__builtin_elementwise_fmod:
4315 case Builtin::BI__builtin_elementwise_log:
4316 case Builtin::BI__builtin_elementwise_log2:
4317 case Builtin::BI__builtin_elementwise_log10:
4318 case Builtin::BI__builtin_elementwise_pow:
4319 case Builtin::BI__builtin_elementwise_roundeven:
4320 case Builtin::BI__builtin_elementwise_sin:
4321 case Builtin::BI__builtin_elementwise_sinh:
4322 case Builtin::BI__builtin_elementwise_sqrt:
4323 case Builtin::BI__builtin_elementwise_tan:
4324 case Builtin::BI__builtin_elementwise_tanh:
4325 case Builtin::BI__builtin_elementwise_trunc: {
4331 case Builtin::BI__builtin_hlsl_buffer_update_counter: {
4332 assert(TheCall->
getNumArgs() == 2 &&
"expected 2 args");
4333 auto checkResTy = [](
const HLSLAttributedResourceType *ResTy) ->
bool {
4334 return !(ResTy->getAttrs().ResourceClass == ResourceClass::UAV &&
4335 ResTy->getAttrs().RawBuffer && ResTy->hasContainedType());
4340 std::optional<llvm::APSInt> Offset =
4342 if (!Offset.has_value() ||
std::abs(Offset->getExtValue()) != 1) {
4344 diag::err_hlsl_expect_arg_const_int_one_or_neg_one)
4350 case Builtin::BI__builtin_hlsl_elementwise_f16tof32: {
4351 if (
SemaRef.checkArgCount(TheCall, 1))
4362 ArgTy = VTy->getElementType();
4365 diag::err_builtin_invalid_arg_type)
4374 case Builtin::BI__builtin_hlsl_elementwise_f32tof16: {
4375 if (
SemaRef.checkArgCount(TheCall, 1))
4390 WorkList.push_back(BaseTy);
4391 while (!WorkList.empty()) {
4392 QualType T = WorkList.pop_back_val();
4393 T = T.getCanonicalType().getUnqualifiedType();
4394 if (
const auto *AT = dyn_cast<ConstantArrayType>(T)) {
4402 for (uint64_t Ct = 0; Ct < AT->
getZExtSize(); ++Ct)
4403 llvm::append_range(List, ElementFields);
4408 if (
const auto *VT = dyn_cast<VectorType>(T)) {
4409 List.insert(List.end(), VT->getNumElements(), VT->getElementType());
4412 if (
const auto *MT = dyn_cast<ConstantMatrixType>(T)) {
4413 List.insert(List.end(), MT->getNumElementsFlattened(),
4414 MT->getElementType());
4417 if (
const auto *RD = T->getAsCXXRecordDecl()) {
4418 if (RD->isStandardLayout())
4419 RD = RD->getStandardLayoutBaseWithFields();
4423 if (RD->
isUnion() || !RD->isAggregate()) {
4429 for (
const auto *FD : RD->
fields())
4430 if (!FD->isUnnamedBitField())
4431 FieldTypes.push_back(FD->
getType());
4433 std::reverse(FieldTypes.begin(), FieldTypes.end());
4434 llvm::append_range(WorkList, FieldTypes);
4438 if (!RD->isStandardLayout()) {
4440 for (
const auto &
Base : RD->bases())
4441 FieldTypes.push_back(
Base.getType());
4442 std::reverse(FieldTypes.begin(), FieldTypes.end());
4443 llvm::append_range(WorkList, FieldTypes);
4465 if (
SemaRef.Context.getTypeSize(QT) / 8 > 16)
4471 int ArraySize = VT->getNumElements();
4476 QualType ElTy = VT->getElementType();
4480 if (
SemaRef.Context.getTypeSize(QT) / 8 > 16)
4496 if (
SemaRef.getASTContext().hasSameType(T1, T2))
4505 return llvm::equal(T1Types, T2Types,
4507 return SemaRef.IsLayoutCompatible(LHS, RHS);
4516 bool HadError =
false;
4518 for (
unsigned i = 0, e =
New->getNumParams(); i != e; ++i) {
4526 const auto *NDAttr = NewParam->
getAttr<HLSLParamModifierAttr>();
4527 unsigned NSpellingIdx = (NDAttr ? NDAttr->getSpellingListIndex() : 0);
4528 const auto *ODAttr = OldParam->
getAttr<HLSLParamModifierAttr>();
4529 unsigned OSpellingIdx = (ODAttr ? ODAttr->getSpellingListIndex() : 0);
4531 if (NSpellingIdx != OSpellingIdx) {
4533 diag::err_hlsl_param_qualifier_mismatch)
4534 << NDAttr << NewParam;
4550 if (
SemaRef.getASTContext().hasSameUnqualifiedType(SrcTy, DestTy))
4565 llvm_unreachable(
"HLSL doesn't support pointers.");
4568 llvm_unreachable(
"HLSL doesn't support complex types.");
4570 llvm_unreachable(
"HLSL doesn't support fixed point types.");
4572 llvm_unreachable(
"Should have returned before this");
4582 llvm_unreachable(
"HLSL doesn't support complex types.");
4584 llvm_unreachable(
"HLSL doesn't support fixed point types.");
4589 llvm_unreachable(
"HLSL doesn't support pointers.");
4591 llvm_unreachable(
"Should have returned before this");
4597 llvm_unreachable(
"HLSL doesn't support pointers.");
4600 llvm_unreachable(
"HLSL doesn't support fixed point types.");
4604 llvm_unreachable(
"HLSL doesn't support complex types.");
4607 llvm_unreachable(
"Unhandled scalar cast");
4634 for (
unsigned I = 0, Size = DestTypes.size(); I < Size; ++I) {
4635 if (DestTypes[I]->isUnionType())
4667 if (SrcTypes.size() < DestTypes.size())
4670 unsigned SrcSize = SrcTypes.size();
4671 unsigned DstSize = DestTypes.size();
4673 for (I = 0; I < DstSize && I < SrcSize; I++) {
4674 if (SrcTypes[I]->isUnionType() || DestTypes[I]->isUnionType())
4682 for (; I < SrcSize; I++) {
4683 if (SrcTypes[I]->isUnionType())
4690 assert(Param->hasAttr<HLSLParamModifierAttr>() &&
4691 "We should not get here without a parameter modifier expression");
4692 const auto *
Attr = Param->getAttr<HLSLParamModifierAttr>();
4699 << Arg << (IsInOut ? 1 : 0);
4705 QualType Ty = Param->getType().getNonLValueExprType(Ctx);
4712 << Arg << (IsInOut ? 1 : 0);
4724 SemaRef.PerformCopyInitialization(Entity, Param->getBeginLoc(), ArgOpV);
4730 auto *OpV =
new (Ctx)
4735 Res =
SemaRef.ActOnBinOp(
SemaRef.getCurScope(), Param->getBeginLoc(),
4736 tok::equal, ArgOpV, OpV);
4752 "Pointer and reference types cannot be inout or out parameters");
4753 Ty =
SemaRef.getASTContext().getLValueReferenceType(Ty);
4769 for (
const auto *FD : RD->
fields()) {
4773 assert(RD->getNumBases() <= 1 &&
4774 "HLSL doesn't support multiple inheritance");
4775 return RD->getNumBases()
4780 if (
const auto *AT = dyn_cast<ArrayType>(Ty)) {
4781 if (
const auto *CAT = dyn_cast<ConstantArrayType>(AT))
4793 bool IsVKPushConstant = IsVulkan && VD->
hasAttr<HLSLVkPushConstantAttr>();
4798 !VD->
hasAttr<HLSLVkConstantIdAttr>() && !IsVKPushConstant &&
4804 if (
Decl->getType().hasAddressSpace())
4807 if (
Decl->getType()->isDependentType())
4820 llvm::Triple::Vulkan;
4821 if (IsVulkan &&
Decl->
hasAttr<HLSLVkPushConstantAttr>()) {
4822 if (HasDeclaredAPushConstant)
4828 HasDeclaredAPushConstant =
true;
4855class StructBindingContext {
4858 HLSLResourceBindingAttr *RegBindingsAttrs[4];
4859 unsigned RegBindingOffset[4];
4862 static_assert(
static_cast<unsigned>(RegisterType::SRV) == 0 &&
4863 static_cast<unsigned>(RegisterType::UAV) == 1 &&
4864 static_cast<unsigned>(RegisterType::CBuffer) == 2 &&
4865 static_cast<unsigned>(RegisterType::Sampler) == 3,
4866 "unexpected register type values");
4869 HLSLVkBindingAttr *VkBindingAttr;
4870 unsigned VkBindingOffset;
4875 StructBindingContext(
VarDecl *VD) {
4876 for (
unsigned i = 0; i < 4; ++i) {
4877 RegBindingsAttrs[i] =
nullptr;
4878 RegBindingOffset[i] = 0;
4880 VkBindingAttr =
nullptr;
4881 VkBindingOffset = 0;
4887 if (
auto *RBA = dyn_cast<HLSLResourceBindingAttr>(A)) {
4889 unsigned RegTypeIdx =
static_cast<unsigned>(RegType);
4892 RegBindingsAttrs[RegTypeIdx] = RBA;
4897 if (
auto *VBA = dyn_cast<HLSLVkBindingAttr>(A))
4898 VkBindingAttr = VBA;
4905 Attr *createBindingAttr(SemaHLSL &S, ASTContext &AST,
RegisterType RegType,
4907 assert(
static_cast<unsigned>(RegType) < 4 &&
"unexpected register type");
4909 if (VkBindingAttr) {
4910 unsigned Offset = VkBindingOffset;
4911 VkBindingOffset +=
Range;
4912 return HLSLVkBindingAttr::CreateImplicit(
4913 AST, VkBindingAttr->getBinding() + Offset, VkBindingAttr->getSet(),
4914 VkBindingAttr->getRange());
4917 HLSLResourceBindingAttr *RBA =
4918 RegBindingsAttrs[
static_cast<unsigned>(RegType)];
4919 HLSLResourceBindingAttr *NewAttr =
nullptr;
4921 if (RBA && RBA->hasRegisterSlot()) {
4924 unsigned Offset = RegBindingOffset[
static_cast<unsigned>(RegType)];
4925 RegBindingOffset[
static_cast<unsigned>(RegType)] += Range;
4927 unsigned NewSlotNumber = RBA->getSlotNumber() + Offset;
4928 StringRef NewSlotNumberStr =
4930 NewAttr = HLSLResourceBindingAttr::CreateImplicit(
4931 AST, NewSlotNumberStr, RBA->getSpace(), RBA->getRange());
4932 NewAttr->setBinding(RegType, NewSlotNumber, RBA->getSpaceNumber());
4936 NewAttr = HLSLResourceBindingAttr::CreateImplicit(AST,
"",
"0", {});
4937 NewAttr->setBinding(RegType, std::nullopt,
4938 RBA ? RBA->getSpaceNumber() : 0);
4948static void createGlobalResourceDeclForStruct(
4950 QualType ResTy, StructBindingContext &BindingCtx) {
4952 "expected resource type or array of resources");
4962 const HLSLAttributedResourceType *ResHandleTy =
nullptr;
4963 if (
const auto *AT = dyn_cast<ArrayType>(ResTy.
getTypePtr())) {
4964 const auto *CAT = dyn_cast<ConstantArrayType>(AT);
4968 ResHandleTy = HLSLAttributedResourceType::findHandleTypeOnResource(
4972 Attr *BindingAttr = BindingCtx.createBindingAttr(
4974 ResDecl->
addAttr(BindingAttr);
4975 ResDecl->
addAttr(InternalLinkageAttr::CreateImplicit(AST));
4984 HLSLAssociatedResourceDeclAttr::CreateImplicit(AST, ResDecl));
4991static void handleArrayOfStructWithResources(
4993 EmbeddedResourceNameBuilder &NameBuilder, StructBindingContext &BindingCtx);
4998static void handleStructWithResources(
Sema &S,
VarDecl *ParentVD,
5000 EmbeddedResourceNameBuilder &NameBuilder,
5001 StructBindingContext &BindingCtx) {
5004 assert(RD->
getNumBases() <= 1 &&
"HLSL doesn't support multiple inheritance");
5011 handleStructWithResources(S, ParentVD, BaseRD, NameBuilder, BindingCtx);
5025 createGlobalResourceDeclForStruct(S, ParentVD, FD->
getLocation(), II,
5028 handleStructWithResources(S, ParentVD, RD, NameBuilder, BindingCtx);
5030 }
else if (
const auto *ArrayTy = dyn_cast<ConstantArrayType>(FDTy)) {
5032 "resource arrays should have been already handled");
5033 handleArrayOfStructWithResources(S, ParentVD, ArrayTy, NameBuilder,
5042handleArrayOfStructWithResources(
Sema &S,
VarDecl *ParentVD,
5044 EmbeddedResourceNameBuilder &NameBuilder,
5045 StructBindingContext &BindingCtx) {
5053 if (!SubCAT && !ElementRD)
5056 for (
unsigned I = 0, E = CAT->
getSize().getZExtValue(); I < E; ++I) {
5059 handleStructWithResources(S, ParentVD, ElementRD, NameBuilder,
5062 handleArrayOfStructWithResources(S, ParentVD, SubCAT, NameBuilder,
5075void SemaHLSL::handleGlobalStructOrArrayOfWithResources(
VarDecl *VD) {
5076 EmbeddedResourceNameBuilder NameBuilder(VD->
getName());
5077 StructBindingContext BindingCtx(VD);
5081 "Expected non-resource struct or array type");
5084 handleStructWithResources(
SemaRef, VD, RD, NameBuilder, BindingCtx);
5088 if (
const auto *CAT = dyn_cast<ConstantArrayType>(VDTy)) {
5089 handleArrayOfStructWithResources(
SemaRef, VD, CAT, NameBuilder, BindingCtx);
5097 if (
SemaRef.RequireCompleteType(
5100 diag::err_typecheck_decl_incomplete_type)) {
5114 DefaultCBufferDecls.push_back(VD);
5119 collectResourceBindingsOnVarDecl(VD);
5121 if (VD->
hasAttr<HLSLVkConstantIdAttr>())
5133 processExplicitBindingsOnDecl(VD);
5171 handleGlobalStructOrArrayOfWithResources(VD);
5175 if (VD->
hasAttr<HLSLGroupSharedAddressSpaceAttr>())
5184 "expected resource record type");
5200 const char *CreateMethodName;
5202 CreateMethodName = HasCounter ?
"__createFromBindingWithImplicitCounter"
5203 :
"__createFromBinding";
5205 CreateMethodName = HasCounter
5206 ?
"__createFromImplicitBindingWithImplicitCounter"
5207 :
"__createFromImplicitBinding";
5222 Args.push_back(RegSlot);
5230 Args.push_back(OrderId);
5236 Args.push_back(Space);
5240 Args.push_back(RangeSize);
5244 Args.push_back(Index);
5246 StringRef VarName = VD->
getName();
5254 Args.push_back(NameCast);
5262 Args.push_back(CounterId);
5285 SemaRef.CheckCompleteVariableDeclaration(VD);
5291 "expected array of resource records");
5312 lookupMethod(
SemaRef, ResourceDecl,
5313 HasCounter ?
"__createFromBindingWithImplicitCounter"
5314 :
"__createFromBinding",
5318 CreateMethod = lookupMethod(
5320 HasCounter ?
"__createFromImplicitBindingWithImplicitCounter"
5321 :
"__createFromImplicitBinding",
5353std::optional<const DeclBindingInfo *> SemaHLSL::inferGlobalBinding(
Expr *E) {
5354 if (
auto *Ternary = dyn_cast<ConditionalOperator>(E)) {
5355 auto TrueInfo = inferGlobalBinding(Ternary->getTrueExpr());
5356 auto FalseInfo = inferGlobalBinding(Ternary->getFalseExpr());
5357 if (!TrueInfo || !FalseInfo)
5358 return std::nullopt;
5359 if (*TrueInfo != *FalseInfo)
5360 return std::nullopt;
5364 if (
auto *ASE = dyn_cast<ArraySubscriptExpr>(E))
5373 if (
const auto *AttrResType =
5374 HLSLAttributedResourceType::findHandleTypeOnResource(Ty)) {
5376 return Bindings.getDeclBindingInfo(VD, RC);
5383void SemaHLSL::trackLocalResource(
VarDecl *VD,
Expr *E) {
5384 std::optional<const DeclBindingInfo *> ExprBinding = inferGlobalBinding(E);
5387 diag::warn_hlsl_assigning_local_resource_is_not_unique)
5392 if (*ExprBinding ==
nullptr)
5395 auto PrevBinding = Assigns.find(VD);
5396 if (PrevBinding == Assigns.end()) {
5398 Assigns.insert({VD, *ExprBinding});
5403 if (*ExprBinding != PrevBinding->second) {
5405 diag::warn_hlsl_assigning_local_resource_is_not_unique)
5407 SemaRef.Diag(VD->getLocation(), diag::note_var_declared_here) << VD;
5418 "expected LHS to be a resource record or array of resource records");
5419 if (Opc != BO_Assign)
5424 while (
auto *ASE = dyn_cast<ArraySubscriptExpr>(E))
5432 SemaRef.Diag(Loc, diag::err_hlsl_assign_to_global_resource) << VD;
5437 trackLocalResource(VD, RHSExpr);
5445void SemaHLSL::collectResourceBindingsOnVarDecl(
VarDecl *VD) {
5447 "expected global variable that contains HLSL resource");
5450 if (
const HLSLBufferDecl *CBufferOrTBuffer = dyn_cast<HLSLBufferDecl>(VD)) {
5451 Bindings.addDeclBindingInfo(VD, CBufferOrTBuffer->isCBuffer()
5452 ? ResourceClass::CBuffer
5453 : ResourceClass::SRV);
5466 if (
const HLSLAttributedResourceType *AttrResType =
5467 HLSLAttributedResourceType::findHandleTypeOnResource(Ty)) {
5468 Bindings.addDeclBindingInfo(VD, AttrResType->getAttrs().ResourceClass);
5473 if (
const RecordType *RT = dyn_cast<RecordType>(Ty))
5474 collectResourceBindingsOnUserRecordDecl(VD, RT);
5480void SemaHLSL::processExplicitBindingsOnDecl(
VarDecl *VD) {
5483 bool HasBinding =
false;
5484 for (Attr *A : VD->
attrs()) {
5487 if (
auto PA = VD->
getAttr<HLSLVkPushConstantAttr>())
5488 Diag(PA->getLoc(), diag::err_hlsl_attr_incompatible) << A << PA;
5491 HLSLResourceBindingAttr *RBA = dyn_cast<HLSLResourceBindingAttr>(A);
5492 if (!RBA || !RBA->hasRegisterSlot())
5497 assert(RT != RegisterType::I &&
"invalid or obsolete register type should "
5498 "never have an attribute created");
5500 if (RT == RegisterType::C) {
5501 if (Bindings.hasBindingInfoForDecl(VD))
5503 diag::warn_hlsl_user_defined_type_missing_member)
5504 <<
static_cast<int>(RT);
5512 if (DeclBindingInfo *BI = Bindings.getDeclBindingInfo(VD, RC)) {
5517 diag::warn_hlsl_user_defined_type_missing_member)
5518 <<
static_cast<int>(RT);
5526class InitListTransformer {
5530 QualType *DstIt =
nullptr;
5531 Expr **ArgIt =
nullptr;
5537 bool castInitializer(Expr *E) {
5538 assert(DstIt &&
"This should always be something!");
5539 if (DstIt == DestTypes.end()) {
5541 ArgExprs.push_back(E);
5546 DstIt = DestTypes.begin();
5549 Ctx, *DstIt,
false);
5554 ArgExprs.push_back(
Init);
5559 bool buildInitializerListImpl(Expr *E) {
5561 if (
auto *
Init = dyn_cast<InitListExpr>(E)) {
5562 for (
auto *SubInit :
Init->inits())
5563 if (!buildInitializerListImpl(SubInit))
5572 return castInitializer(E);
5574 if (
auto *VecTy = Ty->
getAs<VectorType>()) {
5579 for (uint64_t I = 0; I <
Size; ++I) {
5581 SizeTy, SourceLocation());
5587 if (!castInitializer(ElExpr.
get()))
5592 if (
auto *MTy = Ty->
getAs<ConstantMatrixType>()) {
5593 unsigned Rows = MTy->getNumRows();
5594 unsigned Cols = MTy->getNumColumns();
5595 QualType ElemTy = MTy->getElementType();
5597 for (
unsigned R = 0;
R < Rows; ++
R) {
5598 for (
unsigned C = 0;
C < Cols; ++
C) {
5611 if (!castInitializer(ElExpr.
get()))
5619 if (
auto *ArrTy = dyn_cast<ConstantArrayType>(Ty.
getTypePtr())) {
5623 for (uint64_t I = 0; I <
Size; ++I) {
5625 SizeTy, SourceLocation());
5630 if (!buildInitializerListImpl(ElExpr.
get()))
5637 llvm::SmallVector<CXXRecordDecl *> RecordDecls;
5638 RecordDecls.push_back(RD);
5639 while (RecordDecls.back()->getNumBases()) {
5640 CXXRecordDecl *D = RecordDecls.back();
5642 "HLSL doesn't support multiple inheritance");
5643 RecordDecls.push_back(
5646 while (!RecordDecls.empty()) {
5647 CXXRecordDecl *RD = RecordDecls.pop_back_val();
5648 for (
auto *FD : RD->
fields()) {
5649 if (FD->isUnnamedBitField())
5657 if (!buildInitializerListImpl(Res.
get()))
5665 Expr *generateInitListsImpl(QualType Ty) {
5666 assert(ArgIt != ArgExprs.end() &&
"Something is off in iteration!");
5670 llvm::SmallVector<Expr *>
Inits;
5676 if (
auto *ATy = Ty->
getAs<VectorType>()) {
5677 ElTy = ATy->getElementType();
5678 Size = ATy->getNumElements();
5679 }
else if (
auto *CMTy = Ty->
getAs<ConstantMatrixType>()) {
5680 ElTy = CMTy->getElementType();
5681 Size = CMTy->getNumElementsFlattened();
5684 ElTy = VTy->getElementType();
5685 Size = VTy->getZExtSize();
5687 for (uint64_t I = 0; I <
Size; ++I)
5688 Inits.push_back(generateInitListsImpl(ElTy));
5691 llvm::SmallVector<CXXRecordDecl *> RecordDecls;
5692 RecordDecls.push_back(RD);
5693 while (RecordDecls.back()->getNumBases()) {
5694 CXXRecordDecl *D = RecordDecls.back();
5696 "HLSL doesn't support multiple inheritance");
5697 RecordDecls.push_back(
5700 while (!RecordDecls.empty()) {
5701 CXXRecordDecl *RD = RecordDecls.pop_back_val();
5702 for (
auto *FD : RD->
fields())
5703 if (!FD->isUnnamedBitField())
5707 auto *NewInit =
new (Ctx) InitListExpr(Ctx,
Inits.front()->getBeginLoc(),
5709 NewInit->setType(Ty);
5714 llvm::SmallVector<QualType, 16> DestTypes;
5715 llvm::SmallVector<Expr *, 16> ArgExprs;
5716 InitListTransformer(Sema &SemaRef,
const InitializedEntity &Entity)
5717 : S(SemaRef), Ctx(SemaRef.getASTContext()),
5718 Wrap(Entity.
getType()->isIncompleteArrayType()) {
5719 InitTy = Entity.
getType().getNonReferenceType();
5729 DstIt = DestTypes.begin();
5732 bool buildInitializerList(Expr *E) {
return buildInitializerListImpl(E); }
5734 Expr *generateInitLists() {
5735 assert(!ArgExprs.empty() &&
5736 "Call buildInitializerList to generate argument expressions.");
5737 ArgIt = ArgExprs.begin();
5739 return generateInitListsImpl(InitTy);
5740 llvm::SmallVector<Expr *>
Inits;
5741 while (ArgIt != ArgExprs.end())
5742 Inits.push_back(generateInitListsImpl(InitTy));
5744 auto *NewInit =
new (Ctx) InitListExpr(Ctx,
Inits.front()->getBeginLoc(),
5746 llvm::APInt ArySize(64,
Inits.size());
5748 ArraySizeModifier::Normal, 0));
5760 if (
const ArrayType *AT = dyn_cast<ArrayType>(Ty)) {
5767 if (
const auto *RT = Ty->
getAs<RecordType>()) {
5771 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
5791 if (
Init->getType()->isScalarType())
5794 InitListTransformer ILT(
SemaRef, Entity);
5796 for (
unsigned I = 0; I <
Init->getNumInits(); ++I) {
5804 Init->setInit(I, E);
5806 if (!ILT.buildInitializerList(E))
5809 size_t ExpectedSize = ILT.DestTypes.size();
5810 size_t ActualSize = ILT.ArgExprs.size();
5811 if (ExpectedSize == 0 && ActualSize == 0)
5818 InitTy =
SemaRef.getASTContext().removeAddrSpaceQualType(InitTy);
5820 SemaRef.Diag(
Init->getBeginLoc(), diag::err_hlsl_incorrect_num_initializers)
5821 << (int)(ExpectedSize < ActualSize) << InitTy
5822 << ExpectedSize << ActualSize;
5832 assert(ExpectedSize > 0 &&
5833 "The expected size of an incomplete array type must be at least 1.");
5835 ((ActualSize + ExpectedSize - 1) / ExpectedSize) * ExpectedSize;
5843 InitTy =
SemaRef.getASTContext().removeAddrSpaceQualType(InitTy);
5844 if (ExpectedSize != ActualSize) {
5845 int TooManyOrFew = ActualSize > ExpectedSize ? 1 : 0;
5846 SemaRef.Diag(
Init->getBeginLoc(), diag::err_hlsl_incorrect_num_initializers)
5847 << TooManyOrFew << InitTy << ExpectedSize << ActualSize;
5854 Init->resizeInits(Ctx, NewInit->getNumInits());
5855 for (
unsigned I = 0; I < NewInit->getNumInits(); ++I)
5856 Init->updateInit(Ctx, I, NewInit->getInit(I));
5864 S.
Diag(OpLoc, diag::err_builtin_matrix_invalid_member)
5874 StringRef AccessorName = CompName->
getName();
5875 assert(!AccessorName.empty() &&
"Matrix Accessor must have a name");
5877 unsigned Rows = MT->getNumRows();
5878 unsigned Cols = MT->getNumColumns();
5879 bool IsZeroBasedAccessor =
false;
5880 unsigned ChunkLen = 0;
5881 if (AccessorName.size() < 2)
5883 "length 4 for zero based: \'_mRC\' or "
5884 "length 3 for one-based: \'_RC\' accessor",
5887 if (AccessorName[0] ==
'_') {
5888 if (AccessorName[1] ==
'm') {
5889 IsZeroBasedAccessor =
true;
5896 S, AccessorName,
"zero based: \'_mRC\' or one-based: \'_RC\' accessor",
5899 if (AccessorName.size() % ChunkLen != 0) {
5900 const llvm::StringRef
Expected = IsZeroBasedAccessor
5901 ?
"zero based: '_mRC' accessor"
5902 :
"one-based: '_RC' accessor";
5907 auto isDigit = [](
char c) {
return c >=
'0' &&
c <=
'9'; };
5908 auto isZeroBasedIndex = [](
unsigned i) {
return i <= 3; };
5909 auto isOneBasedIndex = [](
unsigned i) {
return i >= 1 && i <= 4; };
5911 bool HasRepeated =
false;
5913 unsigned NumComponents = 0;
5914 const char *Begin = AccessorName.data();
5916 for (
unsigned I = 0, E = AccessorName.size(); I < E; I += ChunkLen) {
5917 const char *Chunk = Begin + I;
5918 char RowChar = 0, ColChar = 0;
5919 if (IsZeroBasedAccessor) {
5921 if (Chunk[0] !=
'_' || Chunk[1] !=
'm') {
5922 char Bad = (Chunk[0] !=
'_') ? Chunk[0] : Chunk[1];
5924 S, StringRef(&Bad, 1),
"\'_m\' prefix",
5931 if (Chunk[0] !=
'_')
5933 S, StringRef(&Chunk[0], 1),
"\'_\' prefix",
5940 bool IsDigitsError =
false;
5942 unsigned BadPos = IsZeroBasedAccessor ? 2 : 1;
5946 IsDigitsError =
true;
5950 unsigned BadPos = IsZeroBasedAccessor ? 3 : 2;
5954 IsDigitsError =
true;
5959 unsigned Row = RowChar -
'0';
5960 unsigned Col = ColChar -
'0';
5962 bool HasIndexingError =
false;
5963 if (IsZeroBasedAccessor) {
5965 if (!isZeroBasedIndex(Row)) {
5966 S.
Diag(OpLoc, diag::err_hlsl_matrix_element_not_in_bounds)
5968 HasIndexingError =
true;
5970 if (!isZeroBasedIndex(Col)) {
5971 S.
Diag(OpLoc, diag::err_hlsl_matrix_element_not_in_bounds)
5973 HasIndexingError =
true;
5977 if (!isOneBasedIndex(Row)) {
5978 S.
Diag(OpLoc, diag::err_hlsl_matrix_element_not_in_bounds)
5980 HasIndexingError =
true;
5982 if (!isOneBasedIndex(Col)) {
5983 S.
Diag(OpLoc, diag::err_hlsl_matrix_element_not_in_bounds)
5985 HasIndexingError =
true;
5992 if (HasIndexingError)
5998 bool HasBoundsError =
false;
6000 Diag(OpLoc, diag::err_hlsl_matrix_index_out_of_bounds)
6002 HasBoundsError =
true;
6005 Diag(OpLoc, diag::err_hlsl_matrix_index_out_of_bounds)
6007 HasBoundsError =
true;
6012 unsigned FlatIndex = Row * Cols + Col;
6013 if (Seen[FlatIndex])
6015 Seen[FlatIndex] =
true;
6018 if (NumComponents == 0 || NumComponents > 4) {
6019 S.
Diag(OpLoc, diag::err_hlsl_matrix_swizzle_invalid_length)
6024 QualType ElemTy = MT->getElementType();
6025 if (NumComponents == 1)
6031 for (Sema::ExtVectorDeclsType::iterator
6035 if ((*I)->getUnderlyingType() == VT)
6046 trackLocalResource(VDecl,
Init);
6048 const HLSLVkConstantIdAttr *ConstIdAttr =
6049 VDecl->
getAttr<HLSLVkConstantIdAttr>();
6056 if (!
Init->isCXX11ConstantExpr(Context, &InitValue)) {
6066 int ConstantID = ConstIdAttr->getId();
6067 llvm::APInt IDVal(Context.getIntWidth(Context.IntTy), ConstantID);
6069 ConstIdAttr->getLocation());
6073 if (
C->getType()->getCanonicalTypeUnqualified() !=
6077 Context.getTrivialTypeSourceInfo(
6078 Init->getType(),
Init->getExprLoc()),
6097 if (!Params || Params->
size() != 1)
6110 if (
auto *TTP = dyn_cast<TemplateTypeParmDecl>(P)) {
6111 if (TTP->hasDefaultArgument()) {
6112 TemplateArgs.
addArgument(TTP->getDefaultArgument());
6115 }
else if (
auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(P)) {
6116 if (NTTP->hasDefaultArgument()) {
6117 TemplateArgs.
addArgument(NTTP->getDefaultArgument());
6120 }
else if (
auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(P)) {
6121 if (TTPD->hasDefaultArgument()) {
6122 TemplateArgs.
addArgument(TTPD->getDefaultArgument());
6129 return SemaRef.CheckTemplateIdType(
6131 TemplateArgs,
nullptr,
false);
Defines the clang::ASTContext interface.
Defines enum values for all the target-independent builtin functions.
llvm::dxil::ResourceClass ResourceClass
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
llvm::SmallVector< std::pair< const MemRegion *, SVal >, 4 > Bindings
static bool CheckArgTypeMatches(Sema *S, Expr *Arg, QualType ExpectedType)
static void BuildFlattenedTypeList(QualType BaseTy, llvm::SmallVectorImpl< QualType > &List)
static bool CheckUnsignedIntRepresentation(Sema *S, SourceLocation Loc, int ArgOrdinal, clang::QualType PassedType)
static bool containsIncompleteArrayType(QualType Ty)
static QualType handleIntegerVectorBinOpConversion(Sema &SemaRef, ExprResult &LHS, ExprResult &RHS, QualType LHSType, QualType RHSType, QualType LElTy, QualType RElTy, bool IsCompAssign)
static bool convertToRegisterType(StringRef Slot, RegisterType *RT)
static StringRef createRegisterString(ASTContext &AST, RegisterType RegType, unsigned N)
static bool CheckWaveActive(Sema *S, CallExpr *TheCall)
static void createHostLayoutStructForBuffer(Sema &S, HLSLBufferDecl *BufDecl)
static void castVector(Sema &S, ExprResult &E, QualType &Ty, unsigned Sz)
static QualType ReportMatrixInvalidMember(Sema &S, StringRef Name, StringRef Expected, SourceLocation OpLoc, SourceLocation CompLoc)
static bool CheckBoolSelect(Sema *S, CallExpr *TheCall)
static unsigned calculateLegacyCbufferFieldAlign(const ASTContext &Context, QualType T)
static bool isZeroSizedArray(const ConstantArrayType *CAT)
static bool DiagnoseHLSLRegisterAttribute(Sema &S, SourceLocation &ArgLoc, Decl *D, RegisterType RegType, bool SpecifiedSpace)
static bool hasConstantBufferLayout(QualType QT)
static FieldDecl * createFieldForHostLayoutStruct(Sema &S, const Type *Ty, IdentifierInfo *II, CXXRecordDecl *LayoutStruct)
static bool CheckUnsignedIntVecRepresentation(Sema *S, SourceLocation Loc, int ArgOrdinal, clang::QualType PassedType)
static bool isInvalidConstantBufferLeafElementType(const Type *Ty)
static Builtin::ID getSpecConstBuiltinId(const Type *Type)
static bool CheckFloatingOrIntRepresentation(Sema *S, SourceLocation Loc, int ArgOrdinal, clang::QualType PassedType)
static const Type * createHostLayoutType(Sema &S, const Type *Ty)
static bool CheckAnyScalarOrVector(Sema *S, CallExpr *TheCall, unsigned ArgIndex)
static const HLSLAttributedResourceType * getResourceArrayHandleType(QualType QT)
static IdentifierInfo * getHostLayoutStructName(Sema &S, NamedDecl *BaseDecl, bool MustBeUnique)
static void addImplicitBindingAttrToDecl(Sema &S, Decl *D, RegisterType RT, uint32_t ImplicitBindingOrderID)
static void SetElementTypeAsReturnType(Sema *S, CallExpr *TheCall, QualType ReturnType)
static unsigned calculateLegacyCbufferSize(const ASTContext &Context, QualType T)
static bool CheckLoadLevelBuiltin(Sema &S, CallExpr *TheCall)
static RegisterType getRegisterType(ResourceClass RC)
static bool ValidateRegisterNumber(uint64_t SlotNum, Decl *TheDecl, ASTContext &Ctx, RegisterType RegTy)
static bool isVkPipelineBuiltin(const ASTContext &AstContext, FunctionDecl *FD, HLSLAppliedSemanticAttr *Semantic, bool IsInput)
static bool CheckVectorElementCount(Sema *S, QualType PassedType, QualType BaseType, unsigned ExpectedCount, SourceLocation Loc)
static bool CheckModifiableLValue(Sema *S, CallExpr *TheCall, unsigned ArgIndex)
static QualType castElement(Sema &S, ExprResult &E, QualType Ty)
static char getRegisterTypeChar(RegisterType RT)
static bool CheckNotBoolScalarOrVector(Sema *S, CallExpr *TheCall, unsigned ArgIndex)
static CXXRecordDecl * findRecordDeclInContext(IdentifierInfo *II, DeclContext *DC)
static bool CheckWavePrefix(Sema *S, CallExpr *TheCall)
static bool CheckExpectedBitWidth(Sema *S, CallExpr *TheCall, unsigned ArgOrdinal, unsigned Width)
static bool hasCounterHandle(const CXXRecordDecl *RD)
static bool CheckVectorSelect(Sema *S, CallExpr *TheCall)
static QualType handleFloatVectorBinOpConversion(Sema &SemaRef, ExprResult &LHS, ExprResult &RHS, QualType LHSType, QualType RHSType, QualType LElTy, QualType RElTy, bool IsCompAssign)
static ResourceClass getResourceClass(RegisterType RT)
static CXXRecordDecl * createHostLayoutStruct(Sema &S, CXXRecordDecl *StructDecl)
static bool CheckScalarOrVector(Sema *S, CallExpr *TheCall, QualType Scalar, unsigned ArgIndex)
static bool CheckSamplingBuiltin(Sema &S, CallExpr *TheCall, SampleKind Kind)
static bool CheckScalarOrVectorOrMatrix(Sema *S, CallExpr *TheCall, QualType Scalar, unsigned ArgIndex)
static bool CheckFloatRepresentation(Sema *S, SourceLocation Loc, int ArgOrdinal, clang::QualType PassedType)
static bool requiresImplicitBufferLayoutStructure(const CXXRecordDecl *RD)
static bool CheckResourceHandle(Sema *S, CallExpr *TheCall, unsigned ArgIndex, llvm::function_ref< bool(const HLSLAttributedResourceType *ResType)> Check=nullptr)
static void validatePackoffset(Sema &S, HLSLBufferDecl *BufDecl)
static bool IsDefaultBufferConstantDecl(const ASTContext &Ctx, VarDecl *VD)
HLSLResourceBindingAttr::RegisterType RegisterType
static CastKind getScalarCastKind(ASTContext &Ctx, QualType DestTy, QualType SrcTy)
static bool CheckGatherBuiltin(Sema &S, CallExpr *TheCall, bool IsCmp)
static bool isValidWaveSizeValue(unsigned Value)
static bool isResourceRecordTypeOrArrayOf(QualType Ty)
static bool AccumulateHLSLResourceSlots(QualType Ty, uint64_t &StartSlot, const uint64_t &Limit, const ResourceClass ResClass, ASTContext &Ctx, uint64_t ArrayCount=1)
static bool CheckNoDoubleVectors(Sema *S, SourceLocation Loc, int ArgOrdinal, clang::QualType PassedType)
static bool ValidateMultipleRegisterAnnotations(Sema &S, Decl *TheDecl, RegisterType regType)
static bool CheckTextureSamplerAndLocation(Sema &S, CallExpr *TheCall)
static bool DiagnoseLocalRegisterBinding(Sema &S, SourceLocation &ArgLoc, Decl *D, RegisterType RegType, bool SpecifiedSpace)
This file declares semantic analysis for HLSL constructs.
Defines the clang::SourceLocation class and associated facilities.
Defines various enumerations that describe declaration and type specifiers.
C Language Family Type Representation.
Defines the clang::TypeLoc interface and its subclasses.
C Language Family Type Representation.
static const TypeInfo & getInfo(unsigned id)
__device__ __2f16 float c
return(__x > > __y)|(__x<<(32 - __y))
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
virtual bool HandleTopLevelDecl(DeclGroupRef D)
HandleTopLevelDecl - Handle the specified top-level declaration.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
unsigned getIntWidth(QualType T) const
int getIntegerTypeOrder(QualType LHS, QualType RHS) const
Return the highest ranked integer type, see C99 6.3.1.8p1.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
const IncompleteArrayType * getAsIncompleteArrayType(QualType T) const
QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize, const Expr *SizeExpr, ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return the unique reference to the type for a constant array of the specified element type.
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
int getFloatingTypeOrder(QualType LHS, QualType RHS) const
Compare the rank of the two specified floating point types, ignoring the domain of the type (i....
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
QualType getStringLiteralArrayType(QualType EltTy, unsigned Length) const
Return a type for a constant array for a string literal of the specified element type and length.
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
CanQualType UnsignedIntTy
QualType getTypedefType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, const TypedefNameDecl *Decl, QualType UnderlyingType=QualType(), std::optional< bool > TypeMatchesDeclOrNone=std::nullopt) const
Return the unique reference to the type for the specified typedef-name decl.
llvm::StringRef backupStr(llvm::StringRef S) const
QualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
QualType getExtVectorType(QualType VectorType, unsigned NumElts) const
Return the unique reference to an extended vector type of the specified element type and size.
const TargetInfo & getTargetInfo() const
QualType getHLSLAttributedResourceType(QualType Wrapped, QualType Contained, const HLSLAttributedResourceType::Attributes &Attrs)
QualType getAddrSpaceQualType(QualType T, LangAS AddressSpace) const
Return the uniqued reference to the type for an address space qualified type with the specified type ...
CanQualType getCanonicalTagType(const TagDecl *TD) const
static bool hasSameUnqualifiedType(QualType T1, QualType T2)
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
QualType getConstantMatrixType(QualType ElementType, unsigned NumRows, unsigned NumColumns) const
Return the unique reference to the matrix type of the specified element type and size.
unsigned getTypeAlign(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in bits.
Represents an array type, per C99 6.7.5.2 - Array Declarators.
QualType getElementType() const
Attr - This represents one attribute.
attr::Kind getKind() const
SourceLocation getLocation() const
SourceLocation getScopeLoc() const
SourceRange getRange() const
const IdentifierInfo * getScopeName() const
SourceLocation getLoc() const
const IdentifierInfo * getAttrName() const
Represents a base class of a C++ class.
QualType getType() const
Retrieves the type of the base class.
Represents a static or instance method of a struct/union/class.
Represents a C++ struct/union/class.
bool isHLSLIntangible() const
Returns true if the class contains HLSL intangible type, either as a field or in base class.
static CXXRecordDecl * Create(const ASTContext &C, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, CXXRecordDecl *PrevDecl=nullptr)
void setBases(CXXBaseSpecifier const *const *Bases, unsigned NumBases)
Sets the base classes of this struct or class.
base_class_iterator bases_end()
void completeDefinition() override
Indicates that the definition of this class is now complete.
unsigned getNumBases() const
Retrieves the number of base classes of this class.
base_class_iterator bases_begin()
bool isEmpty() const
Determine whether this is an empty class in the sense of (C++11 [meta.unary.prop]).
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
SourceLocation getBeginLoc() const
static CallExpr * Create(const ASTContext &Ctx, Expr *Fn, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation RParenLoc, FPOptionsOverride FPFeatures, unsigned MinNumArgs=0, ADLCallKind UsesADL=NotADL)
Create a call expression.
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
QualType withConst() const
Retrieves a version of this type with const applied.
const T * getTypePtr() const
Retrieve the underlying type pointer, which refers to a canonical type.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Represents the canonical version of C arrays with a specified constant size.
bool isZeroSize() const
Return true if the size is zero.
llvm::APInt getSize() const
Return the constant array size as an APInt.
uint64_t getZExtSize() const
Return the size zero-extended as a uint64_t.
Represents a concrete matrix type with constant number of rows and columns.
unsigned getNumColumns() const
Returns the number of columns in the matrix.
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
bool isTranslationUnit() const
void addDecl(Decl *D)
Add the declaration D into this context.
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
DeclContext * getNonTransparentContext()
A reference to a declared variable, function, enum, etc.
static DeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *D, bool RefersToEnclosingVariableOrCapture, SourceLocation NameLoc, QualType T, ExprValueKind VK, NamedDecl *FoundD=nullptr, const TemplateArgumentListInfo *TemplateArgs=nullptr, NonOdrUseReason NOUR=NOUR_None)
Decl - This represents one declaration (or definition), e.g.
ASTContext & getASTContext() const LLVM_READONLY
attr_iterator attr_end() const
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
bool isInExportDeclContext() const
Whether this declaration was exported in a lexical context.
attr_iterator attr_begin() const
DeclContext * getNonTransparentDeclContext()
Return the non transparent context.
SourceLocation getLocation() const
void setImplicit(bool I=true)
DeclContext * getDeclContext()
AccessSpecifier getAccess() const
SourceLocation getBeginLoc() const LLVM_READONLY
The name of a declaration.
Represents a ValueDecl that came out of a declarator.
SourceLocation getBeginLoc() const LLVM_READONLY
This represents one expression.
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
Expr * IgnoreParenImpCasts() LLVM_READONLY
Skip past any parentheses and implicit casts which might surround this expression until reaching a fi...
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
std::optional< llvm::APSInt > getIntegerConstantExpr(const ASTContext &Ctx) const
isIntegerConstantExpr - Return the value if this expression is a valid integer constant expression.
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language.
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
bool HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects=true) const
HasSideEffects - This routine returns true for all those expressions which have any effect other than...
void setValueKind(ExprValueKind Cat)
setValueKind - Set the value kind produced by this expression.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
ExtVectorType - Extended vector type.
Represents difference between two FPOptions values.
Represents a member of a struct/union/class.
static FieldDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, Expr *BW, bool Mutable, InClassInitStyle InitStyle)
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string.
Represents a function declaration or definition.
const ParmVarDecl * getParamDecl(unsigned i) const
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
bool isThisDeclarationADefinition() const
Returns whether this specific declaration of the function is also a definition that does not contain ...
QualType getReturnType() const
ArrayRef< ParmVarDecl * > parameters() const
bool isTemplateInstantiation() const
Determines if the given function was instantiated from a function template.
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
DeclarationNameInfo getNameInfo() const
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
bool isDefined(const FunctionDecl *&Definition, bool CheckForPendingFriendDefinition=false) const
Returns true if the function has a definition that does not need to be instantiated.
HLSLBufferDecl - Represent a cbuffer or tbuffer declaration.
static HLSLBufferDecl * Create(ASTContext &C, DeclContext *LexicalParent, bool CBuffer, SourceLocation KwLoc, IdentifierInfo *ID, SourceLocation IDLoc, SourceLocation LBrace)
void addLayoutStruct(CXXRecordDecl *LS)
void setHasValidPackoffset(bool PO)
static HLSLBufferDecl * CreateDefaultCBuffer(ASTContext &C, DeclContext *LexicalParent, ArrayRef< Decl * > DefaultCBufferDecls)
buffer_decl_range buffer_decls() const
static HLSLOutArgExpr * Create(const ASTContext &C, QualType Ty, OpaqueValueExpr *Base, OpaqueValueExpr *OpV, Expr *WB, bool IsInOut)
static HLSLRootSignatureDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation Loc, IdentifierInfo *ID, llvm::dxbc::RootSignatureVersion Version, ArrayRef< llvm::hlsl::rootsig::RootElement > RootElements)
One of these records is kept for each identifier that is lexed.
StringRef getName() const
Return the actual identifier string.
A simple pair of identifier info and location.
SourceLocation getLoc() const
IdentifierInfo * getIdentifierInfo() const
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
Describes an C or C++ initializer list.
Describes an entity that is being initialized.
QualType getType() const
Retrieve type being initialized.
static InitializedEntity InitializeParameter(ASTContext &Context, ParmVarDecl *Parm)
Create the initialization entity for a parameter.
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'.
iterator begin(Source *source, bool LocalOnly=false)
Represents the results of name lookup.
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
This represents a decl that may have a name.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
A C++ nested-name-specifier augmented with source location information.
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Represents a parameter to a function.
ParsedAttr - Represents a syntactic attribute.
unsigned getSemanticSpelling() const
If the parsed attribute has a semantic equivalent, and it would have a semantic Spelling enumeration ...
unsigned getMinArgs() const
bool checkExactlyNumArgs(class Sema &S, unsigned Num) const
Check if the attribute has exactly as many args as Num.
IdentifierLoc * getArgAsIdent(unsigned Arg) const
bool hasParsedType() const
const ParsedType & getTypeArg() const
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this attribute.
bool isArgIdent(unsigned Arg) const
Expr * getArgAsExpr(unsigned Arg) const
AttributeCommonInfo::Kind getKind() const
A (possibly-)qualified type.
void addRestrict()
Add the restrict qualifier to this QualType.
QualType getNonLValueExprType(const ASTContext &Context) const
Determine the type of a (typically non-lvalue) expression with the specified result type.
QualType getDesugaredType(const ASTContext &Context) const
Return the specified type with any "sugar" removed from the type.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
LangAS getAddressSpace() const
Return the address space of this type.
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
QualType getCanonicalType() const
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
bool hasAddressSpace() const
Check if this type has any address space qualifier.
Represents a struct/union/class.
field_iterator field_end() const
field_range fields() const
field_iterator field_begin() const
bool hasBindingInfoForDecl(const VarDecl *VD) const
DeclBindingInfo * getDeclBindingInfo(const VarDecl *VD, ResourceClass ResClass)
DeclBindingInfo * addDeclBindingInfo(const VarDecl *VD, ResourceClass ResClass)
Scope - A scope is a transient data structure that is used while parsing the program.
ASTContext & getASTContext() const
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
ExprResult ActOnOutParamExpr(ParmVarDecl *Param, Expr *Arg)
HLSLRootSignatureDecl * lookupRootSignatureOverrideDecl(DeclContext *DC) const
bool CanPerformElementwiseCast(Expr *Src, QualType DestType)
void handleWaveSizeAttr(Decl *D, const ParsedAttr &AL)
void handleVkLocationAttr(Decl *D, const ParsedAttr &AL)
HLSLAttributedResourceLocInfo TakeLocForHLSLAttribute(const HLSLAttributedResourceType *RT)
void handleSemanticAttr(Decl *D, const ParsedAttr &AL)
bool CanPerformScalarCast(QualType SrcTy, QualType DestTy)
QualType ProcessResourceTypeAttributes(QualType Wrapped)
void handleShaderAttr(Decl *D, const ParsedAttr &AL)
uint32_t getNextImplicitBindingOrderID()
void CheckEntryPoint(FunctionDecl *FD)
void emitLogicalOperatorFixIt(Expr *LHS, Expr *RHS, BinaryOperatorKind Opc)
T * createSemanticAttr(const AttributeCommonInfo &ACI, std::optional< unsigned > Location)
bool initGlobalResourceDecl(VarDecl *VD)
void ActOnEndOfTranslationUnit(TranslationUnitDecl *TU)
bool initGlobalResourceArrayDecl(VarDecl *VD)
HLSLVkConstantIdAttr * mergeVkConstantIdAttr(Decl *D, const AttributeCommonInfo &AL, int Id)
HLSLNumThreadsAttr * mergeNumThreadsAttr(Decl *D, const AttributeCommonInfo &AL, int X, int Y, int Z)
void deduceAddressSpace(VarDecl *Decl)
std::pair< IdentifierInfo *, bool > ActOnStartRootSignatureDecl(StringRef Signature)
Computes the unique Root Signature identifier from the given signature, then lookup if there is a pre...
void handlePackOffsetAttr(Decl *D, const ParsedAttr &AL)
bool diagnosePositionType(QualType T, const ParsedAttr &AL)
bool handleInitialization(VarDecl *VDecl, Expr *&Init)
bool diagnoseInputIDType(QualType T, const ParsedAttr &AL)
void handleParamModifierAttr(Decl *D, const ParsedAttr &AL)
bool CheckResourceBinOp(BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr, SourceLocation Loc)
bool CanPerformAggregateSplatCast(Expr *Src, QualType DestType)
bool IsScalarizedLayoutCompatible(QualType T1, QualType T2) const
QualType ActOnTemplateShorthand(TemplateDecl *Template, SourceLocation NameLoc)
void diagnoseSystemSemanticAttr(Decl *D, const ParsedAttr &AL, std::optional< unsigned > Index)
void handleRootSignatureAttr(Decl *D, const ParsedAttr &AL)
bool CheckCompatibleParameterABI(FunctionDecl *New, FunctionDecl *Old)
QualType handleVectorBinOpConversion(ExprResult &LHS, ExprResult &RHS, QualType LHSType, QualType RHSType, bool IsCompAssign)
QualType checkMatrixComponent(Sema &S, QualType baseType, ExprValueKind &VK, SourceLocation OpLoc, const IdentifierInfo *CompName, SourceLocation CompLoc)
void handleResourceBindingAttr(Decl *D, const ParsedAttr &AL)
bool IsTypedResourceElementCompatible(QualType T1)
bool transformInitList(const InitializedEntity &Entity, InitListExpr *Init)
void handleNumThreadsAttr(Decl *D, const ParsedAttr &AL)
bool ActOnUninitializedVarDecl(VarDecl *D)
void handleVkExtBuiltinInputAttr(Decl *D, const ParsedAttr &AL)
void ActOnTopLevelFunction(FunctionDecl *FD)
bool handleResourceTypeAttr(QualType T, const ParsedAttr &AL)
void handleVkPushConstantAttr(Decl *D, const ParsedAttr &AL)
HLSLShaderAttr * mergeShaderAttr(Decl *D, const AttributeCommonInfo &AL, llvm::Triple::EnvironmentType ShaderType)
void ActOnFinishBuffer(Decl *Dcl, SourceLocation RBrace)
void handleVkBindingAttr(Decl *D, const ParsedAttr &AL)
HLSLParamModifierAttr * mergeParamModifierAttr(Decl *D, const AttributeCommonInfo &AL, HLSLParamModifierAttr::Spelling Spelling)
QualType getInoutParameterType(QualType Ty)
void handleVkConstantIdAttr(Decl *D, const ParsedAttr &AL)
Decl * ActOnStartBuffer(Scope *BufferScope, bool CBuffer, SourceLocation KwLoc, IdentifierInfo *Ident, SourceLocation IdentLoc, SourceLocation LBrace)
HLSLWaveSizeAttr * mergeWaveSizeAttr(Decl *D, const AttributeCommonInfo &AL, int Min, int Max, int Preferred, int SpelledArgsCount)
bool handleRootSignatureElements(ArrayRef< hlsl::RootSignatureElement > Elements)
void ActOnFinishRootSignatureDecl(SourceLocation Loc, IdentifierInfo *DeclIdent, ArrayRef< hlsl::RootSignatureElement > Elements)
Creates the Root Signature decl of the parsed Root Signature elements onto the AST and push it onto c...
void ActOnVariableDeclarator(VarDecl *VD)
bool CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall)
Sema - This implements semantic analysis and AST building for C.
@ LookupOrdinaryName
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....
@ LookupMemberName
Member name lookup, which finds the names of class/struct/union members.
ExtVectorDeclsType ExtVectorDecls
ExtVectorDecls - This is a list all the extended vector types.
ASTContext & getASTContext() const
ExprResult ImpCastExprToType(Expr *E, QualType Type, CastKind CK, ExprValueKind VK=VK_PRValue, const CXXCastPath *BasePath=nullptr, CheckedConversionKind CCK=CheckedConversionKind::Implicit)
ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast.
const LangOptions & getLangOpts() const
ExprResult BuildFieldReferenceExpr(Expr *BaseExpr, bool IsArrow, SourceLocation OpLoc, const CXXScopeSpec &SS, FieldDecl *Field, DeclAccessPair FoundDecl, const DeclarationNameInfo &MemberNameInfo)
bool checkArgCountRange(CallExpr *Call, unsigned MinArgCount, unsigned MaxArgCount)
Checks that a call expression's argument count is in the desired range.
ExternalSemaSource * getExternalSource() const
ExprResult CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc, Expr *Idx, SourceLocation RLoc)
bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, bool InUnqualifiedLookup=false)
Perform qualified name lookup into a given context.
ExprResult PerformCopyInitialization(const InitializedEntity &Entity, SourceLocation EqualLoc, ExprResult Init, bool TopLevelOfInitList=false, bool AllowExplicit=false)
ExprResult CreateBuiltinMatrixSubscriptExpr(Expr *Base, Expr *RowIdx, Expr *ColumnIdx, SourceLocation RBLoc)
Encodes a location in the source.
SourceLocation getLocWithOffset(IntTy Offset) const
Return a source location with the specified offset from this SourceLocation.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getEndLoc() const LLVM_READONLY
void printPretty(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\n", const ASTContext *Context=nullptr) const
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
SourceLocation getBeginLoc() const LLVM_READONLY
StringLiteral - This represents a string literal expression, e.g.
static StringLiteral * Create(const ASTContext &Ctx, StringRef Str, StringLiteralKind Kind, bool Pascal, QualType Ty, ArrayRef< SourceLocation > Locs)
This is the "fully general" constructor that allows representation of strings formed from one or more...
void startDefinition()
Starts the definition of this tag declaration.
Exposes information about the current target.
TargetOptions & getTargetOpts() const
Retrieve the target options.
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
StringRef getPlatformName() const
Retrieve the name of the platform as it is used in the availability attribute.
VersionTuple getPlatformMinVersion() const
Retrieve the minimum desired version of the platform, to which the program should be compiled.
std::string HLSLEntry
The entry point name for HLSL shader being compiled as specified by -E.
A convenient class for passing around template argument information.
void addArgument(const TemplateArgumentLoc &Loc)
The base class of all kinds of template declarations (e.g., class, function, etc.).
Stores a list of template parameters for a TemplateDecl and its derived classes.
The top declaration context.
SourceLocation getBeginLoc() const
Get the begin source location.
A container of type source information.
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
The base class of the type hierarchy.
bool isBooleanType() const
bool isIncompleteArrayType() const
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isConstantArrayType() const
bool hasIntegerRepresentation() const
Determine whether this type has an integer representation of some sort, e.g., it is an integer type o...
CXXRecordDecl * castAsCXXRecordDecl() const
bool isArithmeticType() const
bool isConstantMatrixType() const
bool isHLSLBuiltinIntangibleType() const
bool isPointerType() const
CanQualType getCanonicalTypeUnqualified() const
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
const T * castAs() const
Member-template castAs<specific type>.
bool isReferenceType() const
bool isHLSLIntangibleType() const
bool isEnumeralType() const
bool isScalarType() const
bool isIntegralType(const ASTContext &Ctx) const
Determine whether this type is an integral type.
const Type * getArrayElementTypeNoTypeQual() const
If this is an array type, return the element type of the array, potentially with type qualifiers miss...
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool hasUnsignedIntegerRepresentation() const
Determine whether this type has an unsigned integer representation of some sort, e....
bool isAggregateType() const
Determines whether the type is a C++ aggregate type or C aggregate or union type.
ScalarTypeKind getScalarTypeKind() const
Given that this is a scalar type, classify it.
bool hasSignedIntegerRepresentation() const
Determine whether this type has an signed integer representation of some sort, e.g....
bool isMatrixType() const
bool isHLSLResourceRecord() const
bool hasFloatingRepresentation() const
Determine whether this type has a floating-point representation of some sort, e.g....
bool isVectorType() const
bool isRealFloatingType() const
Floating point categories.
bool isHLSLAttributedResourceType() const
bool isFloatingType() const
const T * getAs() const
Member-template getAs<specific type>'.
const Type * getUnqualifiedDesugaredType() const
Return the specified type with any "sugar" removed from the type, removing any typedefs,...
bool isRecordType() const
bool isHLSLResourceRecordArray() const
void setType(QualType newType)
Represents a variable declaration or definition.
static VarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S)
void setInitStyle(InitializationStyle Style)
@ CallInit
Call-style initialization (C++98)
void setStorageClass(StorageClass SC)
bool hasGlobalStorage() const
Returns true for all variables that do not have local storage.
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Represents a GCC generic vector type.
unsigned getNumElements() const
QualType getElementType() const
void pushName(llvm::StringRef N)
void pushArrayIndex(uint64_t Index)
void pushBaseName(llvm::StringRef N)
IdentifierInfo * getNameAsIdentifier(ASTContext &AST) const
Defines the clang::TargetInfo interface.
uint32_t getResourceDimensions(llvm::dxil::ResourceDimension Dim)
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
if(T->getSizeExpr()) TRY_TO(TraverseStmt(const_cast< Expr * >(T -> getSizeExpr())))
static bool CheckFloatOrHalfRepresentation(Sema *S, SourceLocation Loc, int ArgOrdinal, clang::QualType PassedType)
@ ICIS_NoInit
No in-class initializer.
@ TemplateName
The identifier is a template name. FIXME: Add an annotation for that.
@ OK_Ordinary
An ordinary object is located at an address in memory.
static bool CheckAllArgTypesAreCorrect(Sema *S, CallExpr *TheCall, llvm::ArrayRef< llvm::function_ref< bool(Sema *, SourceLocation, int, QualType)> > Checks)
@ AANT_ArgumentIdentifier
@ Result
The result type of a method or function.
@ Ordinary
This parameter uses ordinary ABI rules for its type.
llvm::Expected< QualType > ExpectedType
@ Template
We are parsing a template declaration.
LLVM_READONLY bool isDigit(unsigned char c)
Return true if this character is an ASCII digit: [0-9].
static bool CheckAllArgsHaveSameType(Sema *S, CallExpr *TheCall)
@ Type
The name was classified as a type.
LangAS
Defines the address space values used by the address space qualifier of QualType.
bool CreateHLSLAttributedResourceType(Sema &S, QualType Wrapped, ArrayRef< const Attr * > AttrList, QualType &ResType, HLSLAttributedResourceLocInfo *LocInfo=nullptr)
CastKind
CastKind - The kind of operation required for a conversion.
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
DynamicRecursiveASTVisitorBase< false > DynamicRecursiveASTVisitor
U cast(CodeGen::Address addr)
@ None
No keyword precedes the qualified type name.
ActionResult< Expr * > ExprResult
Visibility
Describes the different kinds of visibility that a declaration may have.
hash_code hash_value(const clang::dependencies::ModuleID &ID)
__DEVICE__ bool isnan(float __x)
__DEVICE__ _Tp abs(const std::complex< _Tp > &__c)
TypeSourceInfo * ContainedTyInfo
Describes how types, statements, expressions, and declarations should be printed.
unsigned getImplicitOrderID() const
void setCounterImplicitOrderID(unsigned Value) const
bool hasCounterImplicitOrderID() const
unsigned getSpace() const
bool hasImplicitOrderID() const
void setImplicitOrderID(unsigned Value) const
const SourceLocation & getLocation() const
const llvm::hlsl::rootsig::RootElement & getElement() const