16#include "llvm/ADT/STLExtras.h"
17#include "llvm/ADT/StringExtras.h"
18#include "llvm/ADT/StringRef.h"
19#include "llvm/Support/ErrorHandling.h"
20#include "llvm/TargetParser/Triple.h"
34 getASTContext(), LexicalParent, CBuffer, KwLoc, Ident, IdentLoc, LBrace);
43 auto *BufDecl = cast<HLSLBufferDecl>(Dcl);
44 BufDecl->setRBraceLoc(RBrace);
50 int X,
int Y,
int Z) {
51 if (HLSLNumThreadsAttr *NT = D->
getAttr<HLSLNumThreadsAttr>()) {
52 if (NT->getX() !=
X || NT->getY() != Y || NT->getZ() != Z) {
53 Diag(NT->getLocation(), diag::err_hlsl_attribute_param_mismatch) << AL;
54 Diag(AL.
getLoc(), diag::note_conflicting_attribute);
64 HLSLShaderAttr::ShaderType ShaderType) {
65 if (HLSLShaderAttr *NT = D->
getAttr<HLSLShaderAttr>()) {
66 if (NT->getType() != ShaderType) {
67 Diag(NT->getLocation(), diag::err_hlsl_attribute_param_mismatch) << AL;
68 Diag(AL.
getLoc(), diag::note_conflicting_attribute);
72 return HLSLShaderAttr::Create(
getASTContext(), ShaderType, AL);
75HLSLParamModifierAttr *
77 HLSLParamModifierAttr::Spelling Spelling) {
80 if (HLSLParamModifierAttr *PA = D->
getAttr<HLSLParamModifierAttr>()) {
81 if ((PA->isIn() && Spelling == HLSLParamModifierAttr::Keyword_out) ||
82 (PA->isOut() && Spelling == HLSLParamModifierAttr::Keyword_in)) {
83 D->
dropAttr<HLSLParamModifierAttr>();
85 return HLSLParamModifierAttr::Create(
87 HLSLParamModifierAttr::Keyword_inout);
89 Diag(AL.
getLoc(), diag::err_hlsl_duplicate_parameter_modifier) << AL;
90 Diag(PA->getLocation(), diag::note_conflicting_attribute);
103 HLSLShaderAttr::ShaderType ShaderType;
104 if (HLSLShaderAttr::ConvertStrToShaderType(
Env, ShaderType)) {
105 if (
const auto *Shader = FD->
getAttr<HLSLShaderAttr>()) {
108 if (Shader->getType() != ShaderType) {
109 Diag(Shader->getLocation(), diag::err_hlsl_entry_shader_attr_mismatch)
121 case llvm::Triple::UnknownEnvironment:
122 case llvm::Triple::Library:
125 llvm_unreachable(
"Unhandled environment in triple");
131 const auto *ShaderAttr = FD->
getAttr<HLSLShaderAttr>();
132 assert(ShaderAttr &&
"Entry point has no shader attribute");
133 HLSLShaderAttr::ShaderType ST = ShaderAttr->getType();
136 case HLSLShaderAttr::Pixel:
137 case HLSLShaderAttr::Vertex:
138 case HLSLShaderAttr::Geometry:
139 case HLSLShaderAttr::Hull:
140 case HLSLShaderAttr::Domain:
141 case HLSLShaderAttr::RayGeneration:
142 case HLSLShaderAttr::Intersection:
143 case HLSLShaderAttr::AnyHit:
144 case HLSLShaderAttr::ClosestHit:
145 case HLSLShaderAttr::Miss:
146 case HLSLShaderAttr::Callable:
147 if (
const auto *NT = FD->
getAttr<HLSLNumThreadsAttr>()) {
149 {HLSLShaderAttr::Compute,
150 HLSLShaderAttr::Amplification,
151 HLSLShaderAttr::Mesh});
156 case HLSLShaderAttr::Compute:
157 case HLSLShaderAttr::Amplification:
158 case HLSLShaderAttr::Mesh:
159 if (!FD->
hasAttr<HLSLNumThreadsAttr>()) {
161 << HLSLShaderAttr::ConvertShaderTypeToStr(ST);
174 Diag(Param->getLocation(), diag::note_previous_decl) << Param;
184 auto *ShaderAttr = EntryPoint->
getAttr<HLSLShaderAttr>();
185 assert(ShaderAttr &&
"Entry point has no shader attribute");
186 HLSLShaderAttr::ShaderType ST = ShaderAttr->getType();
188 switch (AnnotationAttr->
getKind()) {
189 case attr::HLSLSV_DispatchThreadID:
190 case attr::HLSLSV_GroupIndex:
191 if (ST == HLSLShaderAttr::Compute)
196 llvm_unreachable(
"Unknown HLSLAnnotationAttr");
201 const Attr *A, HLSLShaderAttr::ShaderType Stage,
202 std::initializer_list<HLSLShaderAttr::ShaderType> AllowedStages) {
204 llvm::transform(AllowedStages, std::back_inserter(StageStrings),
205 [](HLSLShaderAttr::ShaderType ST) {
207 HLSLShaderAttr::ConvertShaderTypeToStr(ST));
209 Diag(A->
getLoc(), diag::err_hlsl_attr_unsupported_in_stage)
210 << A << HLSLShaderAttr::ConvertShaderTypeToStr(Stage)
211 << (AllowedStages.size() != 1) << join(StageStrings,
", ");
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
This file declares semantic analysis for HLSL constructs.
const TargetInfo & getTargetInfo() const
Attr - This represents one attribute.
attr::Kind getKind() const
SourceRange getRange() const
SourceLocation getLoc() const
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Decl - This represents one declaration (or definition), e.g.
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
SourceLocation getLocation() const
SourceLocation getBeginLoc() const LLVM_READONLY
Represents a function declaration or definition.
ArrayRef< ParmVarDecl * > parameters() const
HLSLBufferDecl - Represent a cbuffer or tbuffer declaration.
static HLSLBufferDecl * Create(ASTContext &C, DeclContext *LexicalParent, bool CBuffer, SourceLocation KwLoc, IdentifierInfo *ID, SourceLocation IDLoc, SourceLocation LBrace)
One of these records is kept for each identifier that is lexed.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Represents a parameter to a function.
Scope - A scope is a transient data structure that is used while parsing the program.
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
ASTContext & getASTContext() const
void CheckEntryPoint(FunctionDecl *FD)
HLSLNumThreadsAttr * mergeNumThreadsAttr(Decl *D, const AttributeCommonInfo &AL, int X, int Y, int Z)
void CheckSemanticAnnotation(FunctionDecl *EntryPoint, const Decl *Param, const HLSLAnnotationAttr *AnnotationAttr)
HLSLShaderAttr * mergeShaderAttr(Decl *D, const AttributeCommonInfo &AL, HLSLShaderAttr::ShaderType ShaderType)
void ActOnTopLevelFunction(FunctionDecl *FD)
void ActOnFinishBuffer(Decl *Dcl, SourceLocation RBrace)
HLSLParamModifierAttr * mergeParamModifierAttr(Decl *D, const AttributeCommonInfo &AL, HLSLParamModifierAttr::Spelling Spelling)
Decl * ActOnStartBuffer(Scope *BufferScope, bool CBuffer, SourceLocation KwLoc, IdentifierInfo *Ident, SourceLocation IdentLoc, SourceLocation LBrace)
void DiagnoseAttrStageMismatch(const Attr *A, HLSLShaderAttr::ShaderType Stage, std::initializer_list< HLSLShaderAttr::ShaderType > AllowedStages)
Sema - This implements semantic analysis and AST building for C.
void PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext=true)
Add this decl to the scope shadowed decl chains.
DeclContext * getCurLexicalContext() const
void PushDeclContext(Scope *S, DeclContext *DC)
Set the current declaration context until it gets popped.
Encodes a location in the source.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
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.
std::string HLSLEntry
The entry point name for HLSL shader being compiled as specified by -E.
Defines the clang::TargetInfo interface.
The JSON file list parser is used to communicate input to InstallAPI.
@ Result
The result type of a method or function.