18#include "llvm/Support/AtomicOrdering.h"
28 unsigned OrderIndex, ScopeIndex;
31 assert(FD &&
"AMDGPU builtins should not be used outside of a function");
32 llvm::StringMap<bool> CallerFeatureMap;
38 case AMDGPU::BI__builtin_amdgcn_raw_ptr_buffer_load_lds:
39 case AMDGPU::BI__builtin_amdgcn_struct_ptr_buffer_load_lds:
40 case AMDGPU::BI__builtin_amdgcn_load_to_lds:
41 case AMDGPU::BI__builtin_amdgcn_global_load_lds: {
42 constexpr const int SizeIdx = 2;
48 switch (Size.getSExtValue()) {
60 Diag(ArgExpr->
getExprLoc(), diag::err_amdgcn_load_lds_size_invalid_value)
62 Diag(ArgExpr->
getExprLoc(), diag::note_amdgcn_load_lds_size_valid_value)
67 case AMDGPU::BI__builtin_amdgcn_get_fpenv:
68 case AMDGPU::BI__builtin_amdgcn_set_fpenv:
70 case AMDGPU::BI__builtin_amdgcn_atomic_inc32:
71 case AMDGPU::BI__builtin_amdgcn_atomic_inc64:
72 case AMDGPU::BI__builtin_amdgcn_atomic_dec32:
73 case AMDGPU::BI__builtin_amdgcn_atomic_dec64:
77 case AMDGPU::BI__builtin_amdgcn_fence:
81 case AMDGPU::BI__builtin_amdgcn_mov_dpp:
83 case AMDGPU::BI__builtin_amdgcn_mov_dpp8:
85 case AMDGPU::BI__builtin_amdgcn_update_dpp:
87 case AMDGPU::BI__builtin_amdgcn_cvt_scale_pk8_f16_fp8:
88 case AMDGPU::BI__builtin_amdgcn_cvt_scale_pk8_bf16_fp8:
89 case AMDGPU::BI__builtin_amdgcn_cvt_scale_pk8_f16_bf8:
90 case AMDGPU::BI__builtin_amdgcn_cvt_scale_pk8_bf16_bf8:
91 case AMDGPU::BI__builtin_amdgcn_cvt_scale_pk8_f16_fp4:
92 case AMDGPU::BI__builtin_amdgcn_cvt_scale_pk8_bf16_fp4:
93 case AMDGPU::BI__builtin_amdgcn_cvt_scale_pk8_f32_fp8:
94 case AMDGPU::BI__builtin_amdgcn_cvt_scale_pk8_f32_bf8:
95 case AMDGPU::BI__builtin_amdgcn_cvt_scale_pk8_f32_fp4:
96 case AMDGPU::BI__builtin_amdgcn_cvt_scale_pk16_f16_fp6:
97 case AMDGPU::BI__builtin_amdgcn_cvt_scale_pk16_bf16_fp6:
98 case AMDGPU::BI__builtin_amdgcn_cvt_scale_pk16_f16_bf6:
99 case AMDGPU::BI__builtin_amdgcn_cvt_scale_pk16_bf16_bf6:
100 case AMDGPU::BI__builtin_amdgcn_cvt_scale_pk16_f32_fp6:
101 case AMDGPU::BI__builtin_amdgcn_cvt_scale_pk16_f32_bf6:
108 auto ArgExpr = Arg.
get();
112 return Diag(ArgExpr->getExprLoc(), diag::err_typecheck_expect_int)
113 << ArgExpr->getType();
114 auto Ord = ArgResult.
Val.
getInt().getZExtValue();
118 if (!llvm::isValidAtomicOrderingCABI(Ord))
119 return Diag(ArgExpr->getBeginLoc(),
120 diag::warn_atomic_op_has_invalid_memory_order)
121 << 0 << ArgExpr->getSourceRange();
122 switch (
static_cast<llvm::AtomicOrderingCABI
>(Ord)) {
123 case llvm::AtomicOrderingCABI::relaxed:
124 case llvm::AtomicOrderingCABI::consume:
125 if (BuiltinID == AMDGPU::BI__builtin_amdgcn_fence)
126 return Diag(ArgExpr->getBeginLoc(),
127 diag::warn_atomic_op_has_invalid_memory_order)
128 << 0 << ArgExpr->getSourceRange();
130 case llvm::AtomicOrderingCABI::acquire:
131 case llvm::AtomicOrderingCABI::release:
132 case llvm::AtomicOrderingCABI::acq_rel:
133 case llvm::AtomicOrderingCABI::seq_cst:
137 Arg = TheCall->
getArg(ScopeIndex);
141 if (!ArgExpr->EvaluateAsConstantExpr(ArgResult1,
getASTContext()))
142 return Diag(ArgExpr->getExprLoc(), diag::err_expr_not_string_literal)
143 << ArgExpr->getType();
149 unsigned NumDataArgs) {
150 assert(NumDataArgs <= 2);
155 for (
unsigned I = 0; I != NumDataArgs; ++I) {
156 Args[I] = TheCall->
getArg(I);
157 ArgTys[I] = Args[I]->
getType();
159 if (!ArgTys[I]->isArithmeticType() || ArgTys[I]->isAnyComplexType()) {
161 diag::err_typecheck_cond_expect_int_float)
169 if (
getASTContext().hasSameUnqualifiedType(ArgTys[0], ArgTys[1]))
172 if (((ArgTys[0]->isUnsignedIntegerType() &&
173 ArgTys[1]->isSignedIntegerType()) ||
174 (ArgTys[0]->isSignedIntegerType() &&
175 ArgTys[1]->isUnsignedIntegerType())) &&
181 diag::err_typecheck_call_different_arg_types)
182 << ArgTys[0] << ArgTys[1];
188 const AMDGPUFlatWorkGroupSizeAttr &
Attr) {
202 if (
Min == 0 &&
Max != 0) {
216AMDGPUFlatWorkGroupSizeAttr *
220 AMDGPUFlatWorkGroupSizeAttr TmpAttr(Context, CI, MinExpr, MaxExpr);
224 return ::new (Context)
225 AMDGPUFlatWorkGroupSizeAttr(Context, CI, MinExpr, MaxExpr);
245 const AMDGPUWavesPerEUAttr &
Attr) {
263 if (
Min == 0 &&
Max != 0) {
277AMDGPUWavesPerEUAttr *
281 AMDGPUWavesPerEUAttr TmpAttr(Context, CI, MinExpr, MaxExpr);
286 return ::new (Context) AMDGPUWavesPerEUAttr(Context, CI, MinExpr, MaxExpr);
306 uint32_t NumSGPR = 0;
316 uint32_t NumVGPR = 0;
328 const AMDGPUMaxNumWorkGroupsAttr &
Attr) {
341 Expr *Exprs[3] = {XExpr, YExpr, ZExpr};
342 for (
int i = 0; i < 3; i++) {
361 AMDGPUMaxNumWorkGroupsAttr TmpAttr(Context, CI, XExpr, YExpr, ZExpr);
367 return ::new (Context)
368 AMDGPUMaxNumWorkGroupsAttr(Context, CI, XExpr, YExpr, ZExpr);
This file declares semantic analysis functions specific to AMDGPU.
Enumerates target-specific builtins in their own namespaces within namespace clang.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
void getFunctionFeatureMap(llvm::StringMap< bool > &FeatureMap, const FunctionDecl *) const
Attr - This represents one attribute.
SourceLocation getLocation() const
SourceLocation getLoc() const
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
Decl - This represents one declaration (or definition), e.g.
This represents one expression.
bool isValueDependent() const
Determines whether the value of this expression depends on.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
ParsedAttr - Represents a syntactic attribute.
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this attribute.
Expr * getArgAsExpr(unsigned Arg) const
bool checkAtLeastNumArgs(class Sema &S, unsigned Num) const
Check if the attribute has at least as many args as Num.
bool checkAtMostNumArgs(class Sema &S, unsigned Num) const
Check if the attribute has at most as many args as Num.
A (possibly-)qualified type.
void handleAMDGPUMaxNumWorkGroupsAttr(Decl *D, const ParsedAttr &AL)
void addAMDGPUFlatWorkGroupSizeAttr(Decl *D, const AttributeCommonInfo &CI, Expr *Min, Expr *Max)
addAMDGPUFlatWorkGroupSizeAttr - Adds an amdgpu_flat_work_group_size attribute to a particular declar...
void handleAMDGPUFlatWorkGroupSizeAttr(Decl *D, const ParsedAttr &AL)
void handleAMDGPUNumSGPRAttr(Decl *D, const ParsedAttr &AL)
AMDGPUMaxNumWorkGroupsAttr * CreateAMDGPUMaxNumWorkGroupsAttr(const AttributeCommonInfo &CI, Expr *XExpr, Expr *YExpr, Expr *ZExpr)
Create an AMDGPUMaxNumWorkGroupsAttr attribute.
AMDGPUWavesPerEUAttr * CreateAMDGPUWavesPerEUAttr(const AttributeCommonInfo &CI, Expr *Min, Expr *Max)
Create an AMDGPUWavesPerEUAttr attribute.
void handleAMDGPUNumVGPRAttr(Decl *D, const ParsedAttr &AL)
AMDGPUFlatWorkGroupSizeAttr * CreateAMDGPUFlatWorkGroupSizeAttr(const AttributeCommonInfo &CI, Expr *Min, Expr *Max)
Create an AMDGPUWavesPerEUAttr attribute.
bool checkMovDPPFunctionCall(CallExpr *TheCall, unsigned NumArgs, unsigned NumDataArgs)
void handleAMDGPUWavesPerEUAttr(Decl *D, const ParsedAttr &AL)
bool CheckAMDGCNBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall)
void addAMDGPUWavesPerEUAttr(Decl *D, const AttributeCommonInfo &CI, Expr *Min, Expr *Max)
addAMDGPUWavePersEUAttr - Adds an amdgpu_waves_per_eu attribute to a particular declaration.
void addAMDGPUMaxNumWorkGroupsAttr(Decl *D, const AttributeCommonInfo &CI, Expr *XExpr, Expr *YExpr, Expr *ZExpr)
addAMDGPUMaxNumWorkGroupsAttr - Adds an amdgpu_max_num_work_groups attribute to a particular declarat...
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
ASTContext & getASTContext() const
Sema - This implements semantic analysis and AST building for C.
FunctionDecl * getCurFunctionDecl(bool AllowLambda=false) const
Returns a pointer to the innermost enclosing function, or nullptr if the current context is not insid...
bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, TypeSourceInfo *T, UnexpandedParameterPackContext UPPC)
If the given type contains an unexpanded parameter pack, diagnose the error.
bool checkUInt32Argument(const AttrInfo &AI, const Expr *Expr, uint32_t &Val, unsigned Idx=UINT_MAX, bool StrictlyUnsigned=false)
If Expr is a valid integer constant, get the value of the integer expression and return success or fa...
bool checkArgCountRange(CallExpr *Call, unsigned MinArgCount, unsigned MaxArgCount)
Checks that a call expression's argument count is in the desired range.
ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result, VerifyICEDiagnoser &Diagnoser, AllowFoldKind CanFold=AllowFoldKind::No)
VerifyIntegerConstantExpression - Verifies that an expression is an ICE, and reports the appropriate ...
bool BuiltinConstantArgRange(CallExpr *TheCall, int ArgNum, int Low, int High, bool RangeIsError=true)
BuiltinConstantArgRange - Handle a check if argument ArgNum of CallExpr TheCall is a constant express...
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
bool evaluateRequiredTargetFeatures(llvm::StringRef RequiredFatures, const llvm::StringMap< bool > &TargetFetureMap)
Returns true if the required target features of a builtin function are enabled.
The JSON file list parser is used to communicate input to InstallAPI.
static bool checkAMDGPUMaxNumWorkGroupsArguments(Sema &S, Expr *XExpr, Expr *YExpr, Expr *ZExpr, const AMDGPUMaxNumWorkGroupsAttr &Attr)
static bool checkAMDGPUFlatWorkGroupSizeArguments(Sema &S, Expr *MinExpr, Expr *MaxExpr, const AMDGPUFlatWorkGroupSizeAttr &Attr)
static bool checkAMDGPUWavesPerEUArguments(Sema &S, Expr *MinExpr, Expr *MaxExpr, const AMDGPUWavesPerEUAttr &Attr)
EvalResult is a struct with detailed info about an evaluated expression.
APValue Val
Val - This is the value the expression can be folded to.