From 0b1253000023ad29e34506854ff33ba3977180a5 Mon Sep 17 00:00:00 2001 From: Soumi Manna Date: Wed, 30 Dec 2020 20:45:32 -0800 Subject: [PATCH] [SYCL] [FPGA] Fix linking error with template parameter support for work_group_size attributes A linking error was introduced on PR https://github.com/intel/llvm/pull/2906 where template declaration and definition was added in different files. This patch fixes the issue by moving the template definition for addIntelSYCLTripleArgFunctionAttr to Sema.h. Signed-off-by: Soumi Manna --- clang/include/clang/Sema/Sema.h | 74 +++++++++++++++++++++++++++++++++ clang/lib/Sema/SemaDeclAttr.cpp | 74 --------------------------------- 2 files changed, 74 insertions(+), 74 deletions(-) diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index b4d5511ca2ff6..6bf763dac15e0 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -12962,6 +12962,80 @@ void Sema::addIntelSYCLSingleArgFunctionAttr(Decl *D, D->addAttr(::new (Context) AttrType(Context, CI, E)); } +template +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 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 +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 +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 void Sema::AddOneConstantValueAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E) { diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index d86f5af065694..6275ff18cff2c 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -3061,80 +3061,6 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &AL, return Result; } -template -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 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 -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 -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 static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) {