Skip to content

[SYCL] [FPGA] Fix linking error with template parameter support for work_group_size attributes #2975

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 1 commit into from
Dec 31, 2020
Merged
Show file tree
Hide file tree
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
74 changes: 74 additions & 0 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -12962,6 +12962,80 @@ void Sema::addIntelSYCLSingleArgFunctionAttr(Decl *D,
D->addAttr(::new (Context) AttrType(Context, CI, E));
}

template <typename AttrInfo>
static bool handleMaxWorkSizeAttrExpr(Sema &S, const AttrInfo &AI,
const Expr *Expr, unsigned &Val,
unsigned Idx) {
assert(Expr && "Attribute must have an argument.");

if (!Expr->isInstantiationDependent()) {
Optional<llvm::APSInt> ArgVal =
Expr->getIntegerConstantExpr(S.getASTContext());

if (!ArgVal) {
S.Diag(AI.getLocation(), diag::err_attribute_argument_type)
<< &AI << AANT_ArgumentIntegerConstant << Expr->getSourceRange();
return false;
}

if (ArgVal->isNegative()) {
S.Diag(Expr->getExprLoc(),
diag::warn_attribute_requires_non_negative_integer_argument)
<< &AI << Idx << Expr->getSourceRange();
return true;
}

Val = ArgVal->getZExtValue();
if (Val == 0) {
S.Diag(Expr->getExprLoc(), diag::err_attribute_argument_is_zero)
<< &AI << Expr->getSourceRange();
return false;
}
}
return true;
}

template <typename AttrType>
static bool checkMaxWorkSizeAttrArguments(Sema &S, Expr *XDimExpr,
Expr *YDimExpr, Expr *ZDimExpr,
const AttrType &Attr) {
// Accept template arguments for now as they depend on something else.
// We'll get to check them when they eventually get instantiated.
if (XDimExpr->isValueDependent() ||
(YDimExpr && YDimExpr->isValueDependent()) ||
(ZDimExpr && ZDimExpr->isValueDependent()))
return false;

unsigned XDim = 0;
if (!handleMaxWorkSizeAttrExpr(S, Attr, XDimExpr, XDim, 0))
return true;

unsigned YDim = 0;
if (YDimExpr && !handleMaxWorkSizeAttrExpr(S, Attr, YDimExpr, YDim, 1))
return true;

unsigned ZDim = 0;
if (ZDimExpr && !handleMaxWorkSizeAttrExpr(S, Attr, ZDimExpr, ZDim, 2))
return true;

return false;
}

template <typename WorkGroupAttrType>
void Sema::addIntelSYCLTripleArgFunctionAttr(Decl *D,
const AttributeCommonInfo &CI,
Expr *XDimExpr, Expr *YDimExpr,
Expr *ZDimExpr) {
WorkGroupAttrType TmpAttr(Context, CI, XDimExpr, YDimExpr, ZDimExpr);

if (checkMaxWorkSizeAttrArguments(*this, XDimExpr, YDimExpr, ZDimExpr,
TmpAttr))
return;

D->addAttr(::new (Context)
WorkGroupAttrType(Context, CI, XDimExpr, YDimExpr, ZDimExpr));
}

template <typename AttrType>
void Sema::AddOneConstantValueAttr(Decl *D, const AttributeCommonInfo &CI,
Expr *E) {
Expand Down
74 changes: 0 additions & 74 deletions clang/lib/Sema/SemaDeclAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3061,80 +3061,6 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &AL,
return Result;
}

template <typename AttrInfo>
static bool handleMaxWorkSizeAttrExpr(Sema &S, const AttrInfo &AI,
const Expr *Expr, unsigned &Val,
unsigned Idx) {
assert(Expr && "Attribute must have an argument.");

if (!Expr->isInstantiationDependent()) {
Optional<llvm::APSInt> ArgVal =
Expr->getIntegerConstantExpr(S.getASTContext());

if (!ArgVal) {
S.Diag(getAttrLoc(AI), diag::err_attribute_argument_type)
<< &AI << AANT_ArgumentIntegerConstant << Expr->getSourceRange();
return false;
}

if (ArgVal->isNegative()) {
S.Diag(Expr->getExprLoc(),
diag::warn_attribute_requires_non_negative_integer_argument)
<< &AI << Idx << Expr->getSourceRange();
return true;
}

Val = ArgVal->getZExtValue();
if (Val == 0) {
S.Diag(Expr->getExprLoc(), diag::err_attribute_argument_is_zero)
<< &AI << Expr->getSourceRange();
return false;
}
}
return true;
}

template <typename AttrType>
static bool checkMaxWorkSizeAttrArguments(Sema &S, Expr *XDimExpr,
Expr *YDimExpr, Expr *ZDimExpr,
const AttrType &Attr) {
// Accept template arguments for now as they depend on something else.
// We'll get to check them when they eventually get instantiated.
if (XDimExpr->isValueDependent() ||
(YDimExpr && YDimExpr->isValueDependent()) ||
(ZDimExpr && ZDimExpr->isValueDependent()))
return false;

unsigned XDim = 0;
if (!handleMaxWorkSizeAttrExpr(S, Attr, XDimExpr, XDim, 0))
return true;

unsigned YDim = 0;
if (YDimExpr && !handleMaxWorkSizeAttrExpr(S, Attr, YDimExpr, YDim, 1))
return true;

unsigned ZDim = 0;
if (ZDimExpr && !handleMaxWorkSizeAttrExpr(S, Attr, ZDimExpr, ZDim, 2))
return true;

return false;
}

template <typename WorkGroupAttrType>
void Sema::addIntelSYCLTripleArgFunctionAttr(Decl *D,
const AttributeCommonInfo &CI,
Expr *XDimExpr, Expr *YDimExpr,
Expr *ZDimExpr) {
WorkGroupAttrType TmpAttr(Context, CI, XDimExpr, YDimExpr, ZDimExpr);

if (checkMaxWorkSizeAttrArguments(*this, XDimExpr, YDimExpr, ZDimExpr,
TmpAttr))
return;

D->addAttr(::new (Context)
WorkGroupAttrType(Context, CI, XDimExpr, YDimExpr, ZDimExpr));
}

// Handles reqd_work_group_size and max_work_group_size.
template <typename WorkGroupAttr>
static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) {
Expand Down