File indexing completed on 2026-05-10 08:37:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef LLVM_CLANG_SEMA_SEMAHLSL_H
0014 #define LLVM_CLANG_SEMA_SEMAHLSL_H
0015
0016 #include "clang/AST/ASTFwd.h"
0017 #include "clang/AST/Attr.h"
0018 #include "clang/AST/Type.h"
0019 #include "clang/AST/TypeLoc.h"
0020 #include "clang/Basic/SourceLocation.h"
0021 #include "clang/Sema/SemaBase.h"
0022 #include "llvm/ADT/SmallVector.h"
0023 #include "llvm/TargetParser/Triple.h"
0024 #include <initializer_list>
0025
0026 namespace clang {
0027 class AttributeCommonInfo;
0028 class IdentifierInfo;
0029 class ParsedAttr;
0030 class Scope;
0031 class VarDecl;
0032
0033 using llvm::dxil::ResourceClass;
0034
0035
0036
0037 bool CreateHLSLAttributedResourceType(
0038 Sema &S, QualType Wrapped, ArrayRef<const Attr *> AttrList,
0039 QualType &ResType, HLSLAttributedResourceLocInfo *LocInfo = nullptr);
0040
0041 enum class BindingType : uint8_t { NotAssigned, Explicit, Implicit };
0042
0043
0044
0045 struct DeclBindingInfo {
0046 const VarDecl *Decl;
0047 ResourceClass ResClass;
0048 const HLSLResourceBindingAttr *Attr;
0049 BindingType BindType;
0050
0051 DeclBindingInfo(const VarDecl *Decl, ResourceClass ResClass,
0052 BindingType BindType = BindingType::NotAssigned,
0053 const HLSLResourceBindingAttr *Attr = nullptr)
0054 : Decl(Decl), ResClass(ResClass), Attr(Attr), BindType(BindType) {}
0055
0056 void setBindingAttribute(HLSLResourceBindingAttr *A, BindingType BT) {
0057 assert(Attr == nullptr && BindType == BindingType::NotAssigned &&
0058 "binding attribute already assigned");
0059 Attr = A;
0060 BindType = BT;
0061 }
0062 };
0063
0064
0065
0066
0067 class ResourceBindings {
0068 public:
0069 DeclBindingInfo *addDeclBindingInfo(const VarDecl *VD,
0070 ResourceClass ResClass);
0071 DeclBindingInfo *getDeclBindingInfo(const VarDecl *VD,
0072 ResourceClass ResClass);
0073 bool hasBindingInfoForDecl(const VarDecl *VD) const;
0074
0075 private:
0076
0077
0078
0079
0080
0081 llvm::SmallVector<DeclBindingInfo> BindingsList;
0082 llvm::DenseMap<const VarDecl *, unsigned> DeclToBindingListIndex;
0083 };
0084
0085 class SemaHLSL : public SemaBase {
0086 public:
0087 SemaHLSL(Sema &S);
0088
0089 Decl *ActOnStartBuffer(Scope *BufferScope, bool CBuffer, SourceLocation KwLoc,
0090 IdentifierInfo *Ident, SourceLocation IdentLoc,
0091 SourceLocation LBrace);
0092 void ActOnFinishBuffer(Decl *Dcl, SourceLocation RBrace);
0093 HLSLNumThreadsAttr *mergeNumThreadsAttr(Decl *D,
0094 const AttributeCommonInfo &AL, int X,
0095 int Y, int Z);
0096 HLSLWaveSizeAttr *mergeWaveSizeAttr(Decl *D, const AttributeCommonInfo &AL,
0097 int Min, int Max, int Preferred,
0098 int SpelledArgsCount);
0099 HLSLShaderAttr *mergeShaderAttr(Decl *D, const AttributeCommonInfo &AL,
0100 llvm::Triple::EnvironmentType ShaderType);
0101 HLSLParamModifierAttr *
0102 mergeParamModifierAttr(Decl *D, const AttributeCommonInfo &AL,
0103 HLSLParamModifierAttr::Spelling Spelling);
0104 void ActOnTopLevelFunction(FunctionDecl *FD);
0105 void ActOnVariableDeclarator(VarDecl *VD);
0106 void CheckEntryPoint(FunctionDecl *FD);
0107 void CheckSemanticAnnotation(FunctionDecl *EntryPoint, const Decl *Param,
0108 const HLSLAnnotationAttr *AnnotationAttr);
0109 void DiagnoseAttrStageMismatch(
0110 const Attr *A, llvm::Triple::EnvironmentType Stage,
0111 std::initializer_list<llvm::Triple::EnvironmentType> AllowedStages);
0112 void DiagnoseAvailabilityViolations(TranslationUnitDecl *TU);
0113
0114 QualType handleVectorBinOpConversion(ExprResult &LHS, ExprResult &RHS,
0115 QualType LHSType, QualType RHSType,
0116 bool IsCompAssign);
0117 void emitLogicalOperatorFixIt(Expr *LHS, Expr *RHS, BinaryOperatorKind Opc);
0118
0119 void handleNumThreadsAttr(Decl *D, const ParsedAttr &AL);
0120 void handleWaveSizeAttr(Decl *D, const ParsedAttr &AL);
0121 void handleSV_DispatchThreadIDAttr(Decl *D, const ParsedAttr &AL);
0122 void handleSV_GroupThreadIDAttr(Decl *D, const ParsedAttr &AL);
0123 void handleSV_GroupIDAttr(Decl *D, const ParsedAttr &AL);
0124 void handlePackOffsetAttr(Decl *D, const ParsedAttr &AL);
0125 void handleShaderAttr(Decl *D, const ParsedAttr &AL);
0126 void handleResourceBindingAttr(Decl *D, const ParsedAttr &AL);
0127 void handleParamModifierAttr(Decl *D, const ParsedAttr &AL);
0128 bool handleResourceTypeAttr(QualType T, const ParsedAttr &AL);
0129
0130 bool CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
0131 QualType ProcessResourceTypeAttributes(QualType Wrapped);
0132 HLSLAttributedResourceLocInfo
0133 TakeLocForHLSLAttribute(const HLSLAttributedResourceType *RT);
0134
0135
0136 bool IsScalarizedLayoutCompatible(QualType T1, QualType T2) const;
0137 bool IsTypedResourceElementCompatible(QualType T1);
0138
0139 bool CheckCompatibleParameterABI(FunctionDecl *New, FunctionDecl *Old);
0140
0141
0142 bool diagnoseInputIDType(QualType T, const ParsedAttr &AL);
0143
0144 ExprResult ActOnOutParamExpr(ParmVarDecl *Param, Expr *Arg);
0145
0146 QualType getInoutParameterType(QualType Ty);
0147
0148 private:
0149
0150
0151 llvm::SmallVector<const Attr *> HLSLResourcesTypeAttrs;
0152
0153
0154
0155 llvm::DenseMap<const HLSLAttributedResourceType *,
0156 HLSLAttributedResourceLocInfo>
0157 LocsForHLSLAttributedResources;
0158
0159
0160 ResourceBindings Bindings;
0161
0162 private:
0163 void collectResourcesOnVarDecl(VarDecl *D);
0164 void collectResourcesOnUserRecordDecl(const VarDecl *VD,
0165 const RecordType *RT);
0166 void processExplicitBindingsOnDecl(VarDecl *D);
0167 };
0168
0169 }
0170
0171 #endif