Skip to content

[SYCL][NFC] Minor update for mutual diagnostic function of different work_group_size attributes #3128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 24 additions & 28 deletions clang/lib/Sema/SemaDeclAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3006,12 +3006,14 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &AL) {
return true;
};

/// Returns the usigned constant integer value represented by
/// given expression.
// Returns the unsigned constant integer value represented by
// given expression.
auto getExprValue = [](const Expr *E, ASTContext &Ctx) {
return E->getIntegerConstantExpr(Ctx)->getZExtValue();
};

ASTContext &Ctx = S.getASTContext();

if (AL.getKind() == ParsedAttr::AT_SYCLIntelMaxGlobalWorkDim) {
ArrayRef<const Expr *> Dims;
Attr *B = nullptr;
Expand All @@ -3020,51 +3022,45 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &AL) {
else if (const auto *B = D->getAttr<ReqdWorkGroupSizeAttr>())
Dims = B->dimensions();
if (B) {
Result &= checkZeroDim(B, getExprValue(Dims[0], S.getASTContext()),
getExprValue(Dims[1], S.getASTContext()),
getExprValue(Dims[2], S.getASTContext()));
Result &=
checkZeroDim(B, getExprValue(Dims[0], Ctx),
getExprValue(Dims[1], Ctx), getExprValue(Dims[2], Ctx));
}
return Result;
}

if (AL.getKind() == ParsedAttr::AT_SYCLIntelMaxWorkGroupSize)
S.CheckDeprecatedSYCLAttributeSpelling(AL);

// For a SYCLDevice, WorkGroupAttr arguments are reversed.
// "XDim" gets the third argument to the attribute and
// "ZDim" gets the first argument of the attribute.
if (const auto *A = D->getAttr<SYCLIntelMaxGlobalWorkDimAttr>()) {
int64_t AttrValue =
A->getValue()->getIntegerConstantExpr(S.Context)->getSExtValue();
if (AttrValue == 0) {
Result &=
checkZeroDim(A, getExprValue(AL.getArgAsExpr(0), S.getASTContext()),
getExprValue(AL.getArgAsExpr(1), S.getASTContext()),
getExprValue(AL.getArgAsExpr(2), S.getASTContext()),
/*ReverseAttrs=*/true);
if ((A->getValue()->getIntegerConstantExpr(Ctx)->getSExtValue()) == 0) {
Result &= checkZeroDim(A, getExprValue(AL.getArgAsExpr(0), Ctx),
getExprValue(AL.getArgAsExpr(1), Ctx),
getExprValue(AL.getArgAsExpr(2), Ctx),
/*ReverseAttrs=*/true);
}
}

if (const auto *A = D->getAttr<SYCLIntelMaxWorkGroupSizeAttr>()) {
if (!((getExprValue(AL.getArgAsExpr(0), S.getASTContext()) <=
getExprValue(A->getXDim(), S.getASTContext())) &&
(getExprValue(AL.getArgAsExpr(1), S.getASTContext()) <=
getExprValue(A->getYDim(), S.getASTContext())) &&
(getExprValue(AL.getArgAsExpr(2), S.getASTContext()) <=
getExprValue(A->getZDim(), S.getASTContext())))) {
if (!((getExprValue(AL.getArgAsExpr(0), Ctx) <=
getExprValue(A->getXDim(), Ctx)) &&
(getExprValue(AL.getArgAsExpr(1), Ctx) <=
getExprValue(A->getYDim(), Ctx)) &&
(getExprValue(AL.getArgAsExpr(2), Ctx) <=
getExprValue(A->getZDim(), Ctx)))) {
S.Diag(AL.getLoc(), diag::err_conflicting_sycl_function_attributes)
<< AL << A->getSpelling();
Result &= false;
}
}

if (const auto *A = D->getAttr<ReqdWorkGroupSizeAttr>()) {
if (!((getExprValue(AL.getArgAsExpr(0), S.getASTContext()) >=
getExprValue(A->getXDim(), S.getASTContext())) &&
(getExprValue(AL.getArgAsExpr(1), S.getASTContext()) >=
getExprValue(A->getYDim(), S.getASTContext())) &&
(getExprValue(AL.getArgAsExpr(2), S.getASTContext()) >=
getExprValue(A->getZDim(), S.getASTContext())))) {
if (!((getExprValue(AL.getArgAsExpr(0), Ctx) >=
getExprValue(A->getXDim(), Ctx)) &&
(getExprValue(AL.getArgAsExpr(1), Ctx) >=
getExprValue(A->getYDim(), Ctx)) &&
(getExprValue(AL.getArgAsExpr(2), Ctx) >=
getExprValue(A->getZDim(), Ctx)))) {
S.Diag(AL.getLoc(), diag::err_conflicting_sycl_function_attributes)
<< AL << A->getSpelling();
Result &= false;
Expand Down