From a42d18c6b2483cd2e8e57a566f60b49f196d37c0 Mon Sep 17 00:00:00 2001 From: Soumi Manna Date: Fri, 18 Dec 2020 06:49:47 -0800 Subject: [PATCH 01/21] [SYCL] Add template parameter support for work_group_size attributes This patch adds support for template parameter on triple arguments SYCL function attributes such as: 1. [[intel::reqd_work_group_size()]] 2. [[cl::reqd_work_group_size()]] 3. [[intel::max_work_group_size()]] Default arguments in ReqWorkGroupSize can be used only with intel::reqd_work_group_size spelling. Checks correctness of mutual usage of different work_group_size attributes: reqd_work_group_size, max_work_group_size and max_global_work_dim. Values of reqd_work_group_size arguments shall be equal or less than values coming from max_work_group_size. In case the value of 'max_global_work_dim' attribute equals to 0 we shall ensure that if max_work_group_size and reqd_work_group_size attributes exist, they hold equal values (1, 1, 1). This patch does not add template parameter support on WorkGroupSizeHintAttr since the attribute does not have a [[]] spelling because it is an OpenCL-related attribute. updates sema/codegen tests with mock headers on device. splits tests of 'intel-max-work-group-size' and 'intel-reqd-work-group-size' attributes into host and device. Signed-off-by: Soumi Manna --- clang/include/clang/Basic/Attr.td | 11 +- clang/include/clang/Sema/Sema.h | 4 + clang/lib/CodeGen/CodeGenFunction.cpp | 52 +++-- clang/lib/CodeGen/TargetInfo.cpp | 31 ++- clang/lib/Sema/SemaDecl.cpp | 13 +- clang/lib/Sema/SemaDeclAttr.cpp | 197 +++++++++++++++--- clang/lib/Sema/SemaSYCL.cpp | 27 ++- .../lib/Sema/SemaTemplateInstantiateDecl.cpp | 38 ++++ .../CodeGenSYCL/intel-max-work-group-size.cpp | 47 +++-- .../test/CodeGenSYCL/reqd-work-group-size.cpp | 53 +++-- .../CodeGenSYCL/sycl-multi-kernel-attr.cpp | 52 ++++- clang/test/SemaOpenCL/invalid-kernel-attrs.cl | 10 +- .../intel-max-work-group-size-device.cpp | 92 ++++++++ .../intel-max-work-group-size-host.cpp | 9 + .../SemaSYCL/intel-max-work-group-size.cpp | 86 -------- .../intel-reqd-work-group-size-device.cpp | 151 ++++++++++++++ .../intel-reqd-work-group-size-host.cpp | 13 ++ .../SemaSYCL/intel-reqd-work-group-size.cpp | 136 ------------ .../redeclaration-attribute-propagation.cpp | 11 +- .../SemaSYCL/reqd-work-group-size-device.cpp | 107 ++++++---- ...ice-intel-max-work-group-size-template.cpp | 77 +++++++ ...ce-intel-reqd-work-group-size-template.cpp | 77 +++++++ ...l-device-reqd-work-group-size-template.cpp | 77 +++++++ 23 files changed, 997 insertions(+), 374 deletions(-) create mode 100644 clang/test/SemaSYCL/intel-max-work-group-size-device.cpp create mode 100644 clang/test/SemaSYCL/intel-max-work-group-size-host.cpp delete mode 100644 clang/test/SemaSYCL/intel-max-work-group-size.cpp create mode 100644 clang/test/SemaSYCL/intel-reqd-work-group-size-device.cpp create mode 100644 clang/test/SemaSYCL/intel-reqd-work-group-size-host.cpp delete mode 100644 clang/test/SemaSYCL/intel-reqd-work-group-size.cpp create mode 100644 clang/test/SemaSYCL/sycl-device-intel-max-work-group-size-template.cpp create mode 100644 clang/test/SemaSYCL/sycl-device-intel-reqd-work-group-size-template.cpp create mode 100644 clang/test/SemaSYCL/sycl-device-reqd-work-group-size-template.cpp diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 04b3f5e88e394..aeafbeba66ac1 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -1284,9 +1284,9 @@ def SYCLIntelSchedulerTargetFmaxMhz : InheritableAttr { def SYCLIntelMaxWorkGroupSize : InheritableAttr { let Spellings = [CXX11<"intelfpga","max_work_group_size">, CXX11<"intel","max_work_group_size">]; - let Args = [UnsignedArgument<"XDim">, - UnsignedArgument<"YDim">, - UnsignedArgument<"ZDim">]; + let Args = [ExprArgument<"XDim">, + ExprArgument<"YDim">, + ExprArgument<"ZDim">]; let LangOpts = [SYCLIsDevice, SYCLIsHost]; let Subjects = SubjectList<[Function], ErrorDiag>; let Documentation = [SYCLIntelMaxWorkGroupSizeAttrDocs]; @@ -2785,8 +2785,9 @@ def ReqdWorkGroupSize : InheritableAttr { let Spellings = [GNU<"reqd_work_group_size">, CXX11<"intel","reqd_work_group_size">, CXX11<"cl","reqd_work_group_size">]; - let Args = [UnsignedArgument<"XDim">, DefaultUnsignedArgument<"YDim", 1>, - DefaultUnsignedArgument<"ZDim", 1>]; + let Args = [ExprArgument<"XDim">, + ExprArgument<"YDim", /*optional*/1>, + ExprArgument<"ZDim", /*optional*/1>]; let Subjects = SubjectList<[Function], ErrorDiag>; let Documentation = [ReqdWorkGroupSizeAttrDocs]; } diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index d0a82c982c521..af97d4e43f1b7 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -10151,6 +10151,10 @@ class Sema final { template void addIntelSYCLSingleArgFunctionAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E); + template + void addIntelSYCLTripleArgFunctionAttr(Decl *D, const AttributeCommonInfo &CI, + Expr *XDimExpr, Expr *YDimExpr, + Expr *ZDimExpr); /// AddAlignedAttr - Adds an aligned attribute to a particular declaration. void AddAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E, bool IsPackExpansion); diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 5c947cc66b42d..a559b175df854 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -619,12 +619,24 @@ void CodeGenFunction::EmitOpenCLKernelMetadata(const FunctionDecl *FD, Fn->setMetadata("work_group_size_hint", llvm::MDNode::get(Context, AttrMDArgs)); } - if (const ReqdWorkGroupSizeAttr *A = FD->getAttr()) { + if (const ReqdWorkGroupSizeAttr *A = + FD->getAttr()) { + llvm::LLVMContext &Context = getLLVMContext(); + Optional XDimVal = + A->getXDim()->getIntegerConstantExpr(FD->getASTContext()); + assert(XDimVal.hasValue() && "Not an integer constant expression"); + Optional YDimVal = + A->getYDim()->getIntegerConstantExpr(FD->getASTContext()); + assert(YDimVal.hasValue() && "Not an integer constant expression"); + Optional ZDimVal = + A->getZDim()->getIntegerConstantExpr(FD->getASTContext()); + assert(ZDimVal.hasValue() && "Not an integer constant expression"); llvm::Metadata *AttrMDArgs[] = { - llvm::ConstantAsMetadata::get(Builder.getInt32(A->getXDim())), - llvm::ConstantAsMetadata::get(Builder.getInt32(A->getYDim())), - llvm::ConstantAsMetadata::get(Builder.getInt32(A->getZDim()))}; - Fn->setMetadata("reqd_work_group_size", llvm::MDNode::get(Context, AttrMDArgs)); + llvm::ConstantAsMetadata::get(Builder.getInt32(XDimVal->getSExtValue())), + llvm::ConstantAsMetadata::get(Builder.getInt32(YDimVal->getSExtValue())), + llvm::ConstantAsMetadata::get(Builder.getInt32(ZDimVal->getSExtValue()))}; + Fn->setMetadata("reqd_work_group_size", + llvm::MDNode::get(Context, AttrMDArgs)); } if (const IntelReqdSubGroupSizeAttr *A = @@ -670,16 +682,6 @@ void CodeGenFunction::EmitOpenCLKernelMetadata(const FunctionDecl *FD, llvm::MDNode::get(Context, AttrMDArgs)); } - if (const SYCLIntelMaxWorkGroupSizeAttr *A = - FD->getAttr()) { - llvm::Metadata *AttrMDArgs[] = { - llvm::ConstantAsMetadata::get(Builder.getInt32(A->getXDim())), - llvm::ConstantAsMetadata::get(Builder.getInt32(A->getYDim())), - llvm::ConstantAsMetadata::get(Builder.getInt32(A->getZDim()))}; - Fn->setMetadata("max_work_group_size", - llvm::MDNode::get(Context, AttrMDArgs)); - } - if (const SYCLIntelMaxGlobalWorkDimAttr *A = FD->getAttr()) { llvm::LLVMContext &Context = getLLVMContext(); @@ -692,6 +694,26 @@ void CodeGenFunction::EmitOpenCLKernelMetadata(const FunctionDecl *FD, llvm::MDNode::get(Context, AttrMDArgs)); } + if (const SYCLIntelMaxWorkGroupSizeAttr *A = + FD->getAttr()) { + llvm::LLVMContext &Context = getLLVMContext(); + Optional XDimVal = + A->getXDim()->getIntegerConstantExpr(FD->getASTContext()); + assert(XDimVal.hasValue() && "Not an integer constant expression"); + Optional YDimVal = + A->getYDim()->getIntegerConstantExpr(FD->getASTContext()); + assert(YDimVal.hasValue() && "Not an integer constant expression"); + Optional ZDimVal = + A->getZDim()->getIntegerConstantExpr(FD->getASTContext()); + assert(ZDimVal.hasValue() && "Not an integer constant expression"); + llvm::Metadata *AttrMDArgs[] = { + llvm::ConstantAsMetadata::get(Builder.getInt32(XDimVal->getSExtValue())), + llvm::ConstantAsMetadata::get(Builder.getInt32(YDimVal->getSExtValue())), + llvm::ConstantAsMetadata::get(Builder.getInt32(ZDimVal->getSExtValue()))}; + Fn->setMetadata("max_work_group_size", + llvm::MDNode::get(Context, AttrMDArgs)); + } + if (const SYCLIntelNoGlobalWorkOffsetAttr *A = FD->getAttr()) { const Expr *Arg = A->getValue(); diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp index 35b2edcacc0fa..3a3c21f1003a7 100644 --- a/clang/lib/CodeGen/TargetInfo.cpp +++ b/clang/lib/CodeGen/TargetInfo.cpp @@ -8141,16 +8141,25 @@ void TCETargetCodeGenInfo::setTargetAttributes( SmallVector Operands; Operands.push_back(llvm::ConstantAsMetadata::get(F)); + unsigned XDim = Attr->getXDim() + ->EvaluateKnownConstInt(M.getContext()) + .getExtValue(); + unsigned YDim = Attr->getYDim() + ->EvaluateKnownConstInt(M.getContext()) + .getExtValue(); + unsigned ZDim = Attr->getZDim() + ->EvaluateKnownConstInt(M.getContext()) + .getExtValue(); Operands.push_back( llvm::ConstantAsMetadata::get(llvm::Constant::getIntegerValue( - M.Int32Ty, llvm::APInt(32, Attr->getXDim())))); + M.Int32Ty, llvm::APInt(32, XDim)))); Operands.push_back( llvm::ConstantAsMetadata::get(llvm::Constant::getIntegerValue( - M.Int32Ty, llvm::APInt(32, Attr->getYDim())))); + M.Int32Ty, llvm::APInt(32, YDim)))); Operands.push_back( llvm::ConstantAsMetadata::get(llvm::Constant::getIntegerValue( - M.Int32Ty, llvm::APInt(32, Attr->getZDim())))); + M.Int32Ty, llvm::APInt(32, ZDim)))); // Add a boolean constant operand for "required" (true) or "hint" // (false) for implementing the work_group_size_hint attr later. @@ -9030,6 +9039,9 @@ void AMDGPUTargetCodeGenInfo::setTargetAttributes( if (ReqdWGS || FlatWGS) { unsigned Min = 0; unsigned Max = 0; + unsigned XDim = 0; + unsigned YDim = 0; + unsigned ZDim = 0; if (FlatWGS) { Min = FlatWGS->getMin() ->EvaluateKnownConstInt(M.getContext()) @@ -9038,8 +9050,19 @@ void AMDGPUTargetCodeGenInfo::setTargetAttributes( ->EvaluateKnownConstInt(M.getContext()) .getExtValue(); } + if (ReqdWGS) { + XDim = ReqdWGS->getXDim() + ->EvaluateKnownConstInt(M.getContext()) + .getExtValue(); + YDim = ReqdWGS->getYDim() + ->EvaluateKnownConstInt(M.getContext()) + .getExtValue(); + ZDim = ReqdWGS->getZDim() + ->EvaluateKnownConstInt(M.getContext()) + .getExtValue(); + } if (ReqdWGS && Min == 0 && Max == 0) - Min = Max = ReqdWGS->getXDim() * ReqdWGS->getYDim() * ReqdWGS->getZDim(); + Min = Max = XDim * YDim * ZDim; if (Min != 0) { assert(Min <= Max && "Min must be less than or equal Max"); diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index e97f0c7be033e..a0ef7b39a743b 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -3198,6 +3198,10 @@ static void adjustDeclContextForDeclaratorDecl(DeclaratorDecl *NewD, FixSemaDC(VD->getDescribedVarTemplate()); } +static int64_t getIntExprValue(const Expr *E, ASTContext &Ctx) { + return E->getIntegerConstantExpr(Ctx)->getSExtValue(); +} + template static void checkDimensionsAndSetDiagnostics(Sema &S, FunctionDecl *New, FunctionDecl *Old) { @@ -3207,9 +3211,12 @@ static void checkDimensionsAndSetDiagnostics(Sema &S, FunctionDecl *New, if (!NewDeclAttr || !OldDeclAttr) return; - if ((NewDeclAttr->getXDim() != OldDeclAttr->getXDim()) || - (NewDeclAttr->getYDim() != OldDeclAttr->getYDim()) || - (NewDeclAttr->getZDim() != OldDeclAttr->getZDim())) { + if ((getIntExprValue(NewDeclAttr->getXDim(), S.getASTContext()) != + getIntExprValue(OldDeclAttr->getXDim(), S.getASTContext())) || + (getIntExprValue(NewDeclAttr->getYDim(), S.getASTContext()) != + getIntExprValue(OldDeclAttr->getYDim(), S.getASTContext())) || + (getIntExprValue(NewDeclAttr->getZDim(), S.getASTContext()) != + getIntExprValue(OldDeclAttr->getZDim(), S.getASTContext()))) { S.Diag(New->getLocation(), diag::err_conflicting_sycl_function_attributes) << OldDeclAttr << NewDeclAttr; S.Diag(New->getLocation(), diag::warn_duplicate_attribute) << OldDeclAttr; diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 07f67ad0d84e9..571d2dc9b1fe7 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -2893,6 +2893,7 @@ static void handleWeakImportAttr(Sema &S, Decl *D, const ParsedAttr &AL) { D->addAttr(::new (S.Context) WeakImportAttr(S.Context, AL)); } +// Handles reqd_work_group_size and max_work_group_size // Checks correctness of mutual usage of different work_group_size attributes: // reqd_work_group_size, max_work_group_size and max_global_work_dim. // Values of reqd_work_group_size arguments shall be equal or less than values @@ -2900,6 +2901,11 @@ static void handleWeakImportAttr(Sema &S, Decl *D, const ParsedAttr &AL) { // In case the value of 'max_global_work_dim' attribute equals to 0 we shall // ensure that if max_work_group_size and reqd_work_group_size attributes exist, // they hold equal values (1, 1, 1). + +static int64_t getIntExprValue(const Expr *E, ASTContext &Ctx) { + return E->getIntegerConstantExpr(Ctx)->getSExtValue(); +} + static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr, uint32_t WGSize[3]) { bool Result = true; @@ -2918,10 +2924,17 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr, }; if (Attr.getKind() == ParsedAttr::AT_SYCLIntelMaxGlobalWorkDim) { - if (const auto *A = D->getAttr()) - Result &= checkZeroDim(A, A->getXDim(), A->getYDim(), A->getZDim()); - if (const auto *A = D->getAttr()) - Result &= checkZeroDim(A, A->getXDim(), A->getYDim(), A->getZDim()); + if (const auto *A = D->getAttr()) { + Result &= checkZeroDim(A, + getIntExprValue(A->getXDim(), S.getASTContext()), + getIntExprValue(A->getYDim(), S.getASTContext()), + getIntExprValue(A->getZDim(), S.getASTContext())); + } + if (const auto *A = D->getAttr()) { + Result &= checkZeroDim(A, getIntExprValue(A->getXDim(), S.getASTContext()), + getIntExprValue(A->getYDim(), S.getASTContext()), + getIntExprValue(A->getZDim(), S.getASTContext())); + } return Result; } @@ -2929,13 +2942,20 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr, int64_t AttrValue = A->getValue()->getIntegerConstantExpr(S.Context)->getSExtValue(); if (AttrValue == 0) - Result &= checkZeroDim(A, WGSize[0], WGSize[1], WGSize[2], + Result &= checkZeroDim(A, + getIntExprValue(Attr.getArgAsExpr(0), S.getASTContext()), + getIntExprValue(Attr.getArgAsExpr(0), S.getASTContext()), + getIntExprValue(Attr.getArgAsExpr(0), S.getASTContext()), /*ReverseAttrs=*/true); } if (const auto *A = D->getAttr()) { - if (!(WGSize[0] <= A->getXDim() && WGSize[1] <= A->getYDim() && - WGSize[2] <= A->getZDim())) { + if (!(getIntExprValue(Attr.getArgAsExpr(0), S.getASTContext()) + <= getIntExprValue(A->getXDim(), S.getASTContext()) && + getIntExprValue(Attr.getArgAsExpr(1), S.getASTContext()) + <= getIntExprValue(A->getYDim(), S.getASTContext()) && + getIntExprValue(Attr.getArgAsExpr(2), S.getASTContext()) + <= getIntExprValue(A->getZDim(), S.getASTContext()))) { S.Diag(Attr.getLoc(), diag::err_conflicting_sycl_function_attributes) << Attr << A->getSpelling(); Result &= false; @@ -2948,8 +2968,12 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr, << "'intel::max_work_group_size'"; if (const auto *A = D->getAttr()) { - if (!(WGSize[0] >= A->getXDim() && WGSize[1] >= A->getYDim() && - WGSize[2] >= A->getZDim())) { + if (!(getIntExprValue(Attr.getArgAsExpr(0), S.getASTContext()) + >= getIntExprValue(A->getXDim(), S.getASTContext()) && + getIntExprValue(Attr.getArgAsExpr(1), S.getASTContext()) + >= getIntExprValue(A->getYDim(), S.getASTContext()) && + getIntExprValue(Attr.getArgAsExpr(2), S.getASTContext()) + >= getIntExprValue(A->getZDim(), S.getASTContext()))) { S.Diag(Attr.getLoc(), diag::err_conflicting_sycl_function_attributes) << Attr << A->getSpelling(); Result &= false; @@ -2958,47 +2982,162 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr, return Result; } -// Handles reqd_work_group_size, work_group_size_hint and max_work_group_size +template +void Sema::addIntelSYCLTripleArgFunctionAttr(Decl *D, + const AttributeCommonInfo &CI, + Expr *XDim, Expr *YDim, Expr *ZDim) { + assert(XDim && "Attribute must have an argument."); + assert(YDim && "Attribute must have an argument."); + assert(ZDim && "Attribute must have an argument."); + + if (!XDim->isInstantiationDependent() || + !YDim->isInstantiationDependent() || + !ZDim->isInstantiationDependent()) { + Optional XDimVal= XDim->getIntegerConstantExpr(getASTContext()); + Optional YDimVal= YDim->getIntegerConstantExpr(getASTContext()); + Optional ZDimVal= ZDim->getIntegerConstantExpr(getASTContext()); + + if (!XDimVal) { + Diag(XDim->getExprLoc(), diag::err_attribute_argument_type) + << CI << AANT_ArgumentIntegerConstant << XDim->getSourceRange(); + return; + } + + if (!YDimVal) { + Diag(YDim->getExprLoc(), diag::err_attribute_argument_type) + << CI << AANT_ArgumentIntegerConstant << YDim->getSourceRange(); + return; + } + + if (!ZDimVal) { + Diag(ZDim->getExprLoc(), diag::err_attribute_argument_type) + << CI << AANT_ArgumentIntegerConstant << ZDim->getSourceRange(); + return; + } + + int32_t XDimInt = XDimVal->getSExtValue(); + if (XDimInt <= 0) { + Diag(XDim->getExprLoc(), diag::err_attribute_requires_positive_integer) + << CI << /*positive*/ 0; + return; + } + + int32_t YDimInt = YDimVal->getSExtValue(); + if (YDimInt <= 0) { + Diag(YDim->getExprLoc(), diag::err_attribute_requires_positive_integer) + << CI << /*positive*/ 0; + return; + } + + int32_t ZDimInt = ZDimVal->getSExtValue(); + if (ZDimInt <= 0) { + Diag(ZDim->getExprLoc(), diag::err_attribute_requires_positive_integer) + << CI << /*positive*/ 0; + return; + } + } + + D->addAttr(::new (Context) WorkGroupAttrType (Context, CI, XDim, YDim, ZDim)); +} + template static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) { if (D->isInvalidDecl()) return; uint32_t WGSize[3]; - if (AL.getKind() == ParsedAttr::AT_ReqdWorkGroupSize && - AL.getAttributeSpellingListIndex() == - ReqdWorkGroupSizeAttr::CXX11_intel_reqd_work_group_size) { - WGSize[1] = ReqdWorkGroupSizeAttr::DefaultYDim; - WGSize[2] = ReqdWorkGroupSizeAttr::DefaultZDim; - } else if (!checkAttributeNumArgs(S, AL, 3)) + + Expr *XDimExpr = AL.getArgAsExpr(0); + + // If no attribute argument is specified, set to default value '1' + // in ReqdWorkGroupSizeAttr for only with intel::reqd_work_group_size spelling. + Expr *YDimExpr = AL.isArgExpr(1) + ? AL.getArgAsExpr(1) + : ((AL.getKind() == ParsedAttr::AT_ReqdWorkGroupSize && + AL.getAttributeSpellingListIndex() == + ReqdWorkGroupSizeAttr::CXX11_intel_reqd_work_group_size) + ? (IntegerLiteral::Create(S.Context, llvm::APInt(32, 1), + S.Context.IntTy, AL.getLoc())) + : nullptr); + + // If no attribute argument is specified, set to default value '1' + // in ReqdWorkGroupSizeAttr for only with intel::reqd_work_group_size spelling. + Expr *ZDimExpr = AL.isArgExpr(2) + ? AL.getArgAsExpr(2) + : ((AL.getKind() == ParsedAttr::AT_ReqdWorkGroupSize && + AL.getAttributeSpellingListIndex() == + ReqdWorkGroupSizeAttr::CXX11_intel_reqd_work_group_size) + ? (IntegerLiteral::Create(S.Context, llvm::APInt(32, 1), + S.Context.IntTy, AL.getLoc())) + : nullptr); + + if ((AL.getKind() == ParsedAttr::AT_ReqdWorkGroupSize && + AL.getAttributeSpellingListIndex() == + ReqdWorkGroupSizeAttr::CXX11_cl_reqd_work_group_size) || + (AL.getKind() == ParsedAttr::AT_SYCLIntelMaxWorkGroupSize)) { + if (!checkAttributeNumArgs(S, AL, 3)) + return; + } + + if (S.getLangOpts().SYCLIsDevice) { + std::swap(XDimExpr, ZDimExpr); + } + + if (WorkGroupAttr *ExistingAttr = D->getAttr()) { + Optional XDimVal= XDimExpr->getIntegerConstantExpr(S.getASTContext()); + Optional YDimVal = YDimExpr->getIntegerConstantExpr(S.getASTContext()); + Optional ZDimVal = ZDimExpr->getIntegerConstantExpr(S.getASTContext()); + Optional ExistingXDimVal = + ExistingAttr->getXDim()->getIntegerConstantExpr(S.getASTContext()); + Optional ExistingYDimVal = + ExistingAttr->getYDim()->getIntegerConstantExpr(S.getASTContext()); + Optional ExistingZDimVal = + ExistingAttr->getZDim()->getIntegerConstantExpr(S.getASTContext()); + + // Compare attribute arguments value and warn for a mismatch. + if (ExistingAttr && + !((ExistingXDimVal->getExtValue() == XDimVal->getExtValue()) && + (ExistingYDimVal->getExtValue() == YDimVal->getExtValue()) && + (ExistingZDimVal->getExtValue() == ZDimVal->getExtValue()))) { + S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) + << AL; + } + } + + if (!checkWorkGroupSizeValues(S, D, AL, WGSize)) + return; + + S.addIntelSYCLTripleArgFunctionAttr(D, AL, XDimExpr, YDimExpr, + ZDimExpr); +} + +// Handles work_group_size_hint. +static void handleWorkGroupSizeHint(Sema &S, Decl *D, const ParsedAttr &AL) { + uint32_t WGSize[3]; + + if (!checkAttributeNumArgs(S, AL, 3)) return; for (unsigned i = 0; i < 3; ++i) { - if (i < AL.getNumArgs() && - !checkUInt32Argument(S, AL, AL.getArgAsExpr(i), WGSize[i], i, + if (!checkUInt32Argument(S, AL, AL.getArgAsExpr(i), WGSize[i], i, /*StrictlyUnsigned=*/true)) - return; + return; + if (WGSize[i] == 0) { S.Diag(AL.getLoc(), diag::err_attribute_argument_is_zero) - << AL << AL.getArgAsExpr(i)->getSourceRange(); + << AL << AL.getArgAsExpr(i)->getSourceRange(); return; } } - // For a SYCLDevice WorkGroupAttr arguments are reversed - if (S.getLangOpts().SYCLIsDevice) { - std::swap(WGSize[0], WGSize[2]); - } - WorkGroupAttr *Existing = D->getAttr(); + WorkGroupSizeHintAttr *Existing = D->getAttr(); if (Existing && !(Existing->getXDim() == WGSize[0] && Existing->getYDim() == WGSize[1] && Existing->getZDim() == WGSize[2])) S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL; - if (!checkWorkGroupSizeValues(S, D, AL, WGSize)) - return; D->addAttr(::new (S.Context) - WorkGroupAttr(S.Context, AL, WGSize[0], WGSize[1], WGSize[2])); + WorkGroupSizeHintAttr(S.Context, AL, WGSize[0], WGSize[1], WGSize[2])); } // Handles intel_reqd_sub_group_size. @@ -8353,7 +8492,7 @@ static void ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, handleXReturnsXRetainedAttr(S, D, AL); break; case ParsedAttr::AT_WorkGroupSizeHint: - handleWorkGroupSize(S, D, AL); + handleWorkGroupSizeHint(S, D, AL); break; case ParsedAttr::AT_ReqdWorkGroupSize: handleWorkGroupSize(S, D, AL); diff --git a/clang/lib/Sema/SemaSYCL.cpp b/clang/lib/Sema/SemaSYCL.cpp index 5c66ceee82128..3d174e7342943 100644 --- a/clang/lib/Sema/SemaSYCL.cpp +++ b/clang/lib/Sema/SemaSYCL.cpp @@ -3283,9 +3283,12 @@ void Sema::MarkDevice(void) { case attr::Kind::ReqdWorkGroupSize: { auto *Attr = cast(A); if (auto *Existing = SYCLKernel->getAttr()) { - if (Existing->getXDim() != Attr->getXDim() || - Existing->getYDim() != Attr->getYDim() || - Existing->getZDim() != Attr->getZDim()) { + if ((getIntExprValue(Existing->getXDim(), getASTContext()) != + getIntExprValue(Attr->getXDim(), getASTContext())) || + (getIntExprValue(Existing->getYDim(), getASTContext()) != + getIntExprValue(Attr->getYDim(), getASTContext())) || + (getIntExprValue(Existing->getZDim(), getASTContext()) != + getIntExprValue(Attr->getZDim(), getASTContext()))) { Diag(SYCLKernel->getLocation(), diag::err_conflicting_sycl_kernel_attributes); Diag(Existing->getLocation(), diag::note_conflicting_attribute); @@ -3294,9 +3297,12 @@ void Sema::MarkDevice(void) { } } else if (auto *Existing = SYCLKernel->getAttr()) { - if (Existing->getXDim() < Attr->getXDim() || - Existing->getYDim() < Attr->getYDim() || - Existing->getZDim() < Attr->getZDim()) { + if ((getIntExprValue(Existing->getXDim(), getASTContext()) < + getIntExprValue(Attr->getXDim(), getASTContext())) || + (getIntExprValue(Existing->getYDim(), getASTContext()) < + getIntExprValue(Attr->getYDim(), getASTContext())) || + (getIntExprValue(Existing->getZDim(), getASTContext()) < + getIntExprValue(Attr->getZDim(), getASTContext()))) { Diag(SYCLKernel->getLocation(), diag::err_conflicting_sycl_kernel_attributes); Diag(Existing->getLocation(), diag::note_conflicting_attribute); @@ -3313,9 +3319,12 @@ void Sema::MarkDevice(void) { case attr::Kind::SYCLIntelMaxWorkGroupSize: { auto *Attr = cast(A); if (auto *Existing = SYCLKernel->getAttr()) { - if (Existing->getXDim() > Attr->getXDim() || - Existing->getYDim() > Attr->getYDim() || - Existing->getZDim() > Attr->getZDim()) { + if ((getIntExprValue(Existing->getXDim(), getASTContext()) > + getIntExprValue(Attr->getXDim(), getASTContext())) || + (getIntExprValue(Existing->getYDim(), getASTContext()) > + getIntExprValue(Attr->getYDim(), getASTContext())) || + (getIntExprValue(Existing->getZDim(), getASTContext()) > + getIntExprValue(Attr->getZDim(), getASTContext()))) { Diag(SYCLKernel->getLocation(), diag::err_conflicting_sycl_kernel_attributes); Diag(Existing->getLocation(), diag::note_conflicting_attribute); diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 85fd57c459bf3..f776bb539ce9f 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -604,6 +604,32 @@ static void instantiateIntelSYCLFunctionAttr( Result.getAs()); } +template +static void instantiateIntelSYCTripleLFunctionAttr( + Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, + const AttrName *Attr, Decl *New) { + EnterExpressionEvaluationContext Unevaluated( + S, Sema::ExpressionEvaluationContext::ConstantEvaluated); + + ExprResult Result = S.SubstExpr(Attr->getXDim(), TemplateArgs); + if (Result.isInvalid()) + return; + Expr *XDimExpr = Result.getAs(); + + Result = S.SubstExpr(Attr->getYDim(), TemplateArgs); + if (Result.isInvalid()) + return; + Expr *YDimExpr = Result.getAs(); + + Result = S.SubstExpr(Attr->getZDim(), TemplateArgs); + if (Result.isInvalid()) + return; + Expr *ZDimExpr = Result.getAs(); + + S.addIntelSYCLTripleArgFunctionAttr(New, *Attr, XDimExpr, + YDimExpr, ZDimExpr); +} + void Sema::InstantiateAttrsForDecl( const MultiLevelTemplateArgumentList &TemplateArgs, const Decl *Tmpl, Decl *New, LateInstantiatedAttrVec *LateAttrs, @@ -781,6 +807,18 @@ void Sema::InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs, *this, TemplateArgs, SYCLIntelNoGlobalWorkOffset, New); continue; } + if (const auto *ReqdWorkGroupSize = + dyn_cast(TmplAttr)) { + instantiateIntelSYCTripleLFunctionAttr( + *this, TemplateArgs, ReqdWorkGroupSize, New); + continue; + } + if (const auto *SYCLIntelMaxWorkGroupSize = + dyn_cast(TmplAttr)) { + instantiateIntelSYCTripleLFunctionAttr( + *this, TemplateArgs, SYCLIntelMaxWorkGroupSize, New); + continue; + } // Existing DLL attribute on the instantiation takes precedence. if (TmplAttr->getKind() == attr::DLLExport || TmplAttr->getKind() == attr::DLLImport) { diff --git a/clang/test/CodeGenSYCL/intel-max-work-group-size.cpp b/clang/test/CodeGenSYCL/intel-max-work-group-size.cpp index 87117c585e0d1..3d6a1a85b186c 100644 --- a/clang/test/CodeGenSYCL/intel-max-work-group-size.cpp +++ b/clang/test/CodeGenSYCL/intel-max-work-group-size.cpp @@ -1,24 +1,47 @@ -// RUN: %clang_cc1 -fsycl -fsycl-is-device -triple spir64-unknown-unknown-sycldevice -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -fsycl -fsycl-is-device -internal-isystem %S/Inputs -triple spir64-unknown-unknown-sycldevice -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s + +#include "sycl.hpp" + +using namespace cl::sycl; +queue q; class Foo { public: [[intel::max_work_group_size(1, 1, 1)]] void operator()() const {} }; -template -__attribute__((sycl_kernel)) void kernel(const Func &kernelFunc) { - kernelFunc(); -} +template +class Functor { +public: + [[intel::max_work_group_size(SIZE, SIZE1, SIZE2)]] void operator()() const {} +}; + +template +[[intel::max_work_group_size(N, N1, N2)]] void func() {} + +int main() { + q.submit([&](handler &h) { + Foo boo; + h.single_task(boo); + + h.single_task( + []() [[intel::max_work_group_size(8, 8, 8)]]{}); -void bar() { - Foo boo; - kernel(boo); + Functor<2, 2, 2> f; + h.single_task(f); - kernel( - []() [[intel::max_work_group_size(8, 8, 8)]]{}); + h.single_task([]() { + func<4, 4, 4>(); + }); + }); + return 0; } -// CHECK: define spir_kernel void @{{.*}}kernel_name1() {{.*}} !max_work_group_size ![[NUM1:[0-9]+]] -// CHECK: define spir_kernel void @{{.*}}kernel_name2() {{.*}} !max_work_group_size ![[NUM8:[0-9]+]] +// CHECK: define spir_kernel void @{{.*}}kernel_name1"() #0 {{.*}} !max_work_group_size ![[NUM1:[0-9]+]] +// CHECK: define spir_kernel void @{{.*}}kernel_name2"() #0 {{.*}} !max_work_group_size ![[NUM8:[0-9]+]] +// CHECK: define spir_kernel void @{{.*}}kernel_name3"() #0 {{.*}} !max_work_group_size ![[NUM2:[0-9]+]] +// CHECK: define spir_kernel void @{{.*}}kernel_name4"() #0 {{.*}} !max_work_group_size ![[NUM4:[0-9]+]] // CHECK: ![[NUM1]] = !{i32 1, i32 1, i32 1} // CHECK: ![[NUM8]] = !{i32 8, i32 8, i32 8} +// CHECK: ![[NUM2]] = !{i32 2, i32 2, i32 2} +// CHECK: ![[NUM4]] = !{i32 4, i32 4, i32 4} diff --git a/clang/test/CodeGenSYCL/reqd-work-group-size.cpp b/clang/test/CodeGenSYCL/reqd-work-group-size.cpp index 72ba3492d2ed0..5ef0ad78108dc 100644 --- a/clang/test/CodeGenSYCL/reqd-work-group-size.cpp +++ b/clang/test/CodeGenSYCL/reqd-work-group-size.cpp @@ -1,4 +1,9 @@ -// RUN: %clang_cc1 -fsycl -fsycl-is-device -triple spir64-unknown-unknown-sycldevice -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -fsycl -fsycl-is-device -internal-isystem %S/Inputs -triple spir64-unknown-unknown-sycldevice -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s + +#include "sycl.hpp" + +using namespace cl::sycl; +queue q; class Functor32x16x16 { public: @@ -14,25 +19,43 @@ class Functor { } }; -template -__attribute__((sycl_kernel)) void kernel(const Func &kernelFunc) { - kernelFunc(); -} +template +class FunctorTemp { +public: + [[cl::reqd_work_group_size(SIZE, SIZE1, SIZE2)]] void operator()() const {} +}; + +template +[[cl::reqd_work_group_size(N, N1, N2)]] void func() {} + +int main() { + q.submit([&](handler &h) { + Functor32x16x16 f32x16x16; + h.single_task(f32x16x16); + + Functor f; + h.single_task(f); -void bar() { - Functor32x16x16 f32x16x16; - kernel(f32x16x16); + h.single_task( + []() [[cl::reqd_work_group_size(8, 8, 8)]]{}); - Functor f; - kernel(f); + FunctorTemp<2, 2, 2> ft; + h.single_task(ft); - kernel( - []() [[cl::reqd_work_group_size(8, 8, 8)]]{}); + h.single_task([]() { + func<8, 4, 4>(); + }); + }); + return 0; } -// CHECK: define spir_kernel void @{{.*}}kernel_name1() {{.*}} !reqd_work_group_size ![[WGSIZE32:[0-9]+]] -// CHECK: define spir_kernel void @{{.*}}kernel_name2() {{.*}} !reqd_work_group_size ![[WGSIZE8:[0-9]+]] -// CHECK: define spir_kernel void @{{.*}}kernel_name3() {{.*}} !reqd_work_group_size ![[WGSIZE88:[0-9]+]] +// CHECK: define spir_kernel void @{{.*}}kernel_name1"() #0 {{.*}} !reqd_work_group_size ![[WGSIZE32:[0-9]+]] +// CHECK: define spir_kernel void @{{.*}}kernel_name2"() #0 {{.*}} !reqd_work_group_size ![[WGSIZE8:[0-9]+]] +// CHECK: define spir_kernel void @{{.*}}kernel_name3"() #0 {{.*}} !reqd_work_group_size ![[WGSIZE88:[0-9]+]] +// CHECK: define spir_kernel void @{{.*}}kernel_name4"() #0 {{.*}} !reqd_work_group_size ![[WGSIZE22:[0-9]+]] +// CHECK: define spir_kernel void @{{.*}}kernel_name5"() #0 {{.*}} !reqd_work_group_size ![[WGSIZE44:[0-9]+]] // CHECK: ![[WGSIZE32]] = !{i32 16, i32 16, i32 32} // CHECK: ![[WGSIZE8]] = !{i32 1, i32 1, i32 8} // CHECK: ![[WGSIZE88]] = !{i32 8, i32 8, i32 8} +// CHECK: ![[WGSIZE22]] = !{i32 2, i32 2, i32 2} +// CHECK: ![[WGSIZE44]] = !{i32 4, i32 4, i32 8} diff --git a/clang/test/CodeGenSYCL/sycl-multi-kernel-attr.cpp b/clang/test/CodeGenSYCL/sycl-multi-kernel-attr.cpp index 486975a4081ba..7fb26c1a8c09d 100644 --- a/clang/test/CodeGenSYCL/sycl-multi-kernel-attr.cpp +++ b/clang/test/CodeGenSYCL/sycl-multi-kernel-attr.cpp @@ -1,20 +1,54 @@ -// RUN: %clang_cc1 -fsycl -fsycl-is-device -triple spir64-unknown-unknown-sycldevice -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -fsycl -fsycl-is-device -internal-isystem %S/Inputs -triple spir64-unknown-unknown-sycldevice -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s + +#include "sycl.hpp" + +using namespace cl::sycl; +queue q; class Functor { public: [[intel::reqd_sub_group_size(4), cl::reqd_work_group_size(32, 16, 16)]] void operator()() const {} }; -template -__attribute__((sycl_kernel)) void kernel(const Func &kernelFunc) { - kernelFunc(); -} +class Functor1 { +public: + [[intel::reqd_sub_group_size(2), intel::reqd_work_group_size(64, 32, 32)]] void operator()() const {} +}; + +template +class Functor2 { +public: + [[intel::reqd_work_group_size(SIZE, SIZE1, SIZE2)]] void operator()() const {} +}; + +template +[[intel::reqd_work_group_size(N, N1, N2)]] void func() {} + +int main() { + q.submit([&](handler &h) { + Functor foo; + h.single_task(foo); + + Functor1 foo1; + h.single_task(foo1); + + Functor2<2, 2, 2> foo2; + h.single_task(foo2); -void bar() { - Functor foo; - kernel(foo); + h.single_task([]() { + func<8, 4, 4>(); + }); + }); + return 0; } -// CHECK: define spir_kernel void @{{.*}}kernel_name() {{.*}} !reqd_work_group_size ![[WGSIZE:[0-9]+]] !intel_reqd_sub_group_size ![[SGSIZE:[0-9]+]] +// CHECK: define spir_kernel void @{{.*}}kernel_name1"() #0 {{.*}} !reqd_work_group_size ![[WGSIZE:[0-9]+]] !intel_reqd_sub_group_size ![[SGSIZE:[0-9]+]] +// CHECK: define spir_kernel void @{{.*}}kernel_name2"() #0 {{.*}} !reqd_work_group_size ![[WGSIZE1:[0-9]+]] !intel_reqd_sub_group_size ![[SGSIZE1:[0-9]+]] +// CHECK: define spir_kernel void @{{.*}}kernel_name3"() #0 {{.*}} !reqd_work_group_size ![[WGSIZE2:[0-9]+]] +// CHECK: define spir_kernel void @{{.*}}kernel_name4"() #0 {{.*}} !reqd_work_group_size ![[WGSIZE3:[0-9]+]] // CHECK: ![[WGSIZE]] = !{i32 16, i32 16, i32 32} // CHECK: ![[SGSIZE]] = !{i32 4} +// CHECK: ![[WGSIZE1]] = !{i32 32, i32 32, i32 64} +// CHECK: ![[SGSIZE1]] = !{i32 2} +// CHECK: ![[WGSIZE2]] = !{i32 2, i32 2, i32 2} +// CHECK: ![[WGSIZE3]] = !{i32 4, i32 4, i32 8} diff --git a/clang/test/SemaOpenCL/invalid-kernel-attrs.cl b/clang/test/SemaOpenCL/invalid-kernel-attrs.cl index cc68fe41e5416..44e045296ddb6 100644 --- a/clang/test/SemaOpenCL/invalid-kernel-attrs.cl +++ b/clang/test/SemaOpenCL/invalid-kernel-attrs.cl @@ -30,9 +30,9 @@ void f_kernel_image2d_t( kernel image2d_t image ) { // expected-error {{'kernel' int __kernel x; // expected-error {{'__kernel' attribute only applies to functions}} } -kernel __attribute__((reqd_work_group_size(1,2,0))) void kernel11(){} // expected-error {{'reqd_work_group_size' attribute must be greater than 0}} -kernel __attribute__((reqd_work_group_size(1,0,2))) void kernel12(){} // expected-error {{'reqd_work_group_size' attribute must be greater than 0}} -kernel __attribute__((reqd_work_group_size(0,1,2))) void kernel13(){} // expected-error {{'reqd_work_group_size' attribute must be greater than 0}} +kernel __attribute__((reqd_work_group_size(1,2,0))) void kernel11(){} // expected-error {{'reqd_work_group_size' attribute requires a positive integral compile time constant expression}} +kernel __attribute__((reqd_work_group_size(1,0,2))) void kernel12(){} // expected-error {{'reqd_work_group_size' attribute requires a positive integral compile time constant expression}} +kernel __attribute__((reqd_work_group_size(0,1,2))) void kernel13(){} // expected-error {{'reqd_work_group_size' attribute requires a positive integral compile time constant expression}} __attribute__((intel_reqd_sub_group_size(8))) void kernel14(){} // expected-error {{attribute 'intel_reqd_sub_group_size' can only be applied to an OpenCL kernel}} kernel __attribute__((intel_reqd_sub_group_size(0))) void kernel15() {} // expected-error {{'intel_reqd_sub_group_size' attribute requires a positive integral compile time constant expression}} @@ -42,8 +42,8 @@ kernel __attribute__((intel_reqd_sub_group_size(-1))) void kernel16() {} // expe kernel __attribute__((intel_reqd_sub_group_size(8))) __attribute__((intel_reqd_sub_group_size(16))) void kernel17() {} //expected-warning{{attribute 'intel_reqd_sub_group_size' is already applied with different parameters}} __kernel __attribute__((work_group_size_hint(8,-16,32))) void neg1() {} //expected-error{{'work_group_size_hint' attribute requires a non-negative integral compile time constant expression}} -__kernel __attribute__((reqd_work_group_size(8,16,-32))) void neg2(){} // expected-error{{'reqd_work_group_size' attribute requires a non-negative integral compile time constant expression}} +__kernel __attribute__((reqd_work_group_size(8,16,-32))) void neg2(){} // expected-error{{'reqd_work_group_size' attribute requires a positive integral compile time constant expression}} // 4294967294 is a negative integer if treated as signed. // Should compile successfully, since we expect an unsigned. -__kernel __attribute__((reqd_work_group_size(8,16,4294967294))) void ok1(){} +__kernel __attribute__((reqd_work_group_size(8,16,4294967294))) void ok1(){} //expected-error{{'reqd_work_group_size' attribute requires a positive integral compile time constant expression}} diff --git a/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp b/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp new file mode 100644 index 0000000000000..e802baf5f7d0d --- /dev/null +++ b/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp @@ -0,0 +1,92 @@ +// RUN: %clang_cc1 %s -fsyntax-only -fsycl -fsycl-is-device -internal-isystem %S/Inputs -Wno-sycl-2017-compat -triple spir64 -DTRIGGER_ERROR -verify +// RUN: %clang_cc1 %s -fsyntax-only -ast-dump -fsycl -fsycl-is-device -internal-isystem %S/Inputs -Wno-sycl-2017-compat -triple spir64 | FileCheck %s + +#include "sycl.hpp" + +using namespace cl::sycl; +queue q; + +#ifndef __SYCL_DEVICE_ONLY__ +struct FuncObj { + [[intel::max_work_group_size(1, 1, 1)]] // expected-no-diagnostics + void + operator()() const {} +}; + +void foo() { + q.submit([&](handler &h) { + h.single_task(FuncObj()); + }); +} + +#else // __SYCL_DEVICE_ONLY__ + +[[intel::max_work_group_size(2, 2, 2)]] void func_do_not_ignore() {} + +struct FuncObj { + [[intel::max_work_group_size(4, 4, 4)]] void operator()() const {} +}; + +struct Func { + // expected-warning@+2 {{attribute 'intelfpga::max_work_group_size' is deprecated}} + // expected-note@+1 {{did you mean to use 'intel::max_work_group_size' instead?}} + [[intelfpga::max_work_group_size(1, 1, 1)]] void operator()() const {} +}; + +#ifdef TRIGGER_ERROR +struct DAFuncObj { + [[intel::max_work_group_size(4, 4, 4)]] + [[cl::reqd_work_group_size(8, 8, 4)]] // expected-error{{'reqd_work_group_size' attribute conflicts with 'max_work_group_size' attribute}} + void + operator()() const {} +}; +#endif // TRIGGER_ERROR + +int main() { + q.submit([&](handler &h) { + // CHECK-LABEL: FunctionDecl {{.*}}test_kernel1 + // CHECK: SYCLIntelMaxWorkGroupSizeAttr {{.*}} + // CHECK-NEXT: IntegerLiteral{{.*}}4{{$}} + // CHECK-NEXT: IntegerLiteral{{.*}}4{{$}} + // CHECK-NEXT: IntegerLiteral{{.*}}4{{$}} + h.single_task(FuncObj()); + + // CHECK-LABEL: FunctionDecl {{.*}}test_kernel2 + // CHECK: SYCLIntelMaxWorkGroupSizeAttr {{.*}} {{.*}} + // CHECK-NEXT: IntegerLiteral{{.*}}8{{$}} + // CHECK-NEXT: IntegerLiteral{{.*}}8{{$}} + // CHECK-NEXT: IntegerLiteral{{.*}}8{{$}} + // expected-warning@+3 {{attribute 'intelfpga::max_work_group_size' is deprecated}} + // expected-note@+2 {{did you mean to use 'intel::max_work_group_size' instead?}} + h.single_task( + []() [[intelfpga::max_work_group_size(8, 8, 8)]]{}); + + // CHECK-LABEL: FunctionDecl {{.*}}test_kernel3 + // CHECK: SYCLIntelMaxWorkGroupSizeAttr {{.*}} + // CHECK-NEXT: IntegerLiteral{{.*}}2{{$}} + // CHECK-NEXT: IntegerLiteral{{.*}}2{{$}} + // CHECK-NEXT: IntegerLiteral{{.*}}2{{$}} + h.single_task( + []() { func_do_not_ignore(); }); + +#ifdef TRIGGER_ERROR + [[intel::max_work_group_size(1, 1, 1)]] int Var = 0; // expected-error{{'max_work_group_size' attribute only applies to functions}} + + h.single_task( + []() [[intel::max_work_group_size(0, 1, 3)]]{}); // expected-error{{'max_work_group_size' attribute requires a positive integral compile time constant expression}} + + h.single_task( + []() [[intel::max_work_group_size(-8, 8, 1)]]{}); // expected-error{{'max_work_group_size' attribute requires a positive integral compile time constant expression}} + + h.single_task( + []() [[intel::max_work_group_size(16, 16, 16), + intel::max_work_group_size(2, 2, 2)]]{}); // expected-warning{{attribute 'max_work_group_size' is already applied with different parameters}} + + h.single_task( + DAFuncObj()); + +#endif // TRIGGER_ERROR + }); + return 0; +} +#endif // __SYCL_DEVICE_ONLY__ diff --git a/clang/test/SemaSYCL/intel-max-work-group-size-host.cpp b/clang/test/SemaSYCL/intel-max-work-group-size-host.cpp new file mode 100644 index 0000000000000..7dc35f8c2ccbb --- /dev/null +++ b/clang/test/SemaSYCL/intel-max-work-group-size-host.cpp @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -fsycl -fsycl-is-host -fsyntax-only -Wno-sycl-2017-compat -verify %s +// expected-no-diagnostics + +[[intel::max_work_group_size(2, 2, 2)]] void func_do_not_ignore() {} + +struct FuncObj { + [[intel::max_work_group_size(4, 4, 4)]] void operator()() const {} +}; + diff --git a/clang/test/SemaSYCL/intel-max-work-group-size.cpp b/clang/test/SemaSYCL/intel-max-work-group-size.cpp deleted file mode 100644 index 6a05833815835..0000000000000 --- a/clang/test/SemaSYCL/intel-max-work-group-size.cpp +++ /dev/null @@ -1,86 +0,0 @@ -// RUN: %clang_cc1 %s -fsyntax-only -fsycl -fsycl-is-device -Wno-sycl-2017-compat -triple spir64 -DTRIGGER_ERROR -verify -// RUN: %clang_cc1 %s -fsyntax-only -ast-dump -fsycl -fsycl-is-device -Wno-sycl-2017-compat -triple spir64 | FileCheck %s -// RUN: %clang_cc1 -fsycl -fsycl-is-host -fsyntax-only -Wno-sycl-2017-compat -verify %s - -#ifndef __SYCL_DEVICE_ONLY__ -struct FuncObj { - [[intel::max_work_group_size(1, 1, 1)]] // expected-no-diagnostics - void - operator()() const {} -}; - -template -void kernel(const Func &kernelFunc) { - kernelFunc(); -} - -void foo() { - kernel( - FuncObj()); -} - -#else // __SYCL_DEVICE_ONLY__ - -[[intel::max_work_group_size(2, 2, 2)]] void func_do_not_ignore() {} - -struct FuncObj { - [[intel::max_work_group_size(4, 4, 4)]] void operator()() const {} -}; - -struct Func { - // expected-warning@+2 {{attribute 'intelfpga::max_work_group_size' is deprecated}} - // expected-note@+1 {{did you mean to use 'intel::max_work_group_size' instead?}} - [[intelfpga::max_work_group_size(1, 1, 1)]] void operator()() const {} -}; - -#ifdef TRIGGER_ERROR -struct DAFuncObj { - [[intel::max_work_group_size(4, 4, 4)]] - [[cl::reqd_work_group_size(8, 8, 4)]] // expected-error{{'reqd_work_group_size' attribute conflicts with 'max_work_group_size' attribute}} - void - operator()() const {} -}; -#endif // TRIGGER_ERROR - -template -__attribute__((sycl_kernel)) void kernel(const Func &kernelFunc) { - kernelFunc(); -} - -int main() { - // CHECK-LABEL: FunctionDecl {{.*}}test_kernel1 - // CHECK: SYCLIntelMaxWorkGroupSizeAttr {{.*}} 4 4 4 - kernel( - FuncObj()); - - // CHECK-LABEL: FunctionDecl {{.*}}test_kernel2 - // CHECK: SYCLIntelMaxWorkGroupSizeAttr {{.*}} 8 8 8 - // expected-warning@+3 {{attribute 'intelfpga::max_work_group_size' is deprecated}} - // expected-note@+2 {{did you mean to use 'intel::max_work_group_size' instead?}} - kernel( - []() [[intelfpga::max_work_group_size(8, 8, 8)]]{}); - - // CHECK-LABEL: FunctionDecl {{.*}}test_kernel3 - // CHECK: SYCLIntelMaxWorkGroupSizeAttr {{.*}} - kernel( - []() { func_do_not_ignore(); }); - -#ifdef TRIGGER_ERROR - [[intel::max_work_group_size(1, 1, 1)]] int Var = 0; // expected-error{{'max_work_group_size' attribute only applies to functions}} - - kernel( - []() [[intel::max_work_group_size(0, 1, 3)]]{}); // expected-error{{'max_work_group_size' attribute must be greater than 0}} - - kernel( - []() [[intel::max_work_group_size(-8, 8, 1)]]{}); // expected-error{{'max_work_group_size' attribute requires a non-negative integral compile time constant expression}} - - kernel( - []() [[intel::max_work_group_size(16, 16, 16), - intel::max_work_group_size(2, 2, 2)]]{}); // expected-warning{{attribute 'max_work_group_size' is already applied with different parameters}} - - kernel( - DAFuncObj()); - -#endif // TRIGGER_ERROR -} -#endif // __SYCL_DEVICE_ONLY__ diff --git a/clang/test/SemaSYCL/intel-reqd-work-group-size-device.cpp b/clang/test/SemaSYCL/intel-reqd-work-group-size-device.cpp new file mode 100644 index 0000000000000..6c0bb29a2fe5f --- /dev/null +++ b/clang/test/SemaSYCL/intel-reqd-work-group-size-device.cpp @@ -0,0 +1,151 @@ +// RUN: %clang_cc1 -fsycl -fsycl-is-device -internal-isystem %S/Inputs -Wno-sycl-2017-compat -fsyntax-only -verify -DTRIGGER_ERROR %s +// RUN: %clang_cc1 -fsycl -fsycl-is-device -internal-isystem %S/Inputs -Wno-sycl-2017-compat -ast-dump %s | FileCheck %s + +#include "sycl.hpp" + +using namespace cl::sycl; +queue q; + +#ifndef __SYCL_DEVICE_ONLY__ +// expected-no-diagnostics +class Functor { +public: + [[intel::reqd_work_group_size(4)]] void operator()() const {} +}; + +void bar() { + q.submit([&](handler &h) { + Functor f; + h.single_task(f); + }); +} + +#else +[[intel::reqd_work_group_size(4)]] void f4x1x1() {} // expected-note {{conflicting attribute is here}} +// expected-note@-1 {{conflicting attribute is here}} +[[intel::reqd_work_group_size(32)]] void f32x1x1() {} // expected-note {{conflicting attribute is here}} + +[[intel::reqd_work_group_size(16)]] void f16x1x1() {} // expected-note {{conflicting attribute is here}} +[[intel::reqd_work_group_size(16, 16)]] void f16x16x1() {} // expected-note {{conflicting attribute is here}} + +[[intel::reqd_work_group_size(32, 32)]] void f32x32x1() {} // expected-note {{conflicting attribute is here}} +[[intel::reqd_work_group_size(32, 32, 32)]] void f32x32x32() {} // expected-note {{conflicting attribute is here}} + +#ifdef TRIGGER_ERROR +class Functor32 { +public: + [[cl::reqd_work_group_size(32)]] void operator()() const {} // expected-error {{'reqd_work_group_size' attribute requires exactly 3 arguments}} +}; +class Functor33 { +public: + [[intel::reqd_work_group_size(32, -4)]] void operator()() const {} // expected-error {{'reqd_work_group_size' attribute requires a positive integral compile time constant expression}} +}; +#endif // TRIGGER_ERROR + +class Functor16 { +public: + [[intel::reqd_work_group_size(16)]] void operator()() const {} +}; + +class Functor64 { +public: + [[intel::reqd_work_group_size(64, 64)]] void operator()() const {} +}; + +class Functor16x16x16 { +public: + [[intel::reqd_work_group_size(16, 16, 16)]] void operator()() const {} +}; + +class Functor8 { // expected-error {{conflicting attributes applied to a SYCL kernel}} +public: + [[intel::reqd_work_group_size(8)]] void operator()() const { // expected-note {{conflicting attribute is here}} + f4x1x1(); + } +}; + +class Functor { +public: + void operator()() const { + f4x1x1(); + } +}; + +class FunctorAttr { +public: + __attribute__((reqd_work_group_size(128, 128, 128))) void operator()() const {} +}; + +int main() { + q.submit([&](handler &h) { + Functor16 f16; + h.single_task(f16); + + Functor f; + h.single_task(f); + + Functor16x16x16 f16x16x16; + h.single_task(f16x16x16); + + FunctorAttr fattr; + h.single_task(fattr); + + h.single_task([]() [[intel::reqd_work_group_size(32, 32, 32)]] { + f32x32x32(); + }); + +#ifdef TRIGGER_ERROR + Functor8 f8; + h.single_task(f8); + + h.single_task([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}} + f4x1x1(); + f32x1x1(); + }); + + h.single_task([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}} + f16x1x1(); + f16x16x1(); + }); + + h.single_task([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}} + f32x32x32(); + f32x32x1(); + }); + + // expected-error@+1 {{expected variable name or 'this' in lambda capture list}} + h.single_task([[intel::reqd_work_group_size(32, 32, 32)]][]() { + f32x32x32(); + }); + +#endif // TRIGGER_ERROR + }); + return 0; +} + +// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name1 +// CHECK: ReqdWorkGroupSizeAttr {{.*}} +// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}} +// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}} +// CHECK-NEXT: IntegerLiteral{{.*}}16{{$}} +// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name2 +// CHECK: ReqdWorkGroupSizeAttr {{.*}} +// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}} +// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}} +// CHECK-NEXT: IntegerLiteral{{.*}}4{{$}} +// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name3 +// CHECK: ReqdWorkGroupSizeAttr {{.*}} +// CHECK-NEXT: IntegerLiteral{{.*}}16{{$}} +// CHECK-NEXT: IntegerLiteral{{.*}}16{{$}} +// CHECK-NEXT: IntegerLiteral{{.*}}16{{$}} +// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name4 +// CHECK: ReqdWorkGroupSizeAttr {{.*}} +// CHECK-NEXT: IntegerLiteral{{.*}}128{{$}} +// CHECK-NEXT: IntegerLiteral{{.*}}128{{$}} +// CHECK-NEXT: IntegerLiteral{{.*}}128{{$}} +// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name5 +// CHECK: ReqdWorkGroupSizeAttr {{.*}} +// CHECK-NEXT: IntegerLiteral{{.*}}32{{$}} +// CHECK-NEXT: IntegerLiteral{{.*}}32{{$}} +// CHECK-NEXT: IntegerLiteral{{.*}}32{{$}} +#endif // __SYCL_DEVICE_ONLY__ diff --git a/clang/test/SemaSYCL/intel-reqd-work-group-size-host.cpp b/clang/test/SemaSYCL/intel-reqd-work-group-size-host.cpp new file mode 100644 index 0000000000000..cf52fe1f89a31 --- /dev/null +++ b/clang/test/SemaSYCL/intel-reqd-work-group-size-host.cpp @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -fsycl -fsycl-is-host -Wno-sycl-2017-compat -fsyntax-only -verify %s +// expected-no-diagnostics + +[[intel::reqd_work_group_size(4)]] void f4x1x1() {} + +[[intel::reqd_work_group_size(16)]] void f16x1x1() {} + +[[intel::reqd_work_group_size(32, 32, 32)]] void f32x32x32() {} + +class Functor64 { +public: + [[intel::reqd_work_group_size(64, 64, 64)]] void operator()() const {} +}; diff --git a/clang/test/SemaSYCL/intel-reqd-work-group-size.cpp b/clang/test/SemaSYCL/intel-reqd-work-group-size.cpp deleted file mode 100644 index 09fe0934029b2..0000000000000 --- a/clang/test/SemaSYCL/intel-reqd-work-group-size.cpp +++ /dev/null @@ -1,136 +0,0 @@ -// RUN: %clang_cc1 -fsycl -fsycl-is-device -Wno-sycl-2017-compat -fsyntax-only -verify -DTRIGGER_ERROR %s -// RUN: %clang_cc1 -fsycl -fsycl-is-device -Wno-sycl-2017-compat -ast-dump %s | FileCheck %s -// RUN: %clang_cc1 -fsycl -fsycl-is-host -Wno-sycl-2017-compat -fsyntax-only -verify %s - -#ifndef __SYCL_DEVICE_ONLY__ -// expected-no-diagnostics -class Functor { -public: - [[intel::reqd_work_group_size(4)]] void operator()() const {} -}; - -template -void kernel(const Func &kernelFunc) { - kernelFunc(); -} - -void bar() { - Functor f; - kernel(f); -} -#else -[[intel::reqd_work_group_size(4)]] void f4x1x1() {} // expected-note {{conflicting attribute is here}} -// expected-note@-1 {{conflicting attribute is here}} -[[intel::reqd_work_group_size(32)]] void f32x1x1() {} // expected-note {{conflicting attribute is here}} - -[[intel::reqd_work_group_size(16)]] void f16x1x1() {} // expected-note {{conflicting attribute is here}} -[[intel::reqd_work_group_size(16, 16)]] void f16x16x1() {} // expected-note {{conflicting attribute is here}} - -[[intel::reqd_work_group_size(32, 32)]] void f32x32x1() {} // expected-note {{conflicting attribute is here}} -[[intel::reqd_work_group_size(32, 32, 32)]] void f32x32x32() {} // expected-note {{conflicting attribute is here}} - -#ifdef TRIGGER_ERROR -class Functor32 { -public: - [[cl::reqd_work_group_size(32)]] void operator()() const {} // expected-error {{'reqd_work_group_size' attribute requires exactly 3 arguments}} -}; -class Functor33 { -public: - [[intel::reqd_work_group_size(32, -4)]] void operator()() const {} // expected-error {{'reqd_work_group_size' attribute requires a non-negative integral compile time constant expression}} -}; -#endif // TRIGGER_ERROR - -class Functor16 { -public: - [[intel::reqd_work_group_size(16)]] void operator()() const {} -}; - -class Functor64 { -public: - [[intel::reqd_work_group_size(64, 64)]] void operator()() const {} -}; - -class Functor16x16x16 { -public: - [[intel::reqd_work_group_size(16, 16, 16)]] void operator()() const {} -}; - -class Functor8 { // expected-error {{conflicting attributes applied to a SYCL kernel}} -public: - [[intel::reqd_work_group_size(8)]] void operator()() const { // expected-note {{conflicting attribute is here}} - f4x1x1(); - } -}; - -class Functor { -public: - void operator()() const { - f4x1x1(); - } -}; - -class FunctorAttr { -public: - __attribute__((reqd_work_group_size(128, 128, 128))) void operator()() const {} -}; - -template -__attribute__((sycl_kernel)) void kernel(const Func &kernelFunc) { - kernelFunc(); -} - -void bar() { - Functor16 f16; - kernel(f16); - - Functor f; - kernel(f); - - Functor16x16x16 f16x16x16; - kernel(f16x16x16); - - FunctorAttr fattr; - kernel(fattr); - - kernel([]() [[intel::reqd_work_group_size(32, 32, 32)]] { - f32x32x32(); - }); - -#ifdef TRIGGER_ERROR - Functor8 f8; - kernel(f8); - - kernel([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}} - f4x1x1(); - f32x1x1(); - }); - - kernel([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}} - f16x1x1(); - f16x16x1(); - }); - - kernel([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}} - f32x32x32(); - f32x32x1(); - }); - - // expected-error@+1 {{expected variable name or 'this' in lambda capture list}} - kernel([[intel::reqd_work_group_size(32, 32, 32)]][]() { - f32x32x32(); - }); - -#endif // TRIGGER_ERROR -} - -// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name1 -// CHECK: ReqdWorkGroupSizeAttr {{.*}} 1 1 16 -// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name2 -// CHECK: ReqdWorkGroupSizeAttr {{.*}} 1 1 4 -// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name3 -// CHECK: ReqdWorkGroupSizeAttr {{.*}} 16 16 16 -// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name4 -// CHECK: ReqdWorkGroupSizeAttr {{.*}} 128 128 128 -// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name5 -// CHECK: ReqdWorkGroupSizeAttr {{.*}} 32 32 32 -#endif // __SYCL_DEVICE_ONLY__ diff --git a/clang/test/SemaSYCL/redeclaration-attribute-propagation.cpp b/clang/test/SemaSYCL/redeclaration-attribute-propagation.cpp index 436f9b3186de2..325ed8ad261b0 100644 --- a/clang/test/SemaSYCL/redeclaration-attribute-propagation.cpp +++ b/clang/test/SemaSYCL/redeclaration-attribute-propagation.cpp @@ -53,9 +53,16 @@ int main() { #ifndef TRIGGER_ERROR // CHECK-LABEL: FunctionDecl {{.*}} main 'int ()' // CHECK: `-FunctionDecl {{.*}}test_kernel1 'void ()' - // CHECK: -SYCLIntelMaxWorkGroupSizeAttr {{.*}} Inherited 4 4 4 + // CHECK: -SYCLIntelMaxWorkGroupSizeAttr {{.*}} Inherited + // CHECK-NEXT: IntegerLiteral{{.*}}4{{$}} + // CHECK-NEXT: IntegerLiteral{{.*}}4{{$}} + // CHECK-NEXT: IntegerLiteral{{.*}}4{{$}} // CHECK: -SYCLIntelNoGlobalWorkOffsetAttr {{.*}} - // CHECK: `-ReqdWorkGroupSizeAttr {{.*}} 2 2 2 + // CHECK-NEXT: IntegerLiteral{{.*}}1{{$}} + // CHECK: `-ReqdWorkGroupSizeAttr {{.*}} + // CHECK-NEXT: IntegerLiteral{{.*}}2{{$}} + // CHECK-NEXT: IntegerLiteral{{.*}}2{{$}} + // CHECK-NEXT: IntegerLiteral{{.*}}2{{$}} h.single_task( []() { func1(); }); diff --git a/clang/test/SemaSYCL/reqd-work-group-size-device.cpp b/clang/test/SemaSYCL/reqd-work-group-size-device.cpp index 65bb0b13474d7..67cc66c186031 100644 --- a/clang/test/SemaSYCL/reqd-work-group-size-device.cpp +++ b/clang/test/SemaSYCL/reqd-work-group-size-device.cpp @@ -1,5 +1,10 @@ -// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsyntax-only -Wno-sycl-2017-compat -verify -DTRIGGER_ERROR %s -// RUN: %clang_cc1 -fsycl -fsycl-is-device -Wno-sycl-2017-compat -ast-dump %s | FileCheck %s +// RUN: %clang_cc1 -fsycl -fsycl-is-device -internal-isystem %S/Inputs -fsyntax-only -Wno-sycl-2017-compat -verify -DTRIGGER_ERROR %s +// RUN: %clang_cc1 -fsycl -fsycl-is-device -internal-isystem %S/Inputs -Wno-sycl-2017-compat -ast-dump %s | FileCheck %s + +#include "sycl.hpp" + +using namespace cl::sycl; +queue q; [[cl::reqd_work_group_size(4, 1, 1)]] void f4x1x1() {} // expected-note {{conflicting attribute is here}} // expected-note@-1 {{conflicting attribute is here}} @@ -48,65 +53,79 @@ class FunctorAttr { __attribute__((reqd_work_group_size(128, 128, 128))) void operator()() const {} }; -template -__attribute__((sycl_kernel)) void kernel(const Func &kernelFunc) { - kernelFunc(); -} - -void bar() { - Functor16 f16; - kernel(f16); +int main() { + q.submit([&](handler &h) { + Functor16 f16; + h.single_task(f16); - Functor f; - kernel(f); + Functor f; + h.single_task(f); - Functor16x16x16 f16x16x16; - kernel(f16x16x16); + Functor16x16x16 f16x16x16; + h.single_task(f16x16x16); - FunctorAttr fattr; - kernel(fattr); + FunctorAttr fattr; + h.single_task(fattr); - kernel([]() [[cl::reqd_work_group_size(32, 32, 32), cl::reqd_work_group_size(32, 32, 32)]] { - f32x32x32(); - }); + h.single_task([]() [[cl::reqd_work_group_size(32, 32, 32), cl::reqd_work_group_size(32, 32, 32)]] { + f32x32x32(); + }); #ifdef TRIGGER_ERROR - Functor8 f8; - kernel(f8); + Functor8 f8; + h.single_task(f8); - Functor32 f32; - kernel(f32); + Functor32 f32; + h.single_task(f32); - kernel([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}} - f4x1x1(); - f32x1x1(); - }); + h.single_task([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}} + f4x1x1(); + f32x1x1(); + }); - kernel([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}} - f16x1x1(); - f16x16x1(); - }); + h.single_task([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}} + f16x1x1(); + f16x16x1(); + }); - kernel([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}} - f32x32x32(); - f32x32x1(); - }); + h.single_task([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}} + f32x32x32(); + f32x32x1(); + }); - // expected-error@+1 {{expected variable name or 'this' in lambda capture list}} - kernel([[cl::reqd_work_group_size(32, 32, 32)]][]() { - f32x32x32(); - }); + // expected-error@+1 {{expected variable name or 'this' in lambda capture list}} + h.single_task([[cl::reqd_work_group_size(32, 32, 32)]][]() { + f32x32x32(); + }); #endif + }); + return 0; } // CHECK: FunctionDecl {{.*}} {{.*}}kernel_name1 -// CHECK: ReqdWorkGroupSizeAttr {{.*}} 1 1 16 +// CHECK: ReqdWorkGroupSizeAttr {{.*}} +// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}} +// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}} +// CHECK-NEXT: IntegerLiteral{{.*}}16{{$}} // CHECK: FunctionDecl {{.*}} {{.*}}kernel_name2 -// CHECK: ReqdWorkGroupSizeAttr {{.*}} 1 1 4 +// CHECK: ReqdWorkGroupSizeAttr {{.*}} +// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}} +// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}} +// CHECK-NEXT: IntegerLiteral{{.*}}4{{$}} // CHECK: FunctionDecl {{.*}} {{.*}}kernel_name3 -// CHECK: ReqdWorkGroupSizeAttr {{.*}} 16 16 16 +// CHECK: ReqdWorkGroupSizeAttr {{.*}} +// CHECK-NEXT: IntegerLiteral{{.*}}16{{$}} +// CHECK-NEXT: IntegerLiteral{{.*}}16{{$}} +// CHECK-NEXT: IntegerLiteral{{.*}}16{{$}} // CHECK: FunctionDecl {{.*}} {{.*}}kernel_name4 -// CHECK: ReqdWorkGroupSizeAttr {{.*}} 128 128 128 +// CHECK: ReqdWorkGroupSizeAttr {{.*}} +// CHECK-NEXT: IntegerLiteral{{.*}}128{{$}} +// CHECK-NEXT: IntegerLiteral{{.*}}128{{$}} +// CHECK-NEXT: IntegerLiteral{{.*}}128{{$}} // CHECK: FunctionDecl {{.*}} {{.*}}kernel_name5 -// CHECK: ReqdWorkGroupSizeAttr {{.*}} 32 32 32 +// CHECK: ReqdWorkGroupSizeAttr {{.*}} +// CHECK-NEXT: IntegerLiteral{{.*}}32{{$}} +// CHECK-NEXT: IntegerLiteral{{.*}}32{{$}} +// CHECK-NEXT: IntegerLiteral{{.*}}32{{$}} + diff --git a/clang/test/SemaSYCL/sycl-device-intel-max-work-group-size-template.cpp b/clang/test/SemaSYCL/sycl-device-intel-max-work-group-size-template.cpp new file mode 100644 index 0000000000000..1d781f35f5457 --- /dev/null +++ b/clang/test/SemaSYCL/sycl-device-intel-max-work-group-size-template.cpp @@ -0,0 +1,77 @@ +// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsyntax-only -ast-dump -verify -pedantic %s | FileCheck %s + +// Test that checks template parameter support for 'max_work_group_size' attribute on sycl device. + +// Test that checks wrong function template instantiation and ensures that the type +// is checked properly when instantiating from the template definition. + +template +// expected-error@+1{{'max_work_group_size' attribute requires an integer constant}} +[[intel::max_work_group_size(Ty{}, Ty1{}, Ty2{})]] void func() {} + +struct S {}; +void var() { + //expected-note@+1{{in instantiation of function template specialization 'func' requested here}} + func(); +} + +// Test that checks expression is not a constant expression. +int foo(); +// expected-error@+1{{'max_work_group_size' attribute requires an integer constant}} +[[intel::max_work_group_size(foo() + 12, foo() + 12, foo() + 12)]] void func1(); + +// Test that checks expression is a constant expression. +constexpr int bar() { return 0; } +[[intel::max_work_group_size(bar() + 12, bar() + 12, bar() + 12)]] void func2(); // OK + +// Test that checks template parameter suppport on member function of class template. +template +class KernelFunctor { +public: + // expected-error@+1{{'max_work_group_size' attribute requires a positive integral compile time constant expression}} + [[intel::max_work_group_size(SIZE, SIZE1, SIZE2)]] void operator()() {} +}; + +int main() { + //expected-note@+1{{in instantiation of template class 'KernelFunctor<-1, -1, -1>' requested here}} + KernelFunctor<-1, -1, -1>(); + // no error expected + KernelFunctor<4, 4, 4>(); +} + +// CHECK: ClassTemplateDecl {{.*}} {{.*}} KernelFunctor +// CHECK: ClassTemplateSpecializationDecl {{.*}} {{.*}} class KernelFunctor definition +// CHECK: CXXRecordDecl {{.*}} {{.*}} implicit class KernelFunctor +// SYCLIntelMaxWorkGroupSizeAttr {{.*}} +// CHECK: SubstNonTypeTemplateParmExpr {{.*}} +// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} +// CHECK-NEXT: IntegerLiteral{{.*}}4{{$}} +// CHECK: SubstNonTypeTemplateParmExpr {{.*}} +// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} +// CHECK-NEXT: IntegerLiteral{{.*}}4{{$}} +// CHECK: SubstNonTypeTemplateParmExpr {{.*}} +// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} +// CHECK-NEXT: IntegerLiteral{{.*}}4{{$}} + +// Test that checks template parameter suppport on function. +template +[[intel::max_work_group_size(N, N1, N2)]] void func3() {} + +int check() { + func3<8, 8, 8>(); + return 0; +} + +// CHECK: FunctionTemplateDecl {{.*}} {{.*}} func3 +// CHECK: NonTypeTemplateParmDecl {{.*}} {{.*}} referenced 'int' depth 0 index 0 N +// CHECK: FunctionDecl {{.*}} {{.*}} func3 'void ()' +// SYCLIntelMaxWorkGroupSizeAttr {{.*}} +// CHECK: SubstNonTypeTemplateParmExpr {{.*}} +// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} +// CHECK-NEXT: IntegerLiteral{{.*}}8{{$}} +// CHECK: SubstNonTypeTemplateParmExpr {{.*}} +// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} +// CHECK-NEXT: IntegerLiteral{{.*}}8{{$}} +// CHECK: SubstNonTypeTemplateParmExpr {{.*}} +// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} +// CHECK-NEXT: IntegerLiteral{{.*}}8{{$}} diff --git a/clang/test/SemaSYCL/sycl-device-intel-reqd-work-group-size-template.cpp b/clang/test/SemaSYCL/sycl-device-intel-reqd-work-group-size-template.cpp new file mode 100644 index 0000000000000..fa96e16097735 --- /dev/null +++ b/clang/test/SemaSYCL/sycl-device-intel-reqd-work-group-size-template.cpp @@ -0,0 +1,77 @@ +// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsyntax-only -ast-dump -verify -pedantic %s | FileCheck %s + +// Test that checks template parameter support for 'intel::reqd_work_group_size' attribute on sycl device. + +// Test that checks wrong function template instantiation and ensures that the type +// is checked properly when instantiating from the template definition. + +template +// expected-error@+1{{'reqd_work_group_size' attribute requires an integer constant}} +[[intel::reqd_work_group_size(Ty{}, Ty1{}, Ty2{})]] void func() {} + +struct S {}; +void var() { + //expected-note@+1{{in instantiation of function template specialization 'func' requested here}} + func(); +} + +// Test that checks expression is not a constant expression. +int foo(); +// expected-error@+1{{'reqd_work_group_size' attribute requires an integer constant}} +[[intel::reqd_work_group_size(foo() + 12, foo() + 12, foo() + 12)]] void func1(); + +// Test that checks expression is a constant expression. +constexpr int bar() { return 0; } +[[intel::reqd_work_group_size(bar() + 12, bar() + 12, bar() + 12)]] void func2(); // OK + +// Test that checks template parameter suppport on member function of class template. +template +class KernelFunctor { +public: + // expected-error@+1{{'reqd_work_group_size' attribute requires a positive integral compile time constant expression}} + [[intel::reqd_work_group_size(SIZE, SIZE1, SIZE2)]] void operator()() {} +}; + +int main() { + //expected-note@+1{{in instantiation of template class 'KernelFunctor<-1, -1, -1>' requested here}} + KernelFunctor<-1, -1, -1>(); + // no error expected + KernelFunctor<16, 1, 1>(); +} + +// CHECK: ClassTemplateDecl {{.*}} {{.*}} KernelFunctor +// CHECK: ClassTemplateSpecializationDecl {{.*}} {{.*}} class KernelFunctor definition +// CHECK: CXXRecordDecl {{.*}} {{.*}} implicit class KernelFunctor +// CHECK: ReqdWorkGroupSizeAttr {{.*}} +// CHECK: SubstNonTypeTemplateParmExpr {{.*}} +// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} +// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}} +// CHECK: SubstNonTypeTemplateParmExpr {{.*}} +// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} +// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}} +// CHECK: SubstNonTypeTemplateParmExpr {{.*}} +// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} +// CHECK-NEXT: IntegerLiteral{{.*}}16{{$}} + +// Test that checks template parameter suppport on function. +template +[[intel::reqd_work_group_size(N, N1, N2)]] void func3() {} + +int check() { + func3<8, 8, 8>(); + return 0; +} + +// CHECK: FunctionTemplateDecl {{.*}} {{.*}} func3 +// CHECK: NonTypeTemplateParmDecl {{.*}} {{.*}} referenced 'int' depth 0 index 0 N +// CHECK: FunctionDecl {{.*}} {{.*}} func3 'void ()' +// CHECK: ReqdWorkGroupSizeAttr {{.*}} +// CHECK: SubstNonTypeTemplateParmExpr {{.*}} +// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} +// CHECK-NEXT: IntegerLiteral{{.*}}8{{$}} +// CHECK: SubstNonTypeTemplateParmExpr {{.*}} +// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} +// CHECK-NEXT: IntegerLiteral{{.*}}8{{$}} +// CHECK: SubstNonTypeTemplateParmExpr {{.*}} +// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} +// CHECK-NEXT: IntegerLiteral{{.*}}8{{$}} diff --git a/clang/test/SemaSYCL/sycl-device-reqd-work-group-size-template.cpp b/clang/test/SemaSYCL/sycl-device-reqd-work-group-size-template.cpp new file mode 100644 index 0000000000000..372ac69b84462 --- /dev/null +++ b/clang/test/SemaSYCL/sycl-device-reqd-work-group-size-template.cpp @@ -0,0 +1,77 @@ +// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsyntax-only -ast-dump -verify -pedantic %s | FileCheck %s + +// Test that checks template parameter support for 'cl::reqd_work_group_size' attribute on sycl device. + +// Test that checks wrong function template instantiation and ensures that the type +// is checked properly when instantiating from the template definition. + +template +// expected-error@+1{{'reqd_work_group_size' attribute requires an integer constant}} +[[cl::reqd_work_group_size(Ty{}, Ty1{}, Ty2{})]] void func() {} + +struct S {}; +void var() { + //expected-note@+1{{in instantiation of function template specialization 'func' requested here}} + func(); +} + +// Test that checks expression is not a constant expression. +int foo(); +// expected-error@+1{{'reqd_work_group_size' attribute requires an integer constant}} +[[cl::reqd_work_group_size(foo() + 12, foo() + 12, foo() + 12)]] void func1(); + +// Test that checks expression is a constant expression. +constexpr int bar() { return 0; } +[[cl::reqd_work_group_size(bar() + 12, bar() + 12, bar() + 12)]] void func2(); // OK + +// Test that checks template parameter suppport on member function of class template. +template +class KernelFunctor { +public: + // expected-error@+1{{'reqd_work_group_size' attribute requires a positive integral compile time constant expression}} + [[cl::reqd_work_group_size(SIZE, SIZE1, SIZE2)]] void operator()() {} +}; + +int main() { + //expected-note@+1{{in instantiation of template class 'KernelFunctor<-1, -1, -1>' requested here}} + KernelFunctor<-1, -1, -1>(); + // no error expected + KernelFunctor<16, 1, 1>(); +} + +// CHECK: ClassTemplateDecl {{.*}} {{.*}} KernelFunctor +// CHECK: ClassTemplateSpecializationDecl {{.*}} {{.*}} class KernelFunctor definition +// CHECK: CXXRecordDecl {{.*}} {{.*}} implicit class KernelFunctor +// CHECK: ReqdWorkGroupSizeAttr {{.*}} +// CHECK: SubstNonTypeTemplateParmExpr {{.*}} +// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} +// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}} +// CHECK: SubstNonTypeTemplateParmExpr {{.*}} +// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} +// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}} +// CHECK: SubstNonTypeTemplateParmExpr {{.*}} +// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} +// CHECK-NEXT: IntegerLiteral{{.*}}16{{$}} + +// Test that checks template parameter suppport on function. +template +[[cl::reqd_work_group_size(N, N1, N2)]] void func3() {} + +int check() { + func3<8, 8, 8>(); + return 0; +} + +// CHECK: FunctionTemplateDecl {{.*}} {{.*}} func3 +// CHECK: NonTypeTemplateParmDecl {{.*}} {{.*}} referenced 'int' depth 0 index 0 N +// CHECK: FunctionDecl {{.*}} {{.*}} func3 'void ()' +// CHECK: ReqdWorkGroupSizeAttr {{.*}} +// CHECK: SubstNonTypeTemplateParmExpr {{.*}} +// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} +// CHECK-NEXT: IntegerLiteral{{.*}}8{{$}} +// CHECK: SubstNonTypeTemplateParmExpr {{.*}} +// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} +// CHECK-NEXT: IntegerLiteral{{.*}}8{{$}} +// CHECK: SubstNonTypeTemplateParmExpr {{.*}} +// CHECK-NEXT: NonTypeTemplateParmDecl {{.*}} +// CHECK-NEXT: IntegerLiteral{{.*}}8{{$}} From 7f09ae55a887db5aa579c52d2237659528c4fe3a Mon Sep 17 00:00:00 2001 From: Soumi Manna Date: Fri, 18 Dec 2020 08:06:42 -0800 Subject: [PATCH 02/21] Fix Clang format errors Signed-off-by: Soumi Manna --- clang/include/clang/Sema/Sema.h | 2 +- clang/lib/CodeGen/CodeGenFunction.cpp | 21 +- clang/lib/CodeGen/TargetInfo.cpp | 39 ++-- clang/lib/Sema/SemaDecl.cpp | 8 +- clang/lib/Sema/SemaDeclAttr.cpp | 218 +++++++++--------- clang/lib/Sema/SemaSYCL.cpp | 6 +- .../lib/Sema/SemaTemplateInstantiateDecl.cpp | 4 +- clang/test/SemaOpenCL/invalid-kernel-attrs.cl | 10 +- .../intel-max-work-group-size-device.cpp | 2 +- .../intel-max-work-group-size-host.cpp | 1 - .../intel-reqd-work-group-size-host.cpp | 2 +- .../SemaSYCL/reqd-work-group-size-device.cpp | 1 - 12 files changed, 162 insertions(+), 152 deletions(-) diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index af97d4e43f1b7..e78edc77e6c9e 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -10154,7 +10154,7 @@ class Sema final { template void addIntelSYCLTripleArgFunctionAttr(Decl *D, const AttributeCommonInfo &CI, Expr *XDimExpr, Expr *YDimExpr, - Expr *ZDimExpr); + Expr *ZDimExpr); /// AddAlignedAttr - Adds an aligned attribute to a particular declaration. void AddAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E, bool IsPackExpansion); diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index a559b175df854..6724057a4447c 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -619,8 +619,7 @@ void CodeGenFunction::EmitOpenCLKernelMetadata(const FunctionDecl *FD, Fn->setMetadata("work_group_size_hint", llvm::MDNode::get(Context, AttrMDArgs)); } - if (const ReqdWorkGroupSizeAttr *A = - FD->getAttr()) { + if (const ReqdWorkGroupSizeAttr *A = FD->getAttr()) { llvm::LLVMContext &Context = getLLVMContext(); Optional XDimVal = A->getXDim()->getIntegerConstantExpr(FD->getASTContext()); @@ -632,9 +631,12 @@ void CodeGenFunction::EmitOpenCLKernelMetadata(const FunctionDecl *FD, A->getZDim()->getIntegerConstantExpr(FD->getASTContext()); assert(ZDimVal.hasValue() && "Not an integer constant expression"); llvm::Metadata *AttrMDArgs[] = { - llvm::ConstantAsMetadata::get(Builder.getInt32(XDimVal->getSExtValue())), - llvm::ConstantAsMetadata::get(Builder.getInt32(YDimVal->getSExtValue())), - llvm::ConstantAsMetadata::get(Builder.getInt32(ZDimVal->getSExtValue()))}; + llvm::ConstantAsMetadata::get( + Builder.getInt32(XDimVal->getSExtValue())), + llvm::ConstantAsMetadata::get( + Builder.getInt32(YDimVal->getSExtValue())), + llvm::ConstantAsMetadata::get( + Builder.getInt32(ZDimVal->getSExtValue()))}; Fn->setMetadata("reqd_work_group_size", llvm::MDNode::get(Context, AttrMDArgs)); } @@ -707,9 +709,12 @@ void CodeGenFunction::EmitOpenCLKernelMetadata(const FunctionDecl *FD, A->getZDim()->getIntegerConstantExpr(FD->getASTContext()); assert(ZDimVal.hasValue() && "Not an integer constant expression"); llvm::Metadata *AttrMDArgs[] = { - llvm::ConstantAsMetadata::get(Builder.getInt32(XDimVal->getSExtValue())), - llvm::ConstantAsMetadata::get(Builder.getInt32(YDimVal->getSExtValue())), - llvm::ConstantAsMetadata::get(Builder.getInt32(ZDimVal->getSExtValue()))}; + llvm::ConstantAsMetadata::get( + Builder.getInt32(XDimVal->getSExtValue())), + llvm::ConstantAsMetadata::get( + Builder.getInt32(YDimVal->getSExtValue())), + llvm::ConstantAsMetadata::get( + Builder.getInt32(ZDimVal->getSExtValue()))}; Fn->setMetadata("max_work_group_size", llvm::MDNode::get(Context, AttrMDArgs)); } diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp index 3a3c21f1003a7..62fa915f3b218 100644 --- a/clang/lib/CodeGen/TargetInfo.cpp +++ b/clang/lib/CodeGen/TargetInfo.cpp @@ -8142,24 +8142,21 @@ void TCETargetCodeGenInfo::setTargetAttributes( SmallVector Operands; Operands.push_back(llvm::ConstantAsMetadata::get(F)); unsigned XDim = Attr->getXDim() - ->EvaluateKnownConstInt(M.getContext()) - .getExtValue(); + ->EvaluateKnownConstInt(M.getContext()) + .getExtValue(); unsigned YDim = Attr->getYDim() - ->EvaluateKnownConstInt(M.getContext()) - .getExtValue(); + ->EvaluateKnownConstInt(M.getContext()) + .getExtValue(); unsigned ZDim = Attr->getZDim() - ->EvaluateKnownConstInt(M.getContext()) - .getExtValue(); + ->EvaluateKnownConstInt(M.getContext()) + .getExtValue(); - Operands.push_back( - llvm::ConstantAsMetadata::get(llvm::Constant::getIntegerValue( - M.Int32Ty, llvm::APInt(32, XDim)))); - Operands.push_back( - llvm::ConstantAsMetadata::get(llvm::Constant::getIntegerValue( - M.Int32Ty, llvm::APInt(32, YDim)))); - Operands.push_back( - llvm::ConstantAsMetadata::get(llvm::Constant::getIntegerValue( - M.Int32Ty, llvm::APInt(32, ZDim)))); + Operands.push_back(llvm::ConstantAsMetadata::get( + llvm::Constant::getIntegerValue(M.Int32Ty, llvm::APInt(32, XDim)))); + Operands.push_back(llvm::ConstantAsMetadata::get( + llvm::Constant::getIntegerValue(M.Int32Ty, llvm::APInt(32, YDim)))); + Operands.push_back(llvm::ConstantAsMetadata::get( + llvm::Constant::getIntegerValue(M.Int32Ty, llvm::APInt(32, ZDim)))); // Add a boolean constant operand for "required" (true) or "hint" // (false) for implementing the work_group_size_hint attr later. @@ -9052,14 +9049,14 @@ void AMDGPUTargetCodeGenInfo::setTargetAttributes( } if (ReqdWGS) { XDim = ReqdWGS->getXDim() - ->EvaluateKnownConstInt(M.getContext()) - .getExtValue(); + ->EvaluateKnownConstInt(M.getContext()) + .getExtValue(); YDim = ReqdWGS->getYDim() - ->EvaluateKnownConstInt(M.getContext()) - .getExtValue(); + ->EvaluateKnownConstInt(M.getContext()) + .getExtValue(); ZDim = ReqdWGS->getZDim() - ->EvaluateKnownConstInt(M.getContext()) - .getExtValue(); + ->EvaluateKnownConstInt(M.getContext()) + .getExtValue(); } if (ReqdWGS && Min == 0 && Max == 0) Min = Max = XDim * YDim * ZDim; diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index a0ef7b39a743b..8367e077c3ff7 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -3213,10 +3213,10 @@ static void checkDimensionsAndSetDiagnostics(Sema &S, FunctionDecl *New, if ((getIntExprValue(NewDeclAttr->getXDim(), S.getASTContext()) != getIntExprValue(OldDeclAttr->getXDim(), S.getASTContext())) || - (getIntExprValue(NewDeclAttr->getYDim(), S.getASTContext()) != - getIntExprValue(OldDeclAttr->getYDim(), S.getASTContext())) || - (getIntExprValue(NewDeclAttr->getZDim(), S.getASTContext()) != - getIntExprValue(OldDeclAttr->getZDim(), S.getASTContext()))) { + (getIntExprValue(NewDeclAttr->getYDim(), S.getASTContext()) != + getIntExprValue(OldDeclAttr->getYDim(), S.getASTContext())) || + (getIntExprValue(NewDeclAttr->getZDim(), S.getASTContext()) != + getIntExprValue(OldDeclAttr->getZDim(), S.getASTContext()))) { S.Diag(New->getLocation(), diag::err_conflicting_sycl_function_attributes) << OldDeclAttr << NewDeclAttr; S.Diag(New->getLocation(), diag::warn_duplicate_attribute) << OldDeclAttr; diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 571d2dc9b1fe7..a6ed4eb7aa279 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -2925,15 +2925,16 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr, if (Attr.getKind() == ParsedAttr::AT_SYCLIntelMaxGlobalWorkDim) { if (const auto *A = D->getAttr()) { - Result &= checkZeroDim(A, - getIntExprValue(A->getXDim(), S.getASTContext()), - getIntExprValue(A->getYDim(), S.getASTContext()), - getIntExprValue(A->getZDim(), S.getASTContext())); + Result &= + checkZeroDim(A, getIntExprValue(A->getXDim(), S.getASTContext()), + getIntExprValue(A->getYDim(), S.getASTContext()), + getIntExprValue(A->getZDim(), S.getASTContext())); } if (const auto *A = D->getAttr()) { - Result &= checkZeroDim(A, getIntExprValue(A->getXDim(), S.getASTContext()), - getIntExprValue(A->getYDim(), S.getASTContext()), - getIntExprValue(A->getZDim(), S.getASTContext())); + Result &= + checkZeroDim(A, getIntExprValue(A->getXDim(), S.getASTContext()), + getIntExprValue(A->getYDim(), S.getASTContext()), + getIntExprValue(A->getZDim(), S.getASTContext())); } return Result; } @@ -2942,20 +2943,20 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr, int64_t AttrValue = A->getValue()->getIntegerConstantExpr(S.Context)->getSExtValue(); if (AttrValue == 0) - Result &= checkZeroDim(A, - getIntExprValue(Attr.getArgAsExpr(0), S.getASTContext()), - getIntExprValue(Attr.getArgAsExpr(0), S.getASTContext()), - getIntExprValue(Attr.getArgAsExpr(0), S.getASTContext()), - /*ReverseAttrs=*/true); + Result &= checkZeroDim( + A, getIntExprValue(Attr.getArgAsExpr(0), S.getASTContext()), + getIntExprValue(Attr.getArgAsExpr(0), S.getASTContext()), + getIntExprValue(Attr.getArgAsExpr(0), S.getASTContext()), + /*ReverseAttrs=*/true); } if (const auto *A = D->getAttr()) { - if (!(getIntExprValue(Attr.getArgAsExpr(0), S.getASTContext()) - <= getIntExprValue(A->getXDim(), S.getASTContext()) && - getIntExprValue(Attr.getArgAsExpr(1), S.getASTContext()) - <= getIntExprValue(A->getYDim(), S.getASTContext()) && - getIntExprValue(Attr.getArgAsExpr(2), S.getASTContext()) - <= getIntExprValue(A->getZDim(), S.getASTContext()))) { + if (!(getIntExprValue(Attr.getArgAsExpr(0), S.getASTContext()) <= + getIntExprValue(A->getXDim(), S.getASTContext()) && + getIntExprValue(Attr.getArgAsExpr(1), S.getASTContext()) <= + getIntExprValue(A->getYDim(), S.getASTContext()) && + getIntExprValue(Attr.getArgAsExpr(2), S.getASTContext()) <= + getIntExprValue(A->getZDim(), S.getASTContext()))) { S.Diag(Attr.getLoc(), diag::err_conflicting_sycl_function_attributes) << Attr << A->getSpelling(); Result &= false; @@ -2968,12 +2969,12 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr, << "'intel::max_work_group_size'"; if (const auto *A = D->getAttr()) { - if (!(getIntExprValue(Attr.getArgAsExpr(0), S.getASTContext()) - >= getIntExprValue(A->getXDim(), S.getASTContext()) && - getIntExprValue(Attr.getArgAsExpr(1), S.getASTContext()) - >= getIntExprValue(A->getYDim(), S.getASTContext()) && - getIntExprValue(Attr.getArgAsExpr(2), S.getASTContext()) - >= getIntExprValue(A->getZDim(), S.getASTContext()))) { + if (!(getIntExprValue(Attr.getArgAsExpr(0), S.getASTContext()) >= + getIntExprValue(A->getXDim(), S.getASTContext()) && + getIntExprValue(Attr.getArgAsExpr(1), S.getASTContext()) >= + getIntExprValue(A->getYDim(), S.getASTContext()) && + getIntExprValue(Attr.getArgAsExpr(2), S.getASTContext()) >= + getIntExprValue(A->getZDim(), S.getASTContext()))) { S.Diag(Attr.getLoc(), diag::err_conflicting_sycl_function_attributes) << Attr << A->getSpelling(); Result &= false; @@ -2985,59 +2986,62 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr, template void Sema::addIntelSYCLTripleArgFunctionAttr(Decl *D, const AttributeCommonInfo &CI, - Expr *XDim, Expr *YDim, Expr *ZDim) { - assert(XDim && "Attribute must have an argument."); - assert(YDim && "Attribute must have an argument."); - assert(ZDim && "Attribute must have an argument."); - - if (!XDim->isInstantiationDependent() || - !YDim->isInstantiationDependent() || - !ZDim->isInstantiationDependent()) { - Optional XDimVal= XDim->getIntegerConstantExpr(getASTContext()); - Optional YDimVal= YDim->getIntegerConstantExpr(getASTContext()); - Optional ZDimVal= ZDim->getIntegerConstantExpr(getASTContext()); - - if (!XDimVal) { - Diag(XDim->getExprLoc(), diag::err_attribute_argument_type) + Expr *XDim, Expr *YDim, + Expr *ZDim) { + assert(XDim && "Attribute must have an argument."); + assert(YDim && "Attribute must have an argument."); + assert(ZDim && "Attribute must have an argument."); + + if (!XDim->isInstantiationDependent() || !YDim->isInstantiationDependent() || + !ZDim->isInstantiationDependent()) { + Optional XDimVal = + XDim->getIntegerConstantExpr(getASTContext()); + Optional YDimVal = + YDim->getIntegerConstantExpr(getASTContext()); + Optional ZDimVal = + ZDim->getIntegerConstantExpr(getASTContext()); + + if (!XDimVal) { + Diag(XDim->getExprLoc(), diag::err_attribute_argument_type) << CI << AANT_ArgumentIntegerConstant << XDim->getSourceRange(); - return; - } + return; + } - if (!YDimVal) { - Diag(YDim->getExprLoc(), diag::err_attribute_argument_type) + if (!YDimVal) { + Diag(YDim->getExprLoc(), diag::err_attribute_argument_type) << CI << AANT_ArgumentIntegerConstant << YDim->getSourceRange(); - return; - } + return; + } - if (!ZDimVal) { - Diag(ZDim->getExprLoc(), diag::err_attribute_argument_type) + if (!ZDimVal) { + Diag(ZDim->getExprLoc(), diag::err_attribute_argument_type) << CI << AANT_ArgumentIntegerConstant << ZDim->getSourceRange(); - return; - } + return; + } - int32_t XDimInt = XDimVal->getSExtValue(); - if (XDimInt <= 0) { - Diag(XDim->getExprLoc(), diag::err_attribute_requires_positive_integer) + int32_t XDimInt = XDimVal->getSExtValue(); + if (XDimInt <= 0) { + Diag(XDim->getExprLoc(), diag::err_attribute_requires_positive_integer) << CI << /*positive*/ 0; - return; - } + return; + } - int32_t YDimInt = YDimVal->getSExtValue(); - if (YDimInt <= 0) { - Diag(YDim->getExprLoc(), diag::err_attribute_requires_positive_integer) + int32_t YDimInt = YDimVal->getSExtValue(); + if (YDimInt <= 0) { + Diag(YDim->getExprLoc(), diag::err_attribute_requires_positive_integer) << CI << /*positive*/ 0; - return; - } + return; + } - int32_t ZDimInt = ZDimVal->getSExtValue(); - if (ZDimInt <= 0) { - Diag(ZDim->getExprLoc(), diag::err_attribute_requires_positive_integer) + int32_t ZDimInt = ZDimVal->getSExtValue(); + if (ZDimInt <= 0) { + Diag(ZDim->getExprLoc(), diag::err_attribute_requires_positive_integer) << CI << /*positive*/ 0; - return; - } + return; + } } - D->addAttr(::new (Context) WorkGroupAttrType (Context, CI, XDim, YDim, ZDim)); + D->addAttr(::new (Context) WorkGroupAttrType(Context, CI, XDim, YDim, ZDim)); } template @@ -3050,57 +3054,63 @@ static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) { Expr *XDimExpr = AL.getArgAsExpr(0); // If no attribute argument is specified, set to default value '1' - // in ReqdWorkGroupSizeAttr for only with intel::reqd_work_group_size spelling. - Expr *YDimExpr = AL.isArgExpr(1) - ? AL.getArgAsExpr(1) - : ((AL.getKind() == ParsedAttr::AT_ReqdWorkGroupSize && - AL.getAttributeSpellingListIndex() == - ReqdWorkGroupSizeAttr::CXX11_intel_reqd_work_group_size) - ? (IntegerLiteral::Create(S.Context, llvm::APInt(32, 1), - S.Context.IntTy, AL.getLoc())) - : nullptr); + // in ReqdWorkGroupSizeAttr for only with intel::reqd_work_group_size + // spelling. + Expr *YDimExpr = + AL.isArgExpr(1) + ? AL.getArgAsExpr(1) + : ((AL.getKind() == ParsedAttr::AT_ReqdWorkGroupSize && + AL.getAttributeSpellingListIndex() == + ReqdWorkGroupSizeAttr::CXX11_intel_reqd_work_group_size) + ? (IntegerLiteral::Create(S.Context, llvm::APInt(32, 1), + S.Context.IntTy, AL.getLoc())) + : nullptr); // If no attribute argument is specified, set to default value '1' - // in ReqdWorkGroupSizeAttr for only with intel::reqd_work_group_size spelling. - Expr *ZDimExpr = AL.isArgExpr(2) - ? AL.getArgAsExpr(2) - : ((AL.getKind() == ParsedAttr::AT_ReqdWorkGroupSize && - AL.getAttributeSpellingListIndex() == - ReqdWorkGroupSizeAttr::CXX11_intel_reqd_work_group_size) - ? (IntegerLiteral::Create(S.Context, llvm::APInt(32, 1), - S.Context.IntTy, AL.getLoc())) - : nullptr); + // in ReqdWorkGroupSizeAttr for only with intel::reqd_work_group_size + // spelling. + Expr *ZDimExpr = + AL.isArgExpr(2) + ? AL.getArgAsExpr(2) + : ((AL.getKind() == ParsedAttr::AT_ReqdWorkGroupSize && + AL.getAttributeSpellingListIndex() == + ReqdWorkGroupSizeAttr::CXX11_intel_reqd_work_group_size) + ? (IntegerLiteral::Create(S.Context, llvm::APInt(32, 1), + S.Context.IntTy, AL.getLoc())) + : nullptr); if ((AL.getKind() == ParsedAttr::AT_ReqdWorkGroupSize && AL.getAttributeSpellingListIndex() == - ReqdWorkGroupSizeAttr::CXX11_cl_reqd_work_group_size) || - (AL.getKind() == ParsedAttr::AT_SYCLIntelMaxWorkGroupSize)) { + ReqdWorkGroupSizeAttr::CXX11_cl_reqd_work_group_size) || + (AL.getKind() == ParsedAttr::AT_SYCLIntelMaxWorkGroupSize)) { if (!checkAttributeNumArgs(S, AL, 3)) return; } if (S.getLangOpts().SYCLIsDevice) { - std::swap(XDimExpr, ZDimExpr); + std::swap(XDimExpr, ZDimExpr); } if (WorkGroupAttr *ExistingAttr = D->getAttr()) { - Optional XDimVal= XDimExpr->getIntegerConstantExpr(S.getASTContext()); - Optional YDimVal = YDimExpr->getIntegerConstantExpr(S.getASTContext()); - Optional ZDimVal = ZDimExpr->getIntegerConstantExpr(S.getASTContext()); - Optional ExistingXDimVal = - ExistingAttr->getXDim()->getIntegerConstantExpr(S.getASTContext()); - Optional ExistingYDimVal = - ExistingAttr->getYDim()->getIntegerConstantExpr(S.getASTContext()); - Optional ExistingZDimVal = - ExistingAttr->getZDim()->getIntegerConstantExpr(S.getASTContext()); + Optional XDimVal = + XDimExpr->getIntegerConstantExpr(S.getASTContext()); + Optional YDimVal = + YDimExpr->getIntegerConstantExpr(S.getASTContext()); + Optional ZDimVal = + ZDimExpr->getIntegerConstantExpr(S.getASTContext()); + Optional ExistingXDimVal = + ExistingAttr->getXDim()->getIntegerConstantExpr(S.getASTContext()); + Optional ExistingYDimVal = + ExistingAttr->getYDim()->getIntegerConstantExpr(S.getASTContext()); + Optional ExistingZDimVal = + ExistingAttr->getZDim()->getIntegerConstantExpr(S.getASTContext()); // Compare attribute arguments value and warn for a mismatch. if (ExistingAttr && - !((ExistingXDimVal->getExtValue() == XDimVal->getExtValue()) && - (ExistingYDimVal->getExtValue() == YDimVal->getExtValue()) && - (ExistingZDimVal->getExtValue() == ZDimVal->getExtValue()))) { - S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) - << AL; + !((ExistingXDimVal->getExtValue() == XDimVal->getExtValue()) && + (ExistingYDimVal->getExtValue() == YDimVal->getExtValue()) && + (ExistingZDimVal->getExtValue() == ZDimVal->getExtValue()))) { + S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL; } } @@ -3108,7 +3118,7 @@ static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) { return; S.addIntelSYCLTripleArgFunctionAttr(D, AL, XDimExpr, YDimExpr, - ZDimExpr); + ZDimExpr); } // Handles work_group_size_hint. @@ -3121,11 +3131,11 @@ static void handleWorkGroupSizeHint(Sema &S, Decl *D, const ParsedAttr &AL) { for (unsigned i = 0; i < 3; ++i) { if (!checkUInt32Argument(S, AL, AL.getArgAsExpr(i), WGSize[i], i, /*StrictlyUnsigned=*/true)) - return; + return; if (WGSize[i] == 0) { S.Diag(AL.getLoc(), diag::err_attribute_argument_is_zero) - << AL << AL.getArgAsExpr(i)->getSourceRange(); + << AL << AL.getArgAsExpr(i)->getSourceRange(); return; } } @@ -3136,8 +3146,8 @@ static void handleWorkGroupSizeHint(Sema &S, Decl *D, const ParsedAttr &AL) { Existing->getZDim() == WGSize[2])) S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL; - D->addAttr(::new (S.Context) - WorkGroupSizeHintAttr(S.Context, AL, WGSize[0], WGSize[1], WGSize[2])); + D->addAttr(::new (S.Context) WorkGroupSizeHintAttr(S.Context, AL, WGSize[0], + WGSize[1], WGSize[2])); } // Handles intel_reqd_sub_group_size. diff --git a/clang/lib/Sema/SemaSYCL.cpp b/clang/lib/Sema/SemaSYCL.cpp index 3d174e7342943..6db89e0e950a0 100644 --- a/clang/lib/Sema/SemaSYCL.cpp +++ b/clang/lib/Sema/SemaSYCL.cpp @@ -3283,7 +3283,7 @@ void Sema::MarkDevice(void) { case attr::Kind::ReqdWorkGroupSize: { auto *Attr = cast(A); if (auto *Existing = SYCLKernel->getAttr()) { - if ((getIntExprValue(Existing->getXDim(), getASTContext()) != + if ((getIntExprValue(Existing->getXDim(), getASTContext()) != getIntExprValue(Attr->getXDim(), getASTContext())) || (getIntExprValue(Existing->getYDim(), getASTContext()) != getIntExprValue(Attr->getYDim(), getASTContext())) || @@ -3297,7 +3297,7 @@ void Sema::MarkDevice(void) { } } else if (auto *Existing = SYCLKernel->getAttr()) { - if ((getIntExprValue(Existing->getXDim(), getASTContext()) < + if ((getIntExprValue(Existing->getXDim(), getASTContext()) < getIntExprValue(Attr->getXDim(), getASTContext())) || (getIntExprValue(Existing->getYDim(), getASTContext()) < getIntExprValue(Attr->getYDim(), getASTContext())) || @@ -3319,7 +3319,7 @@ void Sema::MarkDevice(void) { case attr::Kind::SYCLIntelMaxWorkGroupSize: { auto *Attr = cast(A); if (auto *Existing = SYCLKernel->getAttr()) { - if ((getIntExprValue(Existing->getXDim(), getASTContext()) > + if ((getIntExprValue(Existing->getXDim(), getASTContext()) > getIntExprValue(Attr->getXDim(), getASTContext())) || (getIntExprValue(Existing->getYDim(), getASTContext()) > getIntExprValue(Attr->getYDim(), getASTContext())) || diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index f776bb539ce9f..29feaf2502800 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -626,8 +626,8 @@ static void instantiateIntelSYCTripleLFunctionAttr( return; Expr *ZDimExpr = Result.getAs(); - S.addIntelSYCLTripleArgFunctionAttr(New, *Attr, XDimExpr, - YDimExpr, ZDimExpr); + S.addIntelSYCLTripleArgFunctionAttr(New, *Attr, XDimExpr, YDimExpr, + ZDimExpr); } void Sema::InstantiateAttrsForDecl( diff --git a/clang/test/SemaOpenCL/invalid-kernel-attrs.cl b/clang/test/SemaOpenCL/invalid-kernel-attrs.cl index 44e045296ddb6..d0c1a24a414d2 100644 --- a/clang/test/SemaOpenCL/invalid-kernel-attrs.cl +++ b/clang/test/SemaOpenCL/invalid-kernel-attrs.cl @@ -30,9 +30,9 @@ void f_kernel_image2d_t( kernel image2d_t image ) { // expected-error {{'kernel' int __kernel x; // expected-error {{'__kernel' attribute only applies to functions}} } -kernel __attribute__((reqd_work_group_size(1,2,0))) void kernel11(){} // expected-error {{'reqd_work_group_size' attribute requires a positive integral compile time constant expression}} -kernel __attribute__((reqd_work_group_size(1,0,2))) void kernel12(){} // expected-error {{'reqd_work_group_size' attribute requires a positive integral compile time constant expression}} -kernel __attribute__((reqd_work_group_size(0,1,2))) void kernel13(){} // expected-error {{'reqd_work_group_size' attribute requires a positive integral compile time constant expression}} +kernel __attribute__((reqd_work_group_size(1, 2, 0))) void kernel11() {} // expected-error {{'reqd_work_group_size' attribute requires a positive integral compile time constant expression}} +kernel __attribute__((reqd_work_group_size(1, 0, 2))) void kernel12() {} // expected-error {{'reqd_work_group_size' attribute requires a positive integral compile time constant expression}} +kernel __attribute__((reqd_work_group_size(0, 1, 2))) void kernel13() {} // expected-error {{'reqd_work_group_size' attribute requires a positive integral compile time constant expression}} __attribute__((intel_reqd_sub_group_size(8))) void kernel14(){} // expected-error {{attribute 'intel_reqd_sub_group_size' can only be applied to an OpenCL kernel}} kernel __attribute__((intel_reqd_sub_group_size(0))) void kernel15() {} // expected-error {{'intel_reqd_sub_group_size' attribute requires a positive integral compile time constant expression}} @@ -42,8 +42,8 @@ kernel __attribute__((intel_reqd_sub_group_size(-1))) void kernel16() {} // expe kernel __attribute__((intel_reqd_sub_group_size(8))) __attribute__((intel_reqd_sub_group_size(16))) void kernel17() {} //expected-warning{{attribute 'intel_reqd_sub_group_size' is already applied with different parameters}} __kernel __attribute__((work_group_size_hint(8,-16,32))) void neg1() {} //expected-error{{'work_group_size_hint' attribute requires a non-negative integral compile time constant expression}} -__kernel __attribute__((reqd_work_group_size(8,16,-32))) void neg2(){} // expected-error{{'reqd_work_group_size' attribute requires a positive integral compile time constant expression}} +__kernel __attribute__((reqd_work_group_size(8, 16, -32))) void neg2() {} // expected-error{{'reqd_work_group_size' attribute requires a positive integral compile time constant expression}} // 4294967294 is a negative integer if treated as signed. // Should compile successfully, since we expect an unsigned. -__kernel __attribute__((reqd_work_group_size(8,16,4294967294))) void ok1(){} //expected-error{{'reqd_work_group_size' attribute requires a positive integral compile time constant expression}} +__kernel __attribute__((reqd_work_group_size(8, 16, 4294967294))) void ok1() {} //expected-error{{'reqd_work_group_size' attribute requires a positive integral compile time constant expression}} diff --git a/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp b/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp index e802baf5f7d0d..3379a454ef1f0 100644 --- a/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp +++ b/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp @@ -80,7 +80,7 @@ int main() { h.single_task( []() [[intel::max_work_group_size(16, 16, 16), - intel::max_work_group_size(2, 2, 2)]]{}); // expected-warning{{attribute 'max_work_group_size' is already applied with different parameters}} + intel::max_work_group_size(2, 2, 2)]]{}); // expected-warning{{attribute 'max_work_group_size' is already applied with different parameters}} h.single_task( DAFuncObj()); diff --git a/clang/test/SemaSYCL/intel-max-work-group-size-host.cpp b/clang/test/SemaSYCL/intel-max-work-group-size-host.cpp index 7dc35f8c2ccbb..b8b9ceeafe352 100644 --- a/clang/test/SemaSYCL/intel-max-work-group-size-host.cpp +++ b/clang/test/SemaSYCL/intel-max-work-group-size-host.cpp @@ -6,4 +6,3 @@ struct FuncObj { [[intel::max_work_group_size(4, 4, 4)]] void operator()() const {} }; - diff --git a/clang/test/SemaSYCL/intel-reqd-work-group-size-host.cpp b/clang/test/SemaSYCL/intel-reqd-work-group-size-host.cpp index cf52fe1f89a31..d7518762102d4 100644 --- a/clang/test/SemaSYCL/intel-reqd-work-group-size-host.cpp +++ b/clang/test/SemaSYCL/intel-reqd-work-group-size-host.cpp @@ -5,7 +5,7 @@ [[intel::reqd_work_group_size(16)]] void f16x1x1() {} -[[intel::reqd_work_group_size(32, 32, 32)]] void f32x32x32() {} +[[intel::reqd_work_group_size(32, 32, 32)]] void f32x32x32() {} class Functor64 { public: diff --git a/clang/test/SemaSYCL/reqd-work-group-size-device.cpp b/clang/test/SemaSYCL/reqd-work-group-size-device.cpp index 67cc66c186031..f7dfd5eb7cb51 100644 --- a/clang/test/SemaSYCL/reqd-work-group-size-device.cpp +++ b/clang/test/SemaSYCL/reqd-work-group-size-device.cpp @@ -128,4 +128,3 @@ int main() { // CHECK-NEXT: IntegerLiteral{{.*}}32{{$}} // CHECK-NEXT: IntegerLiteral{{.*}}32{{$}} // CHECK-NEXT: IntegerLiteral{{.*}}32{{$}} - From 8c1e8688f11eb6395c20108ad181dcbadb3ab0a6 Mon Sep 17 00:00:00 2001 From: Soumi Manna Date: Fri, 18 Dec 2020 08:27:51 -0800 Subject: [PATCH 03/21] Fix Clang format errors Signed-off-by: Soumi Manna --- clang/lib/CodeGen/CodeGenFunction.cpp | 4 ++-- clang/lib/CodeGen/TargetInfo.cpp | 4 ++-- clang/lib/Sema/SemaDeclAttr.cpp | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 6724057a4447c..e02ccda96ab0a 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -631,7 +631,7 @@ void CodeGenFunction::EmitOpenCLKernelMetadata(const FunctionDecl *FD, A->getZDim()->getIntegerConstantExpr(FD->getASTContext()); assert(ZDimVal.hasValue() && "Not an integer constant expression"); llvm::Metadata *AttrMDArgs[] = { - llvm::ConstantAsMetadata::get( + llvm::ConstantAsMetadata::get( Builder.getInt32(XDimVal->getSExtValue())), llvm::ConstantAsMetadata::get( Builder.getInt32(YDimVal->getSExtValue())), @@ -709,7 +709,7 @@ void CodeGenFunction::EmitOpenCLKernelMetadata(const FunctionDecl *FD, A->getZDim()->getIntegerConstantExpr(FD->getASTContext()); assert(ZDimVal.hasValue() && "Not an integer constant expression"); llvm::Metadata *AttrMDArgs[] = { - llvm::ConstantAsMetadata::get( + llvm::ConstantAsMetadata::get( Builder.getInt32(XDimVal->getSExtValue())), llvm::ConstantAsMetadata::get( Builder.getInt32(YDimVal->getSExtValue())), diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp index 62fa915f3b218..b6d64b1788729 100644 --- a/clang/lib/CodeGen/TargetInfo.cpp +++ b/clang/lib/CodeGen/TargetInfo.cpp @@ -8149,9 +8149,9 @@ void TCETargetCodeGenInfo::setTargetAttributes( .getExtValue(); unsigned ZDim = Attr->getZDim() ->EvaluateKnownConstInt(M.getContext()) - .getExtValue(); + .getExtValue(); - Operands.push_back(llvm::ConstantAsMetadata::get( + Operands.push_back(llvm::ConstantAsMetadata::get( llvm::Constant::getIntegerValue(M.Int32Ty, llvm::APInt(32, XDim)))); Operands.push_back(llvm::ConstantAsMetadata::get( llvm::Constant::getIntegerValue(M.Int32Ty, llvm::APInt(32, YDim)))); diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index a6ed4eb7aa279..b63142227d8f9 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -3081,7 +3081,7 @@ static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) { if ((AL.getKind() == ParsedAttr::AT_ReqdWorkGroupSize && AL.getAttributeSpellingListIndex() == - ReqdWorkGroupSizeAttr::CXX11_cl_reqd_work_group_size) || + ReqdWorkGroupSizeAttr::CXX11_cl_reqd_work_group_size) || (AL.getKind() == ParsedAttr::AT_SYCLIntelMaxWorkGroupSize)) { if (!checkAttributeNumArgs(S, AL, 3)) return; @@ -3098,11 +3098,11 @@ static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) { YDimExpr->getIntegerConstantExpr(S.getASTContext()); Optional ZDimVal = ZDimExpr->getIntegerConstantExpr(S.getASTContext()); - Optional ExistingXDimVal = + Optional ExistingXDimVal = ExistingAttr->getXDim()->getIntegerConstantExpr(S.getASTContext()); - Optional ExistingYDimVal = + Optional ExistingYDimVal = ExistingAttr->getYDim()->getIntegerConstantExpr(S.getASTContext()); - Optional ExistingZDimVal = + Optional ExistingZDimVal = ExistingAttr->getZDim()->getIntegerConstantExpr(S.getASTContext()); // Compare attribute arguments value and warn for a mismatch. @@ -3135,7 +3135,7 @@ static void handleWorkGroupSizeHint(Sema &S, Decl *D, const ParsedAttr &AL) { if (WGSize[i] == 0) { S.Diag(AL.getLoc(), diag::err_attribute_argument_is_zero) - << AL << AL.getArgAsExpr(i)->getSourceRange(); + << AL << AL.getArgAsExpr(i)->getSourceRange(); return; } } From d8790ff62bbf23e1261b2a32b9a8aa05e5a4954a Mon Sep 17 00:00:00 2001 From: Soumi Manna Date: Sun, 20 Dec 2020 11:38:43 -0800 Subject: [PATCH 04/21] Address review comments Signed-off-by: Soumi Manna --- .../clang/Basic/DiagnosticSemaKinds.td | 1 + clang/lib/CodeGen/CodeGenFunction.cpp | 18 +- clang/lib/Sema/SemaDecl.cpp | 26 +- clang/lib/Sema/SemaDeclAttr.cpp | 250 ++++++++++-------- clang/test/SemaOpenCL/invalid-kernel-attrs.cl | 10 +- .../intel-max-global-work-dim-device.cpp | 20 +- .../intel-max-work-group-size-device.cpp | 21 +- .../intel-reqd-work-group-size-device.cpp | 25 +- .../SemaSYCL/reqd-work-group-size-device.cpp | 3 +- ...ice-intel-max-work-group-size-template.cpp | 4 - ...ce-intel-reqd-work-group-size-template.cpp | 4 - ...l-device-reqd-work-group-size-template.cpp | 4 - 12 files changed, 219 insertions(+), 167 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index b67c28a77c27a..b1fdcedefcf2c 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3866,6 +3866,7 @@ def err_mismatched_visibility: Error<"visibility does not match previous declara def note_previous_attribute : Note<"previous attribute is here">; def note_conflicting_attribute : Note<"conflicting attribute is here">; def note_attribute : Note<"attribute is here">; +def note_duplicating_attribute : Note<"duplicating attribute is here">; def err_mismatched_ms_inheritance : Error< "inheritance model does not match %select{definition|previous declaration}0">; def warn_ignored_ms_inheritance : Warning< diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index e02ccda96ab0a..8c92970bdf22d 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -623,20 +623,17 @@ void CodeGenFunction::EmitOpenCLKernelMetadata(const FunctionDecl *FD, llvm::LLVMContext &Context = getLLVMContext(); Optional XDimVal = A->getXDim()->getIntegerConstantExpr(FD->getASTContext()); - assert(XDimVal.hasValue() && "Not an integer constant expression"); Optional YDimVal = A->getYDim()->getIntegerConstantExpr(FD->getASTContext()); - assert(YDimVal.hasValue() && "Not an integer constant expression"); Optional ZDimVal = A->getZDim()->getIntegerConstantExpr(FD->getASTContext()); - assert(ZDimVal.hasValue() && "Not an integer constant expression"); llvm::Metadata *AttrMDArgs[] = { llvm::ConstantAsMetadata::get( - Builder.getInt32(XDimVal->getSExtValue())), + Builder.getInt32(XDimVal->getZExtValue())), llvm::ConstantAsMetadata::get( - Builder.getInt32(YDimVal->getSExtValue())), + Builder.getInt32(YDimVal->getZExtValue())), llvm::ConstantAsMetadata::get( - Builder.getInt32(ZDimVal->getSExtValue()))}; + Builder.getInt32(ZDimVal->getZExtValue()))}; Fn->setMetadata("reqd_work_group_size", llvm::MDNode::get(Context, AttrMDArgs)); } @@ -701,20 +698,17 @@ void CodeGenFunction::EmitOpenCLKernelMetadata(const FunctionDecl *FD, llvm::LLVMContext &Context = getLLVMContext(); Optional XDimVal = A->getXDim()->getIntegerConstantExpr(FD->getASTContext()); - assert(XDimVal.hasValue() && "Not an integer constant expression"); Optional YDimVal = A->getYDim()->getIntegerConstantExpr(FD->getASTContext()); - assert(YDimVal.hasValue() && "Not an integer constant expression"); Optional ZDimVal = A->getZDim()->getIntegerConstantExpr(FD->getASTContext()); - assert(ZDimVal.hasValue() && "Not an integer constant expression"); llvm::Metadata *AttrMDArgs[] = { llvm::ConstantAsMetadata::get( - Builder.getInt32(XDimVal->getSExtValue())), + Builder.getInt32(XDimVal->getZExtValue())), llvm::ConstantAsMetadata::get( - Builder.getInt32(YDimVal->getSExtValue())), + Builder.getInt32(YDimVal->getZExtValue())), llvm::ConstantAsMetadata::get( - Builder.getInt32(ZDimVal->getSExtValue()))}; + Builder.getInt32(ZDimVal->getZExtValue()))}; Fn->setMetadata("max_work_group_size", llvm::MDNode::get(Context, AttrMDArgs)); } diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 8367e077c3ff7..6dd6f4c744a9a 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -3198,10 +3198,6 @@ static void adjustDeclContextForDeclaratorDecl(DeclaratorDecl *NewD, FixSemaDC(VD->getDescribedVarTemplate()); } -static int64_t getIntExprValue(const Expr *E, ASTContext &Ctx) { - return E->getIntegerConstantExpr(Ctx)->getSExtValue(); -} - template static void checkDimensionsAndSetDiagnostics(Sema &S, FunctionDecl *New, FunctionDecl *Old) { @@ -3211,12 +3207,22 @@ static void checkDimensionsAndSetDiagnostics(Sema &S, FunctionDecl *New, if (!NewDeclAttr || !OldDeclAttr) return; - if ((getIntExprValue(NewDeclAttr->getXDim(), S.getASTContext()) != - getIntExprValue(OldDeclAttr->getXDim(), S.getASTContext())) || - (getIntExprValue(NewDeclAttr->getYDim(), S.getASTContext()) != - getIntExprValue(OldDeclAttr->getYDim(), S.getASTContext())) || - (getIntExprValue(NewDeclAttr->getZDim(), S.getASTContext()) != - getIntExprValue(OldDeclAttr->getZDim(), S.getASTContext()))) { + int64_t NewXDimVal = + NewDeclAttr->getXDim()->getIntegerConstantExpr(S.Context)->getSExtValue(); + int64_t NewYDimVal = + NewDeclAttr->getYDim()->getIntegerConstantExpr(S.Context)->getSExtValue(); + int64_t NewZDimVal = + NewDeclAttr->getZDim()->getIntegerConstantExpr(S.Context)->getSExtValue(); + int64_t OldXDimVal = + OldDeclAttr->getXDim()->getIntegerConstantExpr(S.Context)->getSExtValue(); + int64_t OldYDimVal = + OldDeclAttr->getYDim()->getIntegerConstantExpr(S.Context)->getSExtValue(); + int64_t OldZDimVal = + OldDeclAttr->getZDim()->getIntegerConstantExpr(S.Context)->getSExtValue(); + + if ((NewXDimVal != OldXDimVal) || + (NewYDimVal != OldYDimVal) || + (NewZDimVal != OldZDimVal)) { S.Diag(New->getLocation(), diag::err_conflicting_sycl_function_attributes) << OldDeclAttr << NewDeclAttr; S.Diag(New->getLocation(), diag::warn_duplicate_attribute) << OldDeclAttr; diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index b63142227d8f9..3a68f06b0a7a4 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -2901,11 +2901,6 @@ static void handleWeakImportAttr(Sema &S, Decl *D, const ParsedAttr &AL) { // In case the value of 'max_global_work_dim' attribute equals to 0 we shall // ensure that if max_work_group_size and reqd_work_group_size attributes exist, // they hold equal values (1, 1, 1). - -static int64_t getIntExprValue(const Expr *E, ASTContext &Ctx) { - return E->getIntegerConstantExpr(Ctx)->getSExtValue(); -} - static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr, uint32_t WGSize[3]) { bool Result = true; @@ -2925,16 +2920,25 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr, if (Attr.getKind() == ParsedAttr::AT_SYCLIntelMaxGlobalWorkDim) { if (const auto *A = D->getAttr()) { + Optional XDimVal = + A->getXDim()->getIntegerConstantExpr(S.getASTContext()); + Optional YDimVal = + A->getYDim()->getIntegerConstantExpr(S.getASTContext()); + Optional ZDimVal = + A->getZDim()->getIntegerConstantExpr(S.getASTContext()); Result &= - checkZeroDim(A, getIntExprValue(A->getXDim(), S.getASTContext()), - getIntExprValue(A->getYDim(), S.getASTContext()), - getIntExprValue(A->getZDim(), S.getASTContext())); - } - if (const auto *A = D->getAttr()) { + checkZeroDim(A, XDimVal->getZExtValue(), YDimVal->getZExtValue(), + ZDimVal->getZExtValue()); + } else if (const auto *A = D->getAttr()) { + Optional XDimVal = + A->getXDim()->getIntegerConstantExpr(S.getASTContext()); + Optional YDimVal = + A->getYDim()->getIntegerConstantExpr(S.getASTContext()); + Optional ZDimVal = + A->getZDim()->getIntegerConstantExpr(S.getASTContext()); Result &= - checkZeroDim(A, getIntExprValue(A->getXDim(), S.getASTContext()), - getIntExprValue(A->getYDim(), S.getASTContext()), - getIntExprValue(A->getZDim(), S.getASTContext())); + checkZeroDim(A, XDimVal->getZExtValue(), YDimVal->getZExtValue(), + ZDimVal->getZExtValue()); } return Result; } @@ -2942,21 +2946,35 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr, if (const auto *A = D->getAttr()) { int64_t AttrValue = A->getValue()->getIntegerConstantExpr(S.Context)->getSExtValue(); - if (AttrValue == 0) - Result &= checkZeroDim( - A, getIntExprValue(Attr.getArgAsExpr(0), S.getASTContext()), - getIntExprValue(Attr.getArgAsExpr(0), S.getASTContext()), - getIntExprValue(Attr.getArgAsExpr(0), S.getASTContext()), - /*ReverseAttrs=*/true); + if (AttrValue == 0) { + Optional AttrXDim = + Attr.getArgAsExpr(2)->getIntegerConstantExpr(S.getASTContext()); + Optional AttrYDim = + Attr.getArgAsExpr(1)->getIntegerConstantExpr(S.getASTContext()); + Optional AttrZDim = + Attr.getArgAsExpr(0)->getIntegerConstantExpr(S.getASTContext()); + Result &= checkZeroDim(A, AttrXDim->getZExtValue(), + AttrYDim->getZExtValue(),AttrZDim->getZExtValue(), + /*ReverseAttrs=*/true); + } } if (const auto *A = D->getAttr()) { - if (!(getIntExprValue(Attr.getArgAsExpr(0), S.getASTContext()) <= - getIntExprValue(A->getXDim(), S.getASTContext()) && - getIntExprValue(Attr.getArgAsExpr(1), S.getASTContext()) <= - getIntExprValue(A->getYDim(), S.getASTContext()) && - getIntExprValue(Attr.getArgAsExpr(2), S.getASTContext()) <= - getIntExprValue(A->getZDim(), S.getASTContext()))) { + Optional AttrXDimVal= + Attr.getArgAsExpr(2)->getIntegerConstantExpr(S.getASTContext()); + Optional AttrYDimVal = + Attr.getArgAsExpr(1)->getIntegerConstantExpr(S.getASTContext()); + Optional AttrZDimVal = + Attr.getArgAsExpr(0)->getIntegerConstantExpr(S.getASTContext()); + Optional XDimVal = + A->getXDim()->getIntegerConstantExpr(S.getASTContext()); + Optional YDimVal = + A->getYDim()->getIntegerConstantExpr(S.getASTContext()); + Optional ZDimVal = + A->getZDim()->getIntegerConstantExpr(S.getASTContext()); + if (!(AttrXDimVal->getZExtValue() <= XDimVal->getZExtValue() && + AttrYDimVal->getZExtValue() <= YDimVal->getZExtValue() && + AttrZDimVal->getZExtValue() <= ZDimVal->getZExtValue())) { S.Diag(Attr.getLoc(), diag::err_conflicting_sycl_function_attributes) << Attr << A->getSpelling(); Result &= false; @@ -2969,12 +2987,21 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr, << "'intel::max_work_group_size'"; if (const auto *A = D->getAttr()) { - if (!(getIntExprValue(Attr.getArgAsExpr(0), S.getASTContext()) >= - getIntExprValue(A->getXDim(), S.getASTContext()) && - getIntExprValue(Attr.getArgAsExpr(1), S.getASTContext()) >= - getIntExprValue(A->getYDim(), S.getASTContext()) && - getIntExprValue(Attr.getArgAsExpr(2), S.getASTContext()) >= - getIntExprValue(A->getZDim(), S.getASTContext()))) { + Optional AttrXDimVal= + Attr.getArgAsExpr(2)->getIntegerConstantExpr(S.getASTContext()); + Optional AttrYDimVal = + Attr.getArgAsExpr(1)->getIntegerConstantExpr(S.getASTContext()); + Optional AttrZDimVal = + Attr.getArgAsExpr(0)->getIntegerConstantExpr(S.getASTContext()); + Optional XDimVal = + A->getXDim()->getIntegerConstantExpr(S.getASTContext()); + Optional YDimVal = + A->getYDim()->getIntegerConstantExpr(S.getASTContext()); + Optional ZDimVal = + A->getZDim()->getIntegerConstantExpr(S.getASTContext()); + if (!(AttrXDimVal->getZExtValue() >= XDimVal->getZExtValue() && + AttrYDimVal->getZExtValue() >= YDimVal->getZExtValue() && + AttrZDimVal->getZExtValue() >= ZDimVal->getZExtValue())) { S.Diag(Attr.getLoc(), diag::err_conflicting_sycl_function_attributes) << Attr << A->getSpelling(); Result &= false; @@ -2983,65 +3010,72 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr, return Result; } -template -void Sema::addIntelSYCLTripleArgFunctionAttr(Decl *D, - const AttributeCommonInfo &CI, - Expr *XDim, Expr *YDim, - Expr *ZDim) { - assert(XDim && "Attribute must have an argument."); - assert(YDim && "Attribute must have an argument."); - assert(ZDim && "Attribute must have an argument."); - - if (!XDim->isInstantiationDependent() || !YDim->isInstantiationDependent() || - !ZDim->isInstantiationDependent()) { - Optional XDimVal = - XDim->getIntegerConstantExpr(getASTContext()); - Optional YDimVal = - YDim->getIntegerConstantExpr(getASTContext()); - Optional ZDimVal = - ZDim->getIntegerConstantExpr(getASTContext()); +template +static bool handleMaxWorkSizeAttrExpr(Sema &S, const AttrInfo &AI, + const Expr *Expr, + unsigned &Val, unsigned Idx) { + assert(Expr && "Attribute must have an argument."); - if (!XDimVal) { - Diag(XDim->getExprLoc(), diag::err_attribute_argument_type) - << CI << AANT_ArgumentIntegerConstant << XDim->getSourceRange(); - return; - } + if (!Expr->isInstantiationDependent()) { + Optional ArgVal = + Expr->getIntegerConstantExpr(S.getASTContext()); - if (!YDimVal) { - Diag(YDim->getExprLoc(), diag::err_attribute_argument_type) - << CI << AANT_ArgumentIntegerConstant << YDim->getSourceRange(); - return; + if (!ArgVal) { + S.Diag(getAttrLoc(AI), diag::err_attribute_argument_type) + << &AI << AANT_ArgumentIntegerConstant << Expr->getSourceRange(); + return false; } - if (!ZDimVal) { - Diag(ZDim->getExprLoc(), diag::err_attribute_argument_type) - << CI << AANT_ArgumentIntegerConstant << ZDim->getSourceRange(); - return; + Val = ArgVal->getZExtValue(); + if (Val == 0) { + S.Diag(Expr->getExprLoc(), diag::err_attribute_argument_is_zero) + << &AI << Expr->getSourceRange(); + return false; } + } + return true; +} - int32_t XDimInt = XDimVal->getSExtValue(); - if (XDimInt <= 0) { - Diag(XDim->getExprLoc(), diag::err_attribute_requires_positive_integer) - << CI << /*positive*/ 0; - return; - } +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; - int32_t YDimInt = YDimVal->getSExtValue(); - if (YDimInt <= 0) { - Diag(YDim->getExprLoc(), diag::err_attribute_requires_positive_integer) - << CI << /*positive*/ 0; - return; - } + unsigned XDim = 0; + if (!handleMaxWorkSizeAttrExpr(S, Attr, XDimExpr, XDim, 0)) + return true; - int32_t ZDimInt = ZDimVal->getSExtValue(); - if (ZDimInt <= 0) { - Diag(ZDim->getExprLoc(), diag::err_attribute_requires_positive_integer) - << CI << /*positive*/ 0; - return; - } - } + 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; - D->addAttr(::new (Context) WorkGroupAttrType(Context, CI, XDim, YDim, ZDim)); +} + +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 @@ -3054,30 +3088,29 @@ static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) { Expr *XDimExpr = AL.getArgAsExpr(0); // If no attribute argument is specified, set to default value '1' - // in ReqdWorkGroupSizeAttr for only with intel::reqd_work_group_size - // spelling. - Expr *YDimExpr = - AL.isArgExpr(1) - ? AL.getArgAsExpr(1) - : ((AL.getKind() == ParsedAttr::AT_ReqdWorkGroupSize && + // for second and third attribute argument in ReqdWorkGroupSizeAttr + // for only with intel::reqd_work_group_size spelling. + auto SetDefaultValue = [](Sema &S, const ParsedAttr &AL, SourceLocation loc) { + Expr *E; + if (AL.getKind() == ParsedAttr::AT_ReqdWorkGroupSize && AL.getAttributeSpellingListIndex() == - ReqdWorkGroupSizeAttr::CXX11_intel_reqd_work_group_size) - ? (IntegerLiteral::Create(S.Context, llvm::APInt(32, 1), - S.Context.IntTy, AL.getLoc())) - : nullptr); + ReqdWorkGroupSizeAttr::CXX11_intel_reqd_work_group_size) { + E = IntegerLiteral::Create(S.Context, llvm::APInt(32, 1), + S.Context.IntTy, AL.getLoc()); + return E; + } else { + E = nullptr; + return E; + } + }; - // If no attribute argument is specified, set to default value '1' - // in ReqdWorkGroupSizeAttr for only with intel::reqd_work_group_size - // spelling. - Expr *ZDimExpr = - AL.isArgExpr(2) - ? AL.getArgAsExpr(2) - : ((AL.getKind() == ParsedAttr::AT_ReqdWorkGroupSize && - AL.getAttributeSpellingListIndex() == - ReqdWorkGroupSizeAttr::CXX11_intel_reqd_work_group_size) - ? (IntegerLiteral::Create(S.Context, llvm::APInt(32, 1), - S.Context.IntTy, AL.getLoc())) - : nullptr); + Expr *YDimExpr = AL.isArgExpr(1) + ? AL.getArgAsExpr(1) + : SetDefaultValue(S, AL, AL.getLoc()); + + Expr *ZDimExpr = AL.isArgExpr(2) + ? AL.getArgAsExpr(2) + : SetDefaultValue(S, AL, AL.getLoc()); if ((AL.getKind() == ParsedAttr::AT_ReqdWorkGroupSize && AL.getAttributeSpellingListIndex() == @@ -3087,9 +3120,8 @@ static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) { return; } - if (S.getLangOpts().SYCLIsDevice) { + if (S.getLangOpts().SYCLIsDevice) std::swap(XDimExpr, ZDimExpr); - } if (WorkGroupAttr *ExistingAttr = D->getAttr()) { Optional XDimVal = @@ -3106,11 +3138,11 @@ static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) { ExistingAttr->getZDim()->getIntegerConstantExpr(S.getASTContext()); // Compare attribute arguments value and warn for a mismatch. - if (ExistingAttr && - !((ExistingXDimVal->getExtValue() == XDimVal->getExtValue()) && - (ExistingYDimVal->getExtValue() == YDimVal->getExtValue()) && - (ExistingZDimVal->getExtValue() == ZDimVal->getExtValue()))) { + if (!((ExistingXDimVal->getZExtValue() == XDimVal->getZExtValue()) && + (ExistingYDimVal->getZExtValue() == YDimVal->getZExtValue()) && + (ExistingZDimVal->getZExtValue() == ZDimVal->getZExtValue()))) { S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL; + S.Diag(ExistingAttr->getLocation(), diag::note_duplicating_attribute); } } diff --git a/clang/test/SemaOpenCL/invalid-kernel-attrs.cl b/clang/test/SemaOpenCL/invalid-kernel-attrs.cl index d0c1a24a414d2..c5b42155a5d6b 100644 --- a/clang/test/SemaOpenCL/invalid-kernel-attrs.cl +++ b/clang/test/SemaOpenCL/invalid-kernel-attrs.cl @@ -30,9 +30,9 @@ void f_kernel_image2d_t( kernel image2d_t image ) { // expected-error {{'kernel' int __kernel x; // expected-error {{'__kernel' attribute only applies to functions}} } -kernel __attribute__((reqd_work_group_size(1, 2, 0))) void kernel11() {} // expected-error {{'reqd_work_group_size' attribute requires a positive integral compile time constant expression}} -kernel __attribute__((reqd_work_group_size(1, 0, 2))) void kernel12() {} // expected-error {{'reqd_work_group_size' attribute requires a positive integral compile time constant expression}} -kernel __attribute__((reqd_work_group_size(0, 1, 2))) void kernel13() {} // expected-error {{'reqd_work_group_size' attribute requires a positive integral compile time constant expression}} +kernel __attribute__((reqd_work_group_size(1, 2, 0))) void kernel11() {} // expected-error {{'reqd_work_group_size' attribute must be greater than 0}} +kernel __attribute__((reqd_work_group_size(1, 0, 2))) void kernel12() {} // expected-error {{'reqd_work_group_size' attribute must be greater than 0}} +kernel __attribute__((reqd_work_group_size(0, 1, 2))) void kernel13() {} // expected-error {{'reqd_work_group_size' attribute must be greater than 0}} __attribute__((intel_reqd_sub_group_size(8))) void kernel14(){} // expected-error {{attribute 'intel_reqd_sub_group_size' can only be applied to an OpenCL kernel}} kernel __attribute__((intel_reqd_sub_group_size(0))) void kernel15() {} // expected-error {{'intel_reqd_sub_group_size' attribute requires a positive integral compile time constant expression}} @@ -42,8 +42,8 @@ kernel __attribute__((intel_reqd_sub_group_size(-1))) void kernel16() {} // expe kernel __attribute__((intel_reqd_sub_group_size(8))) __attribute__((intel_reqd_sub_group_size(16))) void kernel17() {} //expected-warning{{attribute 'intel_reqd_sub_group_size' is already applied with different parameters}} __kernel __attribute__((work_group_size_hint(8,-16,32))) void neg1() {} //expected-error{{'work_group_size_hint' attribute requires a non-negative integral compile time constant expression}} -__kernel __attribute__((reqd_work_group_size(8, 16, -32))) void neg2() {} // expected-error{{'reqd_work_group_size' attribute requires a positive integral compile time constant expression}} +__kernel __attribute__((reqd_work_group_size(8, 16, -32))) void neg2() {} // OK // 4294967294 is a negative integer if treated as signed. // Should compile successfully, since we expect an unsigned. -__kernel __attribute__((reqd_work_group_size(8, 16, 4294967294))) void ok1() {} //expected-error{{'reqd_work_group_size' attribute requires a positive integral compile time constant expression}} +__kernel __attribute__((reqd_work_group_size(8, 16, 4294967294))) void ok1() {} diff --git a/clang/test/SemaSYCL/intel-max-global-work-dim-device.cpp b/clang/test/SemaSYCL/intel-max-global-work-dim-device.cpp index 0f28cbd9911e5..cb3e359edd70b 100644 --- a/clang/test/SemaSYCL/intel-max-global-work-dim-device.cpp +++ b/clang/test/SemaSYCL/intel-max-global-work-dim-device.cpp @@ -80,15 +80,27 @@ int main() { h.single_task(TRIFuncObjGood1()); // CHECK-LABEL: FunctionDecl {{.*}}test_kernel4 - // CHECK: ReqdWorkGroupSizeAttr {{.*}} 1 1 1 - // CHECK: SYCLIntelMaxWorkGroupSizeAttr {{.*}} 1 1 1 + // CHECK: ReqdWorkGroupSizeAttr {{.*}} + // CHECK-NEXT: IntegerLiteral{{.*}}1{{$}} + // CHECK-NEXT: IntegerLiteral{{.*}}1{{$}} + // CHECK-NEXT: IntegerLiteral{{.*}}1{{$}} + // CHECK: SYCLIntelMaxWorkGroupSizeAttr {{.*}} + // CHECK-NEXT: IntegerLiteral{{.*}}1{{$}} + // CHECK-NEXT: IntegerLiteral{{.*}}1{{$}} + // CHECK-NEXT: IntegerLiteral{{.*}}1{{$}} // CHECK: SYCLIntelMaxGlobalWorkDimAttr {{.*}} // CHECK-NEXT: IntegerLiteral{{.*}}0{{$}} h.single_task(TRIFuncObjGood2()); // CHECK-LABEL: FunctionDecl {{.*}}test_kernel5 - // CHECK: ReqdWorkGroupSizeAttr {{.*}} 1 1 4 - // CHECK: SYCLIntelMaxWorkGroupSizeAttr {{.*}} 1 1 8 + // CHECK: ReqdWorkGroupSizeAttr {{.*}} + // // CHECK-NEXT: IntegerLiteral{{.*}}1{{$}} + // CHECK-NEXT: IntegerLiteral{{.*}}1{{$}} + // CHECK-NEXT: IntegerLiteral{{.*}}4{{$}} + // CHECK: SYCLIntelMaxWorkGroupSizeAttr {{.*}} + // // CHECK-NEXT: IntegerLiteral{{.*}}1{{$}} + // CHECK-NEXT: IntegerLiteral{{.*}}1{{$}} + // CHECK-NEXT: IntegerLiteral{{.*}}8{{$}} // CHECK: SYCLIntelMaxGlobalWorkDimAttr {{.*}} // CHECK-NEXT: IntegerLiteral{{.*}}3{{$}} #ifdef TRIGGER_ERROR diff --git a/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp b/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp index 3379a454ef1f0..be0770846a6e3 100644 --- a/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp +++ b/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp @@ -69,20 +69,29 @@ int main() { h.single_task( []() { func_do_not_ignore(); }); + // CHECK-LABEL: FunctionDecl {{.*}}test_kernel4 + // CHECK: SYCLIntelMaxWorkGroupSizeAttr {{.*}} + // CHECK-NEXT: IntegerLiteral{{.*}}1{{$}} + // CHECK-NEXT: IntegerLiteral{{.*}}8{{$}} + // CHECK-NEXT: UnaryOperator{{.*}} 'int' prefix '-' + // CHECK-NEXT: IntegerLiteral{{.*}}8{{$}} + h.single_task( + []() [[intel::max_work_group_size(-8, 8, 1)]]{}); + #ifdef TRIGGER_ERROR [[intel::max_work_group_size(1, 1, 1)]] int Var = 0; // expected-error{{'max_work_group_size' attribute only applies to functions}} - h.single_task( - []() [[intel::max_work_group_size(0, 1, 3)]]{}); // expected-error{{'max_work_group_size' attribute requires a positive integral compile time constant expression}} - h.single_task( - []() [[intel::max_work_group_size(-8, 8, 1)]]{}); // expected-error{{'max_work_group_size' attribute requires a positive integral compile time constant expression}} + []() [[intel::max_work_group_size(0, 1, 3)]]{}); // expected-error{{'max_work_group_size' attribute must be greater than 0}} h.single_task( - []() [[intel::max_work_group_size(16, 16, 16), - intel::max_work_group_size(2, 2, 2)]]{}); // expected-warning{{attribute 'max_work_group_size' is already applied with different parameters}} + []() [[intel::max_work_group_size(1.2f, 1, 3)]]{}); // expected-error{{'max_work_group_size' attribute requires an integer constant}} h.single_task( + []() [[intel::max_work_group_size(16, 16, 16), // expected-note{{duplicating attribute is here}} + intel::max_work_group_size(2, 2, 2)]]{}); // expected-warning{{attribute 'max_work_group_size' is already applied with different parameters}} + + h.single_task( DAFuncObj()); #endif // TRIGGER_ERROR diff --git a/clang/test/SemaSYCL/intel-reqd-work-group-size-device.cpp b/clang/test/SemaSYCL/intel-reqd-work-group-size-device.cpp index 6c0bb29a2fe5f..ddb8234981edc 100644 --- a/clang/test/SemaSYCL/intel-reqd-work-group-size-device.cpp +++ b/clang/test/SemaSYCL/intel-reqd-work-group-size-device.cpp @@ -36,11 +36,12 @@ class Functor32 { public: [[cl::reqd_work_group_size(32)]] void operator()() const {} // expected-error {{'reqd_work_group_size' attribute requires exactly 3 arguments}} }; +#endif // TRIGGER_ERROR + class Functor33 { public: - [[intel::reqd_work_group_size(32, -4)]] void operator()() const {} // expected-error {{'reqd_work_group_size' attribute requires a positive integral compile time constant expression}} + [[intel::reqd_work_group_size(32, -4)]] void operator()() const {} }; -#endif // TRIGGER_ERROR class Functor16 { public: @@ -90,25 +91,27 @@ int main() { FunctorAttr fattr; h.single_task(fattr); - h.single_task([]() [[intel::reqd_work_group_size(32, 32, 32)]] { + Functor33 f33; + h.single_task(f33); + + h.single_task([]() [[intel::reqd_work_group_size(32, 32, 32)]] { f32x32x32(); }); - #ifdef TRIGGER_ERROR Functor8 f8; - h.single_task(f8); + h.single_task(f8); - h.single_task([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}} + h.single_task([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}} f4x1x1(); f32x1x1(); }); - h.single_task([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}} + h.single_task([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}} f16x1x1(); f16x16x1(); }); - h.single_task([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}} + h.single_task([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}} f32x32x32(); f32x32x1(); }); @@ -145,6 +148,12 @@ int main() { // CHECK-NEXT: IntegerLiteral{{.*}}128{{$}} // CHECK: FunctionDecl {{.*}} {{.*}}kernel_name5 // CHECK: ReqdWorkGroupSizeAttr {{.*}} +// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}} +// CHECK-NEXT: UnaryOperator{{.*}} 'int' prefix '-' +// CHECK-NEXT: IntegerLiteral{{.*}}4{{$}} +// CHECK-NEXT: IntegerLiteral{{.*}}32{{$}} +// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name6 +// CHECK: ReqdWorkGroupSizeAttr {{.*}} // CHECK-NEXT: IntegerLiteral{{.*}}32{{$}} // CHECK-NEXT: IntegerLiteral{{.*}}32{{$}} // CHECK-NEXT: IntegerLiteral{{.*}}32{{$}} diff --git a/clang/test/SemaSYCL/reqd-work-group-size-device.cpp b/clang/test/SemaSYCL/reqd-work-group-size-device.cpp index f7dfd5eb7cb51..56c905fa481a1 100644 --- a/clang/test/SemaSYCL/reqd-work-group-size-device.cpp +++ b/clang/test/SemaSYCL/reqd-work-group-size-device.cpp @@ -24,7 +24,8 @@ class Functor16 { #ifdef TRIGGER_ERROR class Functor32 { public: - //expected-warning@+2{{attribute 'reqd_work_group_size' is already applied with different parameters}} + // expected-note@+3{{duplicating attribute is here}} + // expected-warning@+2{{attribute 'reqd_work_group_size' is already applied with different parameters}} // expected-error@+1{{'reqd_work_group_size' attribute conflicts with 'reqd_work_group_size' attribute}} [[cl::reqd_work_group_size(32, 1, 1)]] [[cl::reqd_work_group_size(1, 1, 32)]] void operator()() const {} }; diff --git a/clang/test/SemaSYCL/sycl-device-intel-max-work-group-size-template.cpp b/clang/test/SemaSYCL/sycl-device-intel-max-work-group-size-template.cpp index 1d781f35f5457..50cc361c19796 100644 --- a/clang/test/SemaSYCL/sycl-device-intel-max-work-group-size-template.cpp +++ b/clang/test/SemaSYCL/sycl-device-intel-max-work-group-size-template.cpp @@ -28,14 +28,10 @@ constexpr int bar() { return 0; } template class KernelFunctor { public: - // expected-error@+1{{'max_work_group_size' attribute requires a positive integral compile time constant expression}} [[intel::max_work_group_size(SIZE, SIZE1, SIZE2)]] void operator()() {} }; int main() { - //expected-note@+1{{in instantiation of template class 'KernelFunctor<-1, -1, -1>' requested here}} - KernelFunctor<-1, -1, -1>(); - // no error expected KernelFunctor<4, 4, 4>(); } diff --git a/clang/test/SemaSYCL/sycl-device-intel-reqd-work-group-size-template.cpp b/clang/test/SemaSYCL/sycl-device-intel-reqd-work-group-size-template.cpp index fa96e16097735..0e00286f9a287 100644 --- a/clang/test/SemaSYCL/sycl-device-intel-reqd-work-group-size-template.cpp +++ b/clang/test/SemaSYCL/sycl-device-intel-reqd-work-group-size-template.cpp @@ -28,14 +28,10 @@ constexpr int bar() { return 0; } template class KernelFunctor { public: - // expected-error@+1{{'reqd_work_group_size' attribute requires a positive integral compile time constant expression}} [[intel::reqd_work_group_size(SIZE, SIZE1, SIZE2)]] void operator()() {} }; int main() { - //expected-note@+1{{in instantiation of template class 'KernelFunctor<-1, -1, -1>' requested here}} - KernelFunctor<-1, -1, -1>(); - // no error expected KernelFunctor<16, 1, 1>(); } diff --git a/clang/test/SemaSYCL/sycl-device-reqd-work-group-size-template.cpp b/clang/test/SemaSYCL/sycl-device-reqd-work-group-size-template.cpp index 372ac69b84462..605bbce1d09b6 100644 --- a/clang/test/SemaSYCL/sycl-device-reqd-work-group-size-template.cpp +++ b/clang/test/SemaSYCL/sycl-device-reqd-work-group-size-template.cpp @@ -28,14 +28,10 @@ constexpr int bar() { return 0; } template class KernelFunctor { public: - // expected-error@+1{{'reqd_work_group_size' attribute requires a positive integral compile time constant expression}} [[cl::reqd_work_group_size(SIZE, SIZE1, SIZE2)]] void operator()() {} }; int main() { - //expected-note@+1{{in instantiation of template class 'KernelFunctor<-1, -1, -1>' requested here}} - KernelFunctor<-1, -1, -1>(); - // no error expected KernelFunctor<16, 1, 1>(); } From 0a37b9e1bd7fa5a462333635bc081c227c661d71 Mon Sep 17 00:00:00 2001 From: Soumi Manna Date: Sun, 20 Dec 2020 12:08:16 -0800 Subject: [PATCH 05/21] Fix errors Signed-off-by: Soumi Manna --- clang/lib/Sema/SemaDecl.cpp | 3 +- clang/lib/Sema/SemaDeclAttr.cpp | 67 +++++++++---------- .../intel-max-work-group-size-device.cpp | 4 +- 3 files changed, 34 insertions(+), 40 deletions(-) diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 6dd6f4c744a9a..42870814a17be 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -3220,8 +3220,7 @@ static void checkDimensionsAndSetDiagnostics(Sema &S, FunctionDecl *New, int64_t OldZDimVal = OldDeclAttr->getZDim()->getIntegerConstantExpr(S.Context)->getSExtValue(); - if ((NewXDimVal != OldXDimVal) || - (NewYDimVal != OldYDimVal) || + if ((NewXDimVal != OldXDimVal) || (NewYDimVal != OldYDimVal) || (NewZDimVal != OldZDimVal)) { S.Diag(New->getLocation(), diag::err_conflicting_sycl_function_attributes) << OldDeclAttr << NewDeclAttr; diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 3a68f06b0a7a4..128d5e5ba2e8a 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -2926,9 +2926,8 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr, A->getYDim()->getIntegerConstantExpr(S.getASTContext()); Optional ZDimVal = A->getZDim()->getIntegerConstantExpr(S.getASTContext()); - Result &= - checkZeroDim(A, XDimVal->getZExtValue(), YDimVal->getZExtValue(), - ZDimVal->getZExtValue()); + Result &= checkZeroDim(A, XDimVal->getZExtValue(), + YDimVal->getZExtValue(), ZDimVal->getZExtValue()); } else if (const auto *A = D->getAttr()) { Optional XDimVal = A->getXDim()->getIntegerConstantExpr(S.getASTContext()); @@ -2936,9 +2935,8 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr, A->getYDim()->getIntegerConstantExpr(S.getASTContext()); Optional ZDimVal = A->getZDim()->getIntegerConstantExpr(S.getASTContext()); - Result &= - checkZeroDim(A, XDimVal->getZExtValue(), YDimVal->getZExtValue(), - ZDimVal->getZExtValue()); + Result &= checkZeroDim(A, XDimVal->getZExtValue(), + YDimVal->getZExtValue(), ZDimVal->getZExtValue()); } return Result; } @@ -2947,20 +2945,20 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr, int64_t AttrValue = A->getValue()->getIntegerConstantExpr(S.Context)->getSExtValue(); if (AttrValue == 0) { - Optional AttrXDim = - Attr.getArgAsExpr(2)->getIntegerConstantExpr(S.getASTContext()); - Optional AttrYDim = - Attr.getArgAsExpr(1)->getIntegerConstantExpr(S.getASTContext()); - Optional AttrZDim = - Attr.getArgAsExpr(0)->getIntegerConstantExpr(S.getASTContext()); + Optional AttrXDim = + Attr.getArgAsExpr(2)->getIntegerConstantExpr(S.getASTContext()); + Optional AttrYDim = + Attr.getArgAsExpr(1)->getIntegerConstantExpr(S.getASTContext()); + Optional AttrZDim = + Attr.getArgAsExpr(0)->getIntegerConstantExpr(S.getASTContext()); Result &= checkZeroDim(A, AttrXDim->getZExtValue(), - AttrYDim->getZExtValue(),AttrZDim->getZExtValue(), - /*ReverseAttrs=*/true); + AttrYDim->getZExtValue(), AttrZDim->getZExtValue(), + /*ReverseAttrs=*/true); } } if (const auto *A = D->getAttr()) { - Optional AttrXDimVal= + Optional AttrXDimVal = Attr.getArgAsExpr(2)->getIntegerConstantExpr(S.getASTContext()); Optional AttrYDimVal = Attr.getArgAsExpr(1)->getIntegerConstantExpr(S.getASTContext()); @@ -2973,7 +2971,7 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr, Optional ZDimVal = A->getZDim()->getIntegerConstantExpr(S.getASTContext()); if (!(AttrXDimVal->getZExtValue() <= XDimVal->getZExtValue() && - AttrYDimVal->getZExtValue() <= YDimVal->getZExtValue() && + AttrYDimVal->getZExtValue() <= YDimVal->getZExtValue() && AttrZDimVal->getZExtValue() <= ZDimVal->getZExtValue())) { S.Diag(Attr.getLoc(), diag::err_conflicting_sycl_function_attributes) << Attr << A->getSpelling(); @@ -2987,7 +2985,7 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr, << "'intel::max_work_group_size'"; if (const auto *A = D->getAttr()) { - Optional AttrXDimVal= + Optional AttrXDimVal= Attr.getArgAsExpr(2)->getIntegerConstantExpr(S.getASTContext()); Optional AttrYDimVal = Attr.getArgAsExpr(1)->getIntegerConstantExpr(S.getASTContext()); @@ -3012,8 +3010,8 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr, template static bool handleMaxWorkSizeAttrExpr(Sema &S, const AttrInfo &AI, - const Expr *Expr, - unsigned &Val, unsigned Idx) { + const Expr *Expr, unsigned &Val, + unsigned Idx) { assert(Expr && "Attribute must have an argument."); if (!Expr->isInstantiationDependent()) { @@ -3029,7 +3027,7 @@ static bool handleMaxWorkSizeAttrExpr(Sema &S, const AttrInfo &AI, Val = ArgVal->getZExtValue(); if (Val == 0) { S.Diag(Expr->getExprLoc(), diag::err_attribute_argument_is_zero) - << &AI << Expr->getSourceRange(); + << &AI << Expr->getSourceRange(); return false; } } @@ -3043,8 +3041,8 @@ static bool checkMaxWorkSizeAttrArguments(Sema &S, Expr *XDimExpr, // 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())) + (YDimExpr && YDimExpr->isValueDependent()) || + (ZDimExpr && ZDimExpr->isValueDependent())) return false; unsigned XDim = 0; @@ -3058,20 +3056,19 @@ static bool checkMaxWorkSizeAttrArguments(Sema &S, Expr *XDimExpr, unsigned ZDim = 0; if (ZDimExpr && !handleMaxWorkSizeAttrExpr(S, Attr, ZDimExpr, ZDim, 2)) return true; - return false; } template void Sema::addIntelSYCLTripleArgFunctionAttr(Decl *D, - const AttributeCommonInfo &CI, + const AttributeCommonInfo &CI, Expr *XDimExpr, Expr *YDimExpr, - Expr *ZDimExpr) { + Expr *ZDimExpr) { WorkGroupAttrType TmpAttr(Context, CI, XDimExpr, YDimExpr, ZDimExpr); if (checkMaxWorkSizeAttrArguments(*this, XDimExpr, YDimExpr, ZDimExpr, - TmpAttr)) + TmpAttr)) return; D->addAttr(::new (Context) @@ -3093,10 +3090,10 @@ static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) { auto SetDefaultValue = [](Sema &S, const ParsedAttr &AL, SourceLocation loc) { Expr *E; if (AL.getKind() == ParsedAttr::AT_ReqdWorkGroupSize && - AL.getAttributeSpellingListIndex() == - ReqdWorkGroupSizeAttr::CXX11_intel_reqd_work_group_size) { - E = IntegerLiteral::Create(S.Context, llvm::APInt(32, 1), - S.Context.IntTy, AL.getLoc()); + AL.getAttributeSpellingListIndex() == + ReqdWorkGroupSizeAttr::CXX11_intel_reqd_work_group_size) { + E = IntegerLiteral::Create(S.Context, llvm::APInt(32, 1), S.Context.IntTy, + AL.getLoc()); return E; } else { E = nullptr; @@ -3104,13 +3101,11 @@ static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) { } }; - Expr *YDimExpr = AL.isArgExpr(1) - ? AL.getArgAsExpr(1) - : SetDefaultValue(S, AL, AL.getLoc()); + Expr *YDimExpr = AL.isArgExpr(1) ? AL.getArgAsExpr(1) + : SetDefaultValue(S, AL, AL.getLoc()); - Expr *ZDimExpr = AL.isArgExpr(2) - ? AL.getArgAsExpr(2) - : SetDefaultValue(S, AL, AL.getLoc()); + Expr *ZDimExpr = AL.isArgExpr(2) ? AL.getArgAsExpr(2) + : SetDefaultValue(S, AL, AL.getLoc()); if ((AL.getKind() == ParsedAttr::AT_ReqdWorkGroupSize && AL.getAttributeSpellingListIndex() == diff --git a/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp b/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp index be0770846a6e3..baa5263482af2 100644 --- a/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp +++ b/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp @@ -88,8 +88,8 @@ int main() { []() [[intel::max_work_group_size(1.2f, 1, 3)]]{}); // expected-error{{'max_work_group_size' attribute requires an integer constant}} h.single_task( - []() [[intel::max_work_group_size(16, 16, 16), // expected-note{{duplicating attribute is here}} - intel::max_work_group_size(2, 2, 2)]]{}); // expected-warning{{attribute 'max_work_group_size' is already applied with different parameters}} + []() [[intel::max_work_group_size(16, 16, 16), // expected-note{{duplicating attribute is here}} + intel::max_work_group_size(2, 2, 2)]]{}); // expected-warning{{attribute 'max_work_group_size' is already applied with different parameters}} h.single_task( DAFuncObj()); From a72cc84f4ab932e584f2e6b5ff3b67076204e0ac Mon Sep 17 00:00:00 2001 From: Soumi Manna Date: Sun, 20 Dec 2020 12:22:34 -0800 Subject: [PATCH 06/21] Fix errors Signed-off-by: Soumi Manna --- clang/lib/Sema/SemaDeclAttr.cpp | 7 ++++--- clang/test/SemaSYCL/intel-max-work-group-size-device.cpp | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 128d5e5ba2e8a..34a2d1fefc634 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -2952,9 +2952,9 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr, Optional AttrZDim = Attr.getArgAsExpr(0)->getIntegerConstantExpr(S.getASTContext()); Result &= checkZeroDim(A, AttrXDim->getZExtValue(), - AttrYDim->getZExtValue(), AttrZDim->getZExtValue(), + AttrYDim->getZExtValue(), AttrZDim->getZExtValue(), /*ReverseAttrs=*/true); - } + } } if (const auto *A = D->getAttr()) { @@ -2985,7 +2985,7 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr, << "'intel::max_work_group_size'"; if (const auto *A = D->getAttr()) { - Optional AttrXDimVal= + Optional AttrXDimVal = Attr.getArgAsExpr(2)->getIntegerConstantExpr(S.getASTContext()); Optional AttrYDimVal = Attr.getArgAsExpr(1)->getIntegerConstantExpr(S.getASTContext()); @@ -3056,6 +3056,7 @@ static bool checkMaxWorkSizeAttrArguments(Sema &S, Expr *XDimExpr, unsigned ZDim = 0; if (ZDimExpr && !handleMaxWorkSizeAttrExpr(S, Attr, ZDimExpr, ZDim, 2)) return true; + return false; } diff --git a/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp b/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp index baa5263482af2..5886d9990951c 100644 --- a/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp +++ b/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp @@ -89,7 +89,7 @@ int main() { h.single_task( []() [[intel::max_work_group_size(16, 16, 16), // expected-note{{duplicating attribute is here}} - intel::max_work_group_size(2, 2, 2)]]{}); // expected-warning{{attribute 'max_work_group_size' is already applied with different parameters}} + intel::max_work_group_size(2, 2, 2)]]{}); // expected-warning{{attribute 'max_work_group_size' is already applied with different parameters}} h.single_task( DAFuncObj()); From 05f2d08c38f803621a33b83a1839d3e82e8b67c4 Mon Sep 17 00:00:00 2001 From: Soumi Manna Date: Sun, 20 Dec 2020 12:26:01 -0800 Subject: [PATCH 07/21] remove extra space issues Signed-off-by: Soumi Manna --- clang/lib/Sema/SemaDeclAttr.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 34a2d1fefc634..9696ff22776de 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -3058,7 +3058,6 @@ static bool checkMaxWorkSizeAttrArguments(Sema &S, Expr *XDimExpr, return true; return false; - } template From d06e05d169efcd354b5ef75cdb21bbdc6f2b87d1 Mon Sep 17 00:00:00 2001 From: Soumi Manna Date: Mon, 21 Dec 2020 12:06:53 -0800 Subject: [PATCH 08/21] Address review comments Signed-off-by: Soumi Manna --- .../clang/Basic/DiagnosticSemaKinds.td | 2 +- clang/lib/Sema/SemaDecl.cpp | 24 +++++++++---------- clang/lib/Sema/SemaDeclAttr.cpp | 12 ++++------ .../intel-max-work-group-size-device.cpp | 2 +- .../SemaSYCL/reqd-work-group-size-device.cpp | 2 +- 5 files changed, 20 insertions(+), 22 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index b1fdcedefcf2c..0bd5f9e5110e1 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3866,7 +3866,7 @@ def err_mismatched_visibility: Error<"visibility does not match previous declara def note_previous_attribute : Note<"previous attribute is here">; def note_conflicting_attribute : Note<"conflicting attribute is here">; def note_attribute : Note<"attribute is here">; -def note_duplicating_attribute : Note<"duplicating attribute is here">; +def note_duplicate_attribute : Note<"duplicate attribute is here">; def err_mismatched_ms_inheritance : Error< "inheritance model does not match %select{definition|previous declaration}0">; def warn_ignored_ms_inheritance : Warning< diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 42870814a17be..4d62d8165b98a 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -3207,18 +3207,18 @@ static void checkDimensionsAndSetDiagnostics(Sema &S, FunctionDecl *New, if (!NewDeclAttr || !OldDeclAttr) return; - int64_t NewXDimVal = - NewDeclAttr->getXDim()->getIntegerConstantExpr(S.Context)->getSExtValue(); - int64_t NewYDimVal = - NewDeclAttr->getYDim()->getIntegerConstantExpr(S.Context)->getSExtValue(); - int64_t NewZDimVal = - NewDeclAttr->getZDim()->getIntegerConstantExpr(S.Context)->getSExtValue(); - int64_t OldXDimVal = - OldDeclAttr->getXDim()->getIntegerConstantExpr(S.Context)->getSExtValue(); - int64_t OldYDimVal = - OldDeclAttr->getYDim()->getIntegerConstantExpr(S.Context)->getSExtValue(); - int64_t OldZDimVal = - OldDeclAttr->getZDim()->getIntegerConstantExpr(S.Context)->getSExtValue(); + unsigned NewXDimVal = + NewDeclAttr->getXDim()->getIntegerConstantExpr(S.Context)->getZExtValue(); + unsigned NewYDimVal = + NewDeclAttr->getYDim()->getIntegerConstantExpr(S.Context)->getZExtValue(); + unsigned NewZDimVal = + NewDeclAttr->getZDim()->getIntegerConstantExpr(S.Context)->getZExtValue(); + unsigned OldXDimVal = + OldDeclAttr->getXDim()->getIntegerConstantExpr(S.Context)->getZExtValue(); + unsigned OldYDimVal = + OldDeclAttr->getYDim()->getIntegerConstantExpr(S.Context)->getZExtValue(); + unsigned OldZDimVal = + OldDeclAttr->getZDim()->getIntegerConstantExpr(S.Context)->getZExtValue(); if ((NewXDimVal != OldXDimVal) || (NewYDimVal != OldYDimVal) || (NewZDimVal != OldZDimVal)) { diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 9696ff22776de..5ab18d8b60da2 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -2893,7 +2893,6 @@ static void handleWeakImportAttr(Sema &S, Decl *D, const ParsedAttr &AL) { D->addAttr(::new (S.Context) WeakImportAttr(S.Context, AL)); } -// Handles reqd_work_group_size and max_work_group_size // Checks correctness of mutual usage of different work_group_size attributes: // reqd_work_group_size, max_work_group_size and max_global_work_dim. // Values of reqd_work_group_size arguments shall be equal or less than values @@ -3075,6 +3074,7 @@ void Sema::addIntelSYCLTripleArgFunctionAttr(Decl *D, 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) { if (D->isInvalidDecl()) @@ -3091,14 +3091,12 @@ static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) { Expr *E; if (AL.getKind() == ParsedAttr::AT_ReqdWorkGroupSize && AL.getAttributeSpellingListIndex() == - ReqdWorkGroupSizeAttr::CXX11_intel_reqd_work_group_size) { + ReqdWorkGroupSizeAttr::CXX11_intel_reqd_work_group_size) E = IntegerLiteral::Create(S.Context, llvm::APInt(32, 1), S.Context.IntTy, AL.getLoc()); - return E; - } else { + else E = nullptr; - return E; - } + return E; }; Expr *YDimExpr = AL.isArgExpr(1) ? AL.getArgAsExpr(1) @@ -3137,7 +3135,7 @@ static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) { (ExistingYDimVal->getZExtValue() == YDimVal->getZExtValue()) && (ExistingZDimVal->getZExtValue() == ZDimVal->getZExtValue()))) { S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL; - S.Diag(ExistingAttr->getLocation(), diag::note_duplicating_attribute); + S.Diag(ExistingAttr->getLocation(), diag::note_duplicate_attribute); } } diff --git a/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp b/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp index 5886d9990951c..a26f1279bf49b 100644 --- a/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp +++ b/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp @@ -88,7 +88,7 @@ int main() { []() [[intel::max_work_group_size(1.2f, 1, 3)]]{}); // expected-error{{'max_work_group_size' attribute requires an integer constant}} h.single_task( - []() [[intel::max_work_group_size(16, 16, 16), // expected-note{{duplicating attribute is here}} + []() [[intel::max_work_group_size(16, 16, 16), // expected-note{{duplicate attribute is here}} intel::max_work_group_size(2, 2, 2)]]{}); // expected-warning{{attribute 'max_work_group_size' is already applied with different parameters}} h.single_task( diff --git a/clang/test/SemaSYCL/reqd-work-group-size-device.cpp b/clang/test/SemaSYCL/reqd-work-group-size-device.cpp index 56c905fa481a1..b3dfea9b1143f 100644 --- a/clang/test/SemaSYCL/reqd-work-group-size-device.cpp +++ b/clang/test/SemaSYCL/reqd-work-group-size-device.cpp @@ -24,7 +24,7 @@ class Functor16 { #ifdef TRIGGER_ERROR class Functor32 { public: - // expected-note@+3{{duplicating attribute is here}} + // expected-note@+3{{duplicate attribute is here}} // expected-warning@+2{{attribute 'reqd_work_group_size' is already applied with different parameters}} // expected-error@+1{{'reqd_work_group_size' attribute conflicts with 'reqd_work_group_size' attribute}} [[cl::reqd_work_group_size(32, 1, 1)]] [[cl::reqd_work_group_size(1, 1, 32)]] void operator()() const {} From e741d5796186b8a8af136f9c37045a3c9c2d7664 Mon Sep 17 00:00:00 2001 From: Soumi Manna Date: Mon, 21 Dec 2020 22:27:23 -0800 Subject: [PATCH 09/21] Address review comments Signed-off-by: Soumi Manna --- .../clang/Basic/DiagnosticSemaKinds.td | 1 - clang/lib/CodeGen/TargetInfo.cpp | 12 +- clang/lib/Sema/SemaDecl.cpp | 26 ++--- clang/lib/Sema/SemaDeclAttr.cpp | 106 +++++++----------- .../intel-max-work-group-size-device.cpp | 2 +- .../SemaSYCL/reqd-work-group-size-device.cpp | 2 +- 6 files changed, 59 insertions(+), 90 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 0bd5f9e5110e1..b67c28a77c27a 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3866,7 +3866,6 @@ def err_mismatched_visibility: Error<"visibility does not match previous declara def note_previous_attribute : Note<"previous attribute is here">; def note_conflicting_attribute : Note<"conflicting attribute is here">; def note_attribute : Note<"attribute is here">; -def note_duplicate_attribute : Note<"duplicate attribute is here">; def err_mismatched_ms_inheritance : Error< "inheritance model does not match %select{definition|previous declaration}0">; def warn_ignored_ms_inheritance : Warning< diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp index b6d64b1788729..20fa2a49c5900 100644 --- a/clang/lib/CodeGen/TargetInfo.cpp +++ b/clang/lib/CodeGen/TargetInfo.cpp @@ -8143,13 +8143,13 @@ void TCETargetCodeGenInfo::setTargetAttributes( Operands.push_back(llvm::ConstantAsMetadata::get(F)); unsigned XDim = Attr->getXDim() ->EvaluateKnownConstInt(M.getContext()) - .getExtValue(); + .getZExtValue(); unsigned YDim = Attr->getYDim() ->EvaluateKnownConstInt(M.getContext()) - .getExtValue(); + .getZExtValue(); unsigned ZDim = Attr->getZDim() ->EvaluateKnownConstInt(M.getContext()) - .getExtValue(); + .getZExtValue(); Operands.push_back(llvm::ConstantAsMetadata::get( llvm::Constant::getIntegerValue(M.Int32Ty, llvm::APInt(32, XDim)))); @@ -9050,13 +9050,13 @@ void AMDGPUTargetCodeGenInfo::setTargetAttributes( if (ReqdWGS) { XDim = ReqdWGS->getXDim() ->EvaluateKnownConstInt(M.getContext()) - .getExtValue(); + .getZExtValue(); YDim = ReqdWGS->getYDim() ->EvaluateKnownConstInt(M.getContext()) - .getExtValue(); + .getZExtValue(); ZDim = ReqdWGS->getZDim() ->EvaluateKnownConstInt(M.getContext()) - .getExtValue(); + .getZExtValue(); } if (ReqdWGS && Min == 0 && Max == 0) Min = Max = XDim * YDim * ZDim; diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 4d62d8165b98a..abe64f71a2af8 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -3207,21 +3207,17 @@ static void checkDimensionsAndSetDiagnostics(Sema &S, FunctionDecl *New, if (!NewDeclAttr || !OldDeclAttr) return; - unsigned NewXDimVal = - NewDeclAttr->getXDim()->getIntegerConstantExpr(S.Context)->getZExtValue(); - unsigned NewYDimVal = - NewDeclAttr->getYDim()->getIntegerConstantExpr(S.Context)->getZExtValue(); - unsigned NewZDimVal = - NewDeclAttr->getZDim()->getIntegerConstantExpr(S.Context)->getZExtValue(); - unsigned OldXDimVal = - OldDeclAttr->getXDim()->getIntegerConstantExpr(S.Context)->getZExtValue(); - unsigned OldYDimVal = - OldDeclAttr->getYDim()->getIntegerConstantExpr(S.Context)->getZExtValue(); - unsigned OldZDimVal = - OldDeclAttr->getZDim()->getIntegerConstantExpr(S.Context)->getZExtValue(); - - if ((NewXDimVal != OldXDimVal) || (NewYDimVal != OldYDimVal) || - (NewZDimVal != OldZDimVal)) { + /// Returns the usigned constant integer value represented by given expression. + auto getExprValue = [](const Expr *E, ASTContext &Ctx) { + return E->getIntegerConstantExpr(Ctx)->getZExtValue(); + }; + + if ((getExprValue(NewDeclAttr->getXDim(), S.getASTContext()) != + getExprValue(OldDeclAttr->getXDim(), S.getASTContext())) || + (getExprValue(NewDeclAttr->getYDim(), S.getASTContext()) != + getExprValue(OldDeclAttr->getYDim(), S.getASTContext())) || + (getExprValue(NewDeclAttr->getZDim(), S.getASTContext()) != + getExprValue(OldDeclAttr->getZDim(), S.getASTContext()))) { S.Diag(New->getLocation(), diag::err_conflicting_sycl_function_attributes) << OldDeclAttr << NewDeclAttr; S.Diag(New->getLocation(), diag::warn_duplicate_attribute) << OldDeclAttr; diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 5ab18d8b60da2..c2f03c3df2a48 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -2917,88 +2917,65 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr, return true; }; + /// Returns the usigned constant integer value represented by + /// given expression. + auto getExprValue = [](const Expr *E, ASTContext &Ctx) { + return E->getIntegerConstantExpr(Ctx)->getZExtValue(); + }; + if (Attr.getKind() == ParsedAttr::AT_SYCLIntelMaxGlobalWorkDim) { if (const auto *A = D->getAttr()) { - Optional XDimVal = - A->getXDim()->getIntegerConstantExpr(S.getASTContext()); - Optional YDimVal = - A->getYDim()->getIntegerConstantExpr(S.getASTContext()); - Optional ZDimVal = - A->getZDim()->getIntegerConstantExpr(S.getASTContext()); - Result &= checkZeroDim(A, XDimVal->getZExtValue(), - YDimVal->getZExtValue(), ZDimVal->getZExtValue()); + Result &= checkZeroDim(A, getExprValue(A->getXDim(), S.getASTContext()), + getExprValue(A->getYDim(), S.getASTContext()), + getExprValue(A->getZDim(), S.getASTContext())); } else if (const auto *A = D->getAttr()) { - Optional XDimVal = - A->getXDim()->getIntegerConstantExpr(S.getASTContext()); - Optional YDimVal = - A->getYDim()->getIntegerConstantExpr(S.getASTContext()); - Optional ZDimVal = - A->getZDim()->getIntegerConstantExpr(S.getASTContext()); - Result &= checkZeroDim(A, XDimVal->getZExtValue(), - YDimVal->getZExtValue(), ZDimVal->getZExtValue()); + Result &= checkZeroDim(A, getExprValue(A->getXDim(), S.getASTContext()), + getExprValue(A->getYDim(), S.getASTContext()), + getExprValue(A->getZDim(), S.getASTContext())); } return Result; } + if (Attr.getKind() == ParsedAttr::AT_SYCLIntelMaxWorkGroupSize && + checkDeprecatedSYCLAttributeSpelling(S, Attr)) + S.Diag(Attr.getLoc(), diag::note_spelling_suggestion) + << "'intel::max_work_group_size'"; + + // 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()) { int64_t AttrValue = A->getValue()->getIntegerConstantExpr(S.Context)->getSExtValue(); if (AttrValue == 0) { - Optional AttrXDim = - Attr.getArgAsExpr(2)->getIntegerConstantExpr(S.getASTContext()); - Optional AttrYDim = - Attr.getArgAsExpr(1)->getIntegerConstantExpr(S.getASTContext()); - Optional AttrZDim = - Attr.getArgAsExpr(0)->getIntegerConstantExpr(S.getASTContext()); - Result &= checkZeroDim(A, AttrXDim->getZExtValue(), - AttrYDim->getZExtValue(), AttrZDim->getZExtValue(), + Result &= checkZeroDim(A, S.getLangOpts().SYCLIsDevice && + getExprValue(Attr.getArgAsExpr(2), S.getASTContext()), + getExprValue(Attr.getArgAsExpr(1), S.getASTContext()), + getExprValue(Attr.getArgAsExpr(0), S.getASTContext()), /*ReverseAttrs=*/true); } } if (const auto *A = D->getAttr()) { - Optional AttrXDimVal = - Attr.getArgAsExpr(2)->getIntegerConstantExpr(S.getASTContext()); - Optional AttrYDimVal = - Attr.getArgAsExpr(1)->getIntegerConstantExpr(S.getASTContext()); - Optional AttrZDimVal = - Attr.getArgAsExpr(0)->getIntegerConstantExpr(S.getASTContext()); - Optional XDimVal = - A->getXDim()->getIntegerConstantExpr(S.getASTContext()); - Optional YDimVal = - A->getYDim()->getIntegerConstantExpr(S.getASTContext()); - Optional ZDimVal = - A->getZDim()->getIntegerConstantExpr(S.getASTContext()); - if (!(AttrXDimVal->getZExtValue() <= XDimVal->getZExtValue() && - AttrYDimVal->getZExtValue() <= YDimVal->getZExtValue() && - AttrZDimVal->getZExtValue() <= ZDimVal->getZExtValue())) { + if (!((getExprValue(Attr.getArgAsExpr(2), S.getASTContext()) <= + getExprValue(A->getXDim(), S.getASTContext())) && + (getExprValue(Attr.getArgAsExpr(1), S.getASTContext()) <= + getExprValue(A->getYDim(), S.getASTContext())) && + (getExprValue(Attr.getArgAsExpr(0), S.getASTContext()) <= + getExprValue(A->getZDim(), S.getASTContext())))) { S.Diag(Attr.getLoc(), diag::err_conflicting_sycl_function_attributes) << Attr << A->getSpelling(); Result &= false; } } - if (Attr.getKind() == ParsedAttr::AT_SYCLIntelMaxWorkGroupSize && - checkDeprecatedSYCLAttributeSpelling(S, Attr)) - S.Diag(Attr.getLoc(), diag::note_spelling_suggestion) - << "'intel::max_work_group_size'"; - if (const auto *A = D->getAttr()) { - Optional AttrXDimVal = - Attr.getArgAsExpr(2)->getIntegerConstantExpr(S.getASTContext()); - Optional AttrYDimVal = - Attr.getArgAsExpr(1)->getIntegerConstantExpr(S.getASTContext()); - Optional AttrZDimVal = - Attr.getArgAsExpr(0)->getIntegerConstantExpr(S.getASTContext()); - Optional XDimVal = - A->getXDim()->getIntegerConstantExpr(S.getASTContext()); - Optional YDimVal = - A->getYDim()->getIntegerConstantExpr(S.getASTContext()); - Optional ZDimVal = - A->getZDim()->getIntegerConstantExpr(S.getASTContext()); - if (!(AttrXDimVal->getZExtValue() >= XDimVal->getZExtValue() && - AttrYDimVal->getZExtValue() >= YDimVal->getZExtValue() && - AttrZDimVal->getZExtValue() >= ZDimVal->getZExtValue())) { + if (!((getExprValue(Attr.getArgAsExpr(2), S.getASTContext()) >= + getExprValue(A->getXDim(), S.getASTContext())) && + (getExprValue(Attr.getArgAsExpr(1), S.getASTContext()) >= + getExprValue(A->getYDim(), S.getASTContext())) && + (getExprValue(Attr.getArgAsExpr(0), S.getASTContext()) >= + getExprValue(A->getZDim(), S.getASTContext())))) { S.Diag(Attr.getLoc(), diag::err_conflicting_sycl_function_attributes) << Attr << A->getSpelling(); Result &= false; @@ -3088,15 +3065,11 @@ static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) { // for second and third attribute argument in ReqdWorkGroupSizeAttr // for only with intel::reqd_work_group_size spelling. auto SetDefaultValue = [](Sema &S, const ParsedAttr &AL, SourceLocation loc) { - Expr *E; if (AL.getKind() == ParsedAttr::AT_ReqdWorkGroupSize && AL.getAttributeSpellingListIndex() == ReqdWorkGroupSizeAttr::CXX11_intel_reqd_work_group_size) - E = IntegerLiteral::Create(S.Context, llvm::APInt(32, 1), S.Context.IntTy, - AL.getLoc()); - else - E = nullptr; - return E; + return IntegerLiteral::Create(S.Context, llvm::APInt(32, 1), + S.Context.IntTy, AL.getLoc()); }; Expr *YDimExpr = AL.isArgExpr(1) ? AL.getArgAsExpr(1) @@ -3113,6 +3086,7 @@ static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) { return; } + // For a SYCLDevice WorkGroupAttr arguments are reversed. if (S.getLangOpts().SYCLIsDevice) std::swap(XDimExpr, ZDimExpr); @@ -3135,7 +3109,7 @@ static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) { (ExistingYDimVal->getZExtValue() == YDimVal->getZExtValue()) && (ExistingZDimVal->getZExtValue() == ZDimVal->getZExtValue()))) { S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL; - S.Diag(ExistingAttr->getLocation(), diag::note_duplicate_attribute); + S.Diag(ExistingAttr->getLocation(), diag::note_conflicting_attribute); } } diff --git a/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp b/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp index a26f1279bf49b..1dfbf09550812 100644 --- a/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp +++ b/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp @@ -88,7 +88,7 @@ int main() { []() [[intel::max_work_group_size(1.2f, 1, 3)]]{}); // expected-error{{'max_work_group_size' attribute requires an integer constant}} h.single_task( - []() [[intel::max_work_group_size(16, 16, 16), // expected-note{{duplicate attribute is here}} + []() [[intel::max_work_group_size(16, 16, 16), // expected-note{{conflicting attribute is here}} intel::max_work_group_size(2, 2, 2)]]{}); // expected-warning{{attribute 'max_work_group_size' is already applied with different parameters}} h.single_task( diff --git a/clang/test/SemaSYCL/reqd-work-group-size-device.cpp b/clang/test/SemaSYCL/reqd-work-group-size-device.cpp index b3dfea9b1143f..441516a57ded9 100644 --- a/clang/test/SemaSYCL/reqd-work-group-size-device.cpp +++ b/clang/test/SemaSYCL/reqd-work-group-size-device.cpp @@ -24,7 +24,7 @@ class Functor16 { #ifdef TRIGGER_ERROR class Functor32 { public: - // expected-note@+3{{duplicate attribute is here}} + // expected-note@+3{{conflicting attribute is here}} // expected-warning@+2{{attribute 'reqd_work_group_size' is already applied with different parameters}} // expected-error@+1{{'reqd_work_group_size' attribute conflicts with 'reqd_work_group_size' attribute}} [[cl::reqd_work_group_size(32, 1, 1)]] [[cl::reqd_work_group_size(1, 1, 32)]] void operator()() const {} From 730d481cd787a87294bc2935980df87671d65c7c Mon Sep 17 00:00:00 2001 From: Soumi Manna Date: Mon, 21 Dec 2020 23:22:17 -0800 Subject: [PATCH 10/21] update patch Signed-off-by: Soumi Manna --- .../lib/Sema/SemaTemplateInstantiateDecl.cpp | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 2fc60360b2df0..84a945fe78af4 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -549,6 +549,32 @@ static void instantiateDependentAMDGPUWavesPerEUAttr( S.addAMDGPUWavesPerEUAttr(New, Attr, MinExpr, MaxExpr); } +template +static void instantiateIntelSYCTripleLFunctionAttr( + Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, + const AttrName *Attr, Decl *New) { + EnterExpressionEvaluationContext Unevaluated( + S, Sema::ExpressionEvaluationContext::ConstantEvaluated); + + ExprResult Result = S.SubstExpr(Attr->getXDim(), TemplateArgs); + if (Result.isInvalid()) + return; + Expr *XDimExpr = Result.getAs(); + + Result = S.SubstExpr(Attr->getYDim(), TemplateArgs); + if (Result.isInvalid()) + return; + Expr *YDimExpr = Result.getAs(); + + Result = S.SubstExpr(Attr->getZDim(), TemplateArgs); + if (Result.isInvalid()) + return; + Expr *ZDimExpr = Result.getAs(); + + S.addIntelSYCLTripleArgFunctionAttr(New, *Attr, XDimExpr, + YDimExpr, ZDimExpr); +} + template static void instantiateIntelFPGAMemoryAttr( Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, From 8359e95999316cdef3dc8bfde41e3364b955a6e7 Mon Sep 17 00:00:00 2001 From: Soumi Manna Date: Tue, 22 Dec 2020 00:08:11 -0800 Subject: [PATCH 11/21] Fix errors Signed-off-by: Soumi Manna --- clang/lib/Sema/SemaDecl.cpp | 3 ++- clang/lib/Sema/SemaDeclAttr.cpp | 23 ++++++++++--------- .../lib/Sema/SemaTemplateInstantiateDecl.cpp | 4 ++-- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 82fde8cc55c31..83c2b2bc0bd60 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -3207,7 +3207,8 @@ static void checkDimensionsAndSetDiagnostics(Sema &S, FunctionDecl *New, if (!NewDeclAttr || !OldDeclAttr) return; - /// Returns the usigned constant integer value represented by given expression. + /// Returns the usigned constant integer value represented by + // given expression. auto getExprValue = [](const Expr *E, ASTContext &Ctx) { return E->getIntegerConstantExpr(Ctx)->getZExtValue(); }; diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index c0e21d3c5da9d..e064f67797f4d 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -2963,12 +2963,12 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr, if (Attr.getKind() == ParsedAttr::AT_SYCLIntelMaxGlobalWorkDim) { if (const auto *A = D->getAttr()) { Result &= checkZeroDim(A, getExprValue(A->getXDim(), S.getASTContext()), - getExprValue(A->getYDim(), S.getASTContext()), - getExprValue(A->getZDim(), S.getASTContext())); + getExprValue(A->getYDim(), S.getASTContext()), + getExprValue(A->getZDim(), S.getASTContext())); } else if (const auto *A = D->getAttr()) { Result &= checkZeroDim(A, getExprValue(A->getXDim(), S.getASTContext()), - getExprValue(A->getYDim(), S.getASTContext()), - getExprValue(A->getZDim(), S.getASTContext())); + getExprValue(A->getYDim(), S.getASTContext()), + getExprValue(A->getZDim(), S.getASTContext())); } return Result; } @@ -2985,18 +2985,19 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr, int64_t AttrValue = A->getValue()->getIntegerConstantExpr(S.Context)->getSExtValue(); if (AttrValue == 0) { - Result &= checkZeroDim(A, S.getLangOpts().SYCLIsDevice && - getExprValue(Attr.getArgAsExpr(2), S.getASTContext()), - getExprValue(Attr.getArgAsExpr(1), S.getASTContext()), - getExprValue(Attr.getArgAsExpr(0), S.getASTContext()), - /*ReverseAttrs=*/true); + Result &= checkZeroDim( + A, + getExprValue(Attr.getArgAsExpr(2), S.getASTContext()), + getExprValue(Attr.getArgAsExpr(1), S.getASTContext()), + getExprValue(Attr.getArgAsExpr(0), S.getASTContext()), + /*ReverseAttrs=*/true); } } if (const auto *A = D->getAttr()) { if (!((getExprValue(Attr.getArgAsExpr(2), S.getASTContext()) <= getExprValue(A->getXDim(), S.getASTContext())) && - (getExprValue(Attr.getArgAsExpr(1), S.getASTContext()) <= + (getExprValue(Attr.getArgAsExpr(1), S.getASTContext()) <= getExprValue(A->getYDim(), S.getASTContext())) && (getExprValue(Attr.getArgAsExpr(0), S.getASTContext()) <= getExprValue(A->getZDim(), S.getASTContext())))) { @@ -3106,7 +3107,7 @@ static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) { AL.getAttributeSpellingListIndex() == ReqdWorkGroupSizeAttr::CXX11_intel_reqd_work_group_size) return IntegerLiteral::Create(S.Context, llvm::APInt(32, 1), - S.Context.IntTy, AL.getLoc()); + S.Context.IntTy, AL.getLoc()); }; Expr *YDimExpr = AL.isArgExpr(1) ? AL.getArgAsExpr(1) diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 84a945fe78af4..41646b5af17e0 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -571,8 +571,8 @@ static void instantiateIntelSYCTripleLFunctionAttr( return; Expr *ZDimExpr = Result.getAs(); - S.addIntelSYCLTripleArgFunctionAttr(New, *Attr, XDimExpr, - YDimExpr, ZDimExpr); + S.addIntelSYCLTripleArgFunctionAttr(New, *Attr, XDimExpr, YDimExpr, + ZDimExpr); } template From 6b01ac347274f2d150a600e5013c1093dcaaba1b Mon Sep 17 00:00:00 2001 From: Soumi Manna Date: Tue, 22 Dec 2020 00:12:41 -0800 Subject: [PATCH 12/21] Fix errors Signed-off-by: Soumi Manna --- clang/lib/Sema/SemaDeclAttr.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index e064f67797f4d..c6580999fba51 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -2985,12 +2985,11 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr, int64_t AttrValue = A->getValue()->getIntegerConstantExpr(S.Context)->getSExtValue(); if (AttrValue == 0) { - Result &= checkZeroDim( - A, - getExprValue(Attr.getArgAsExpr(2), S.getASTContext()), - getExprValue(Attr.getArgAsExpr(1), S.getASTContext()), - getExprValue(Attr.getArgAsExpr(0), S.getASTContext()), - /*ReverseAttrs=*/true); + Result &= + checkZeroDim(A, getExprValue(Attr.getArgAsExpr(2), S.getASTContext()), + getExprValue(Attr.getArgAsExpr(1), S.getASTContext()), + getExprValue(Attr.getArgAsExpr(0), S.getASTContext()), + /*ReverseAttrs=*/true); } } From ef03d041487bb1244efe91db1f2ba0b98a7b0456 Mon Sep 17 00:00:00 2001 From: Soumi Manna Date: Tue, 22 Dec 2020 00:18:16 -0800 Subject: [PATCH 13/21] Fix errors Signed-off-by: Soumi Manna --- clang/lib/Sema/SemaDeclAttr.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index c6580999fba51..d41d11105fed4 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -2985,11 +2985,11 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr, int64_t AttrValue = A->getValue()->getIntegerConstantExpr(S.Context)->getSExtValue(); if (AttrValue == 0) { - Result &= - checkZeroDim(A, getExprValue(Attr.getArgAsExpr(2), S.getASTContext()), - getExprValue(Attr.getArgAsExpr(1), S.getASTContext()), - getExprValue(Attr.getArgAsExpr(0), S.getASTContext()), - /*ReverseAttrs=*/true); + Result &= + checkZeroDim(A, getExprValue(Attr.getArgAsExpr(2), S.getASTContext()), + getExprValue(Attr.getArgAsExpr(1), S.getASTContext()), + getExprValue(Attr.getArgAsExpr(0), S.getASTContext()), + /*ReverseAttrs=*/true); } } From 8dccbfd1a11a59eeaa5e43e18bb50c1c5f70017a Mon Sep 17 00:00:00 2001 From: Soumi Manna Date: Tue, 22 Dec 2020 18:32:28 -0800 Subject: [PATCH 14/21] Address review comments Signed-off-by: Soumi Manna --- clang/include/clang/Basic/Attr.td | 12 ++++- clang/lib/Sema/SemaDecl.cpp | 2 +- clang/lib/Sema/SemaDeclAttr.cpp | 74 ++++++++++++++++--------------- 3 files changed, 51 insertions(+), 37 deletions(-) diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index bcf54ab38d3fc..78fd2f9575089 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -1292,8 +1292,13 @@ def SYCLIntelMaxWorkGroupSize : InheritableAttr { ExprArgument<"ZDim">]; let LangOpts = [SYCLIsDevice, SYCLIsHost]; let Subjects = SubjectList<[Function], ErrorDiag>; - let Documentation = [SYCLIntelMaxWorkGroupSizeAttrDocs]; let PragmaAttributeSupport = 0; + let AdditionalMembers = [{ + ArrayRef dimensions() const { + return {getXDim(), getYDim(), getZDim()}; + } + }]; + let Documentation = [SYCLIntelMaxWorkGroupSizeAttrDocs]; } def SYCLIntelMaxGlobalWorkDim : InheritableAttr { @@ -2810,6 +2815,11 @@ def ReqdWorkGroupSize : InheritableAttr { ExprArgument<"YDim", /*optional*/1>, ExprArgument<"ZDim", /*optional*/1>]; let Subjects = SubjectList<[Function], ErrorDiag>; + let AdditionalMembers = [{ + ArrayRef dimensions() const { + return {getXDim(), getYDim(), getZDim()}; + } + }]; let Documentation = [ReqdWorkGroupSizeAttrDocs]; } diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 83c2b2bc0bd60..22283b92a83c8 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -3208,7 +3208,7 @@ static void checkDimensionsAndSetDiagnostics(Sema &S, FunctionDecl *New, return; /// Returns the usigned constant integer value represented by - // given expression. + /// given expression. auto getExprValue = [](const Expr *E, ASTContext &Ctx) { return E->getIntegerConstantExpr(Ctx)->getZExtValue(); }; diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index d41d11105fed4..96174344581d7 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -2937,18 +2937,18 @@ static void handleWeakImportAttr(Sema &S, Decl *D, const ParsedAttr &AL) { // In case the value of 'max_global_work_dim' attribute equals to 0 we shall // ensure that if max_work_group_size and reqd_work_group_size attributes exist, // they hold equal values (1, 1, 1). -static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr, +static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &AL, uint32_t WGSize[3]) { bool Result = true; - auto checkZeroDim = [&S, &Attr](auto &A, size_t X, size_t Y, size_t Z, + auto checkZeroDim = [&S, &AL](auto &A, size_t X, size_t Y, size_t Z, bool ReverseAttrs = false) -> bool { if (X != 1 || Y != 1 || Z != 1) { auto Diag = - S.Diag(Attr.getLoc(), diag::err_sycl_x_y_z_arguments_must_be_one); + S.Diag(AL.getLoc(), diag::err_sycl_x_y_z_arguments_must_be_one); if (ReverseAttrs) - Diag << Attr << A; + Diag << AL << A; else - Diag << A << Attr; + Diag << A << AL; return false; } return true; @@ -2960,22 +2960,24 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr, return E->getIntegerConstantExpr(Ctx)->getZExtValue(); }; - if (Attr.getKind() == ParsedAttr::AT_SYCLIntelMaxGlobalWorkDim) { - if (const auto *A = D->getAttr()) { - Result &= checkZeroDim(A, getExprValue(A->getXDim(), S.getASTContext()), - getExprValue(A->getYDim(), S.getASTContext()), - getExprValue(A->getZDim(), S.getASTContext())); - } else if (const auto *A = D->getAttr()) { - Result &= checkZeroDim(A, getExprValue(A->getXDim(), S.getASTContext()), - getExprValue(A->getYDim(), S.getASTContext()), - getExprValue(A->getZDim(), S.getASTContext())); + if (AL.getKind() == ParsedAttr::AT_SYCLIntelMaxGlobalWorkDim) { + ArrayRef Dims; + Attr *B = nullptr; + if (const auto *B = D->getAttr()) + Dims = B->dimensions(); + else if (const auto *B = D->getAttr()) + Dims = B->dimensions(); + if (B) { + Result &= checkZeroDim(B, getExprValue(Dims[0], S.getASTContext()), + getExprValue(Dims[1], S.getASTContext()), + getExprValue(Dims[2], S.getASTContext())); } return Result; } - if (Attr.getKind() == ParsedAttr::AT_SYCLIntelMaxWorkGroupSize && - checkDeprecatedSYCLAttributeSpelling(S, Attr)) - S.Diag(Attr.getLoc(), diag::note_spelling_suggestion) + if (AL.getKind() == ParsedAttr::AT_SYCLIntelMaxWorkGroupSize && + checkDeprecatedSYCLAttributeSpelling(S, AL)) + S.Diag(AL.getLoc(), diag::note_spelling_suggestion) << "'intel::max_work_group_size'"; // For a SYCLDevice, WorkGroupAttr arguments are reversed. @@ -2986,35 +2988,35 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr, A->getValue()->getIntegerConstantExpr(S.Context)->getSExtValue(); if (AttrValue == 0) { Result &= - checkZeroDim(A, getExprValue(Attr.getArgAsExpr(2), S.getASTContext()), - getExprValue(Attr.getArgAsExpr(1), S.getASTContext()), - getExprValue(Attr.getArgAsExpr(0), S.getASTContext()), + checkZeroDim(A, getExprValue(AL.getArgAsExpr(2), S.getASTContext()), + getExprValue(AL.getArgAsExpr(1), S.getASTContext()), + getExprValue(AL.getArgAsExpr(0), S.getASTContext()), /*ReverseAttrs=*/true); } } if (const auto *A = D->getAttr()) { - if (!((getExprValue(Attr.getArgAsExpr(2), S.getASTContext()) <= + if (!((getExprValue(AL.getArgAsExpr(2), S.getASTContext()) <= getExprValue(A->getXDim(), S.getASTContext())) && - (getExprValue(Attr.getArgAsExpr(1), S.getASTContext()) <= + (getExprValue(AL.getArgAsExpr(1), S.getASTContext()) <= getExprValue(A->getYDim(), S.getASTContext())) && - (getExprValue(Attr.getArgAsExpr(0), S.getASTContext()) <= + (getExprValue(AL.getArgAsExpr(0), S.getASTContext()) <= getExprValue(A->getZDim(), S.getASTContext())))) { - S.Diag(Attr.getLoc(), diag::err_conflicting_sycl_function_attributes) - << Attr << A->getSpelling(); + S.Diag(AL.getLoc(), diag::err_conflicting_sycl_function_attributes) + << AL << A->getSpelling(); Result &= false; } } if (const auto *A = D->getAttr()) { - if (!((getExprValue(Attr.getArgAsExpr(2), S.getASTContext()) >= + if (!((getExprValue(AL.getArgAsExpr(2), S.getASTContext()) >= getExprValue(A->getXDim(), S.getASTContext())) && - (getExprValue(Attr.getArgAsExpr(1), S.getASTContext()) >= + (getExprValue(AL.getArgAsExpr(1), S.getASTContext()) >= getExprValue(A->getYDim(), S.getASTContext())) && - (getExprValue(Attr.getArgAsExpr(0), S.getASTContext()) >= + (getExprValue(AL.getArgAsExpr(0), S.getASTContext()) >= getExprValue(A->getZDim(), S.getASTContext())))) { - S.Diag(Attr.getLoc(), diag::err_conflicting_sycl_function_attributes) - << Attr << A->getSpelling(); + S.Diag(AL.getLoc(), diag::err_conflicting_sycl_function_attributes) + << AL << A->getSpelling(); Result &= false; } } @@ -3102,11 +3104,13 @@ static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) { // for second and third attribute argument in ReqdWorkGroupSizeAttr // for only with intel::reqd_work_group_size spelling. auto SetDefaultValue = [](Sema &S, const ParsedAttr &AL, SourceLocation loc) { - if (AL.getKind() == ParsedAttr::AT_ReqdWorkGroupSize && - AL.getAttributeSpellingListIndex() == - ReqdWorkGroupSizeAttr::CXX11_intel_reqd_work_group_size) - return IntegerLiteral::Create(S.Context, llvm::APInt(32, 1), - S.Context.IntTy, AL.getLoc()); + Expr *E = (AL.getKind() == ParsedAttr::AT_ReqdWorkGroupSize && + AL.getAttributeSpellingListIndex() == + ReqdWorkGroupSizeAttr::CXX11_intel_reqd_work_group_size) + ? IntegerLiteral::Create(S.Context, llvm::APInt(32, 1), + S.Context.IntTy, AL.getLoc()) + : nullptr; + return E; }; Expr *YDimExpr = AL.isArgExpr(1) ? AL.getArgAsExpr(1) From e749b0ec79ae754ba65f02e15f58921dd48313d4 Mon Sep 17 00:00:00 2001 From: Soumi Manna Date: Tue, 22 Dec 2020 18:37:52 -0800 Subject: [PATCH 15/21] Address review comments Signed-off-by: Soumi Manna --- clang/lib/Sema/SemaDeclAttr.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 96174344581d7..ca0af7251740d 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -2941,7 +2941,7 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &AL, uint32_t WGSize[3]) { bool Result = true; auto checkZeroDim = [&S, &AL](auto &A, size_t X, size_t Y, size_t Z, - bool ReverseAttrs = false) -> bool { + bool ReverseAttrs = false) -> bool { if (X != 1 || Y != 1 || Z != 1) { auto Diag = S.Diag(AL.getLoc(), diag::err_sycl_x_y_z_arguments_must_be_one); @@ -3106,10 +3106,10 @@ static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) { auto SetDefaultValue = [](Sema &S, const ParsedAttr &AL, SourceLocation loc) { Expr *E = (AL.getKind() == ParsedAttr::AT_ReqdWorkGroupSize && AL.getAttributeSpellingListIndex() == - ReqdWorkGroupSizeAttr::CXX11_intel_reqd_work_group_size) - ? IntegerLiteral::Create(S.Context, llvm::APInt(32, 1), - S.Context.IntTy, AL.getLoc()) - : nullptr; + ReqdWorkGroupSizeAttr::CXX11_intel_reqd_work_group_size) + ? IntegerLiteral::Create(S.Context, llvm::APInt(32, 1), + S.Context.IntTy, AL.getLoc()) + : nullptr; return E; }; From 767ded2fdbe121f82c84790a5d71e21122589bd6 Mon Sep 17 00:00:00 2001 From: Soumi Manna Date: Wed, 23 Dec 2020 10:42:25 -0800 Subject: [PATCH 16/21] add warning diagnostic for nrgative attribute values and updated tests Signed-off-by: Soumi Manna --- clang/lib/Sema/SemaDeclAttr.cpp | 6 ++++++ clang/test/SemaOpenCL/invalid-kernel-attrs.cl | 2 +- .../intel-max-work-group-size-device.cpp | 15 +++++--------- .../intel-reqd-work-group-size-device.cpp | 20 ++++++------------- ...ice-intel-max-work-group-size-template.cpp | 4 ++++ ...ce-intel-reqd-work-group-size-template.cpp | 4 ++++ ...l-device-reqd-work-group-size-template.cpp | 6 ++++++ 7 files changed, 32 insertions(+), 25 deletions(-) diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index ca0af7251740d..2bc2092c90456 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -3039,6 +3039,12 @@ static bool handleMaxWorkSizeAttrExpr(Sema &S, const AttrInfo &AI, return false; } + if (ArgVal->isNegative()) { + S.Diag(getAttrLoc(AI), diag::warn_attribute_requires_positive_integer) + << &AI << /*non-negative*/ 1; + return false; + } + Val = ArgVal->getZExtValue(); if (Val == 0) { S.Diag(Expr->getExprLoc(), diag::err_attribute_argument_is_zero) diff --git a/clang/test/SemaOpenCL/invalid-kernel-attrs.cl b/clang/test/SemaOpenCL/invalid-kernel-attrs.cl index c5b42155a5d6b..9277f45f41306 100644 --- a/clang/test/SemaOpenCL/invalid-kernel-attrs.cl +++ b/clang/test/SemaOpenCL/invalid-kernel-attrs.cl @@ -42,7 +42,7 @@ kernel __attribute__((intel_reqd_sub_group_size(-1))) void kernel16() {} // expe kernel __attribute__((intel_reqd_sub_group_size(8))) __attribute__((intel_reqd_sub_group_size(16))) void kernel17() {} //expected-warning{{attribute 'intel_reqd_sub_group_size' is already applied with different parameters}} __kernel __attribute__((work_group_size_hint(8,-16,32))) void neg1() {} //expected-error{{'work_group_size_hint' attribute requires a non-negative integral compile time constant expression}} -__kernel __attribute__((reqd_work_group_size(8, 16, -32))) void neg2() {} // OK +__kernel __attribute__((reqd_work_group_size(8, 16, -32))) void neg2() {} //expected-warning{{'reqd_work_group_size' attribute requires a non-negative integral compile time constant expression - attribute ignored}} // 4294967294 is a negative integer if treated as signed. // Should compile successfully, since we expect an unsigned. diff --git a/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp b/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp index 1dfbf09550812..ea2a72093c4e6 100644 --- a/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp +++ b/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp @@ -69,21 +69,16 @@ int main() { h.single_task( []() { func_do_not_ignore(); }); - // CHECK-LABEL: FunctionDecl {{.*}}test_kernel4 - // CHECK: SYCLIntelMaxWorkGroupSizeAttr {{.*}} - // CHECK-NEXT: IntegerLiteral{{.*}}1{{$}} - // CHECK-NEXT: IntegerLiteral{{.*}}8{{$}} - // CHECK-NEXT: UnaryOperator{{.*}} 'int' prefix '-' - // CHECK-NEXT: IntegerLiteral{{.*}}8{{$}} - h.single_task( - []() [[intel::max_work_group_size(-8, 8, 1)]]{}); - #ifdef TRIGGER_ERROR [[intel::max_work_group_size(1, 1, 1)]] int Var = 0; // expected-error{{'max_work_group_size' attribute only applies to functions}} - h.single_task( + h.single_task( []() [[intel::max_work_group_size(0, 1, 3)]]{}); // expected-error{{'max_work_group_size' attribute must be greater than 0}} + // expected-warning@+2{{'max_work_group_size' attribute requires a non-negative integral compile time constant expression - attribute ignored}} + h.single_task( + []() [[intel::max_work_group_size(-8, 8, 1)]]{}); + h.single_task( []() [[intel::max_work_group_size(1.2f, 1, 3)]]{}); // expected-error{{'max_work_group_size' attribute requires an integer constant}} diff --git a/clang/test/SemaSYCL/intel-reqd-work-group-size-device.cpp b/clang/test/SemaSYCL/intel-reqd-work-group-size-device.cpp index ddb8234981edc..70ac41290502a 100644 --- a/clang/test/SemaSYCL/intel-reqd-work-group-size-device.cpp +++ b/clang/test/SemaSYCL/intel-reqd-work-group-size-device.cpp @@ -40,6 +40,7 @@ class Functor32 { class Functor33 { public: + // expected-warning@+1{{'reqd_work_group_size' attribute requires a non-negative integral compile time constant expression - attribute ignored}} [[intel::reqd_work_group_size(32, -4)]] void operator()() const {} }; @@ -91,27 +92,24 @@ int main() { FunctorAttr fattr; h.single_task(fattr); - Functor33 f33; - h.single_task(f33); - - h.single_task([]() [[intel::reqd_work_group_size(32, 32, 32)]] { + h.single_task([]() [[intel::reqd_work_group_size(32, 32, 32)]] { f32x32x32(); }); #ifdef TRIGGER_ERROR Functor8 f8; - h.single_task(f8); + h.single_task(f8); - h.single_task([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}} + h.single_task([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}} f4x1x1(); f32x1x1(); }); - h.single_task([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}} + h.single_task([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}} f16x1x1(); f16x16x1(); }); - h.single_task([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}} + h.single_task([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}} f32x32x32(); f32x32x1(); }); @@ -148,12 +146,6 @@ int main() { // CHECK-NEXT: IntegerLiteral{{.*}}128{{$}} // CHECK: FunctionDecl {{.*}} {{.*}}kernel_name5 // CHECK: ReqdWorkGroupSizeAttr {{.*}} -// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}} -// CHECK-NEXT: UnaryOperator{{.*}} 'int' prefix '-' -// CHECK-NEXT: IntegerLiteral{{.*}}4{{$}} -// CHECK-NEXT: IntegerLiteral{{.*}}32{{$}} -// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name6 -// CHECK: ReqdWorkGroupSizeAttr {{.*}} // CHECK-NEXT: IntegerLiteral{{.*}}32{{$}} // CHECK-NEXT: IntegerLiteral{{.*}}32{{$}} // CHECK-NEXT: IntegerLiteral{{.*}}32{{$}} diff --git a/clang/test/SemaSYCL/sycl-device-intel-max-work-group-size-template.cpp b/clang/test/SemaSYCL/sycl-device-intel-max-work-group-size-template.cpp index 50cc361c19796..16c6ed9b366a9 100644 --- a/clang/test/SemaSYCL/sycl-device-intel-max-work-group-size-template.cpp +++ b/clang/test/SemaSYCL/sycl-device-intel-max-work-group-size-template.cpp @@ -28,10 +28,14 @@ constexpr int bar() { return 0; } template class KernelFunctor { public: + // expected-warning@+1{{'max_work_group_size' attribute requires a non-negative integral compile time constant expression - attribute ignored}} [[intel::max_work_group_size(SIZE, SIZE1, SIZE2)]] void operator()() {} }; int main() { + //expected-note@+1{{in instantiation of template class 'KernelFunctor<-1, -1, -1>' requested here}} + KernelFunctor<-1, -1, -1>(); + // no error expected KernelFunctor<4, 4, 4>(); } diff --git a/clang/test/SemaSYCL/sycl-device-intel-reqd-work-group-size-template.cpp b/clang/test/SemaSYCL/sycl-device-intel-reqd-work-group-size-template.cpp index 0e00286f9a287..b09b841e44126 100644 --- a/clang/test/SemaSYCL/sycl-device-intel-reqd-work-group-size-template.cpp +++ b/clang/test/SemaSYCL/sycl-device-intel-reqd-work-group-size-template.cpp @@ -28,10 +28,14 @@ constexpr int bar() { return 0; } template class KernelFunctor { public: + // expected-warning@+1{{'reqd_work_group_size' attribute requires a non-negative integral compile time constant expression - attribute ignored}} [[intel::reqd_work_group_size(SIZE, SIZE1, SIZE2)]] void operator()() {} }; int main() { + //expected-note@+1{{in instantiation of template class 'KernelFunctor<-1, -1, -1>' requested here}} + KernelFunctor<-1, -1, -1>(); + // no error expected KernelFunctor<16, 1, 1>(); } diff --git a/clang/test/SemaSYCL/sycl-device-reqd-work-group-size-template.cpp b/clang/test/SemaSYCL/sycl-device-reqd-work-group-size-template.cpp index 605bbce1d09b6..03ec14bdbbefb 100644 --- a/clang/test/SemaSYCL/sycl-device-reqd-work-group-size-template.cpp +++ b/clang/test/SemaSYCL/sycl-device-reqd-work-group-size-template.cpp @@ -28,10 +28,14 @@ constexpr int bar() { return 0; } template class KernelFunctor { public: + // expected-warning@+1{{'reqd_work_group_size' attribute requires a non-negative integral compile time constant expression - attribute ignored}} [[cl::reqd_work_group_size(SIZE, SIZE1, SIZE2)]] void operator()() {} }; int main() { + //expected-note@+1{{in instantiation of template class 'KernelFunctor<-1, -1, -1>' requested here}} + KernelFunctor<-1, -1, -1>(); + // no error expected KernelFunctor<16, 1, 1>(); } @@ -60,6 +64,8 @@ int check() { // CHECK: FunctionTemplateDecl {{.*}} {{.*}} func3 // CHECK: NonTypeTemplateParmDecl {{.*}} {{.*}} referenced 'int' depth 0 index 0 N +// CHECK: NonTypeTemplateParmDecl {{.*}} {{.*}} referenced 'int' depth 0 index 1 N1 +// CHECK: NonTypeTemplateParmDecl {{.*}} {{.*}} referenced 'int' depth 0 index 2 N2 // CHECK: FunctionDecl {{.*}} {{.*}} func3 'void ()' // CHECK: ReqdWorkGroupSizeAttr {{.*}} // CHECK: SubstNonTypeTemplateParmExpr {{.*}} From 245fa089bd932018e6bf05a89c5220a8e44254f1 Mon Sep 17 00:00:00 2001 From: Soumi Manna Date: Wed, 23 Dec 2020 13:07:33 -0800 Subject: [PATCH 17/21] Accept attribute with negative value Signed-off-by: Soumi Manna --- clang/include/clang/Basic/DiagnosticGroups.td | 4 +++- .../clang/Basic/DiagnosticSemaKinds.td | 3 +++ clang/lib/Sema/SemaDeclAttr.cpp | 6 ++--- clang/test/SemaOpenCL/invalid-kernel-attrs.cl | 2 +- .../intel-max-work-group-size-device.cpp | 16 +++++++++---- .../intel-reqd-work-group-size-device.cpp | 23 +++++++++++++------ ...ice-intel-max-work-group-size-template.cpp | 4 ---- ...ce-intel-reqd-work-group-size-template.cpp | 4 ---- ...l-device-reqd-work-group-size-template.cpp | 4 ---- 9 files changed, 37 insertions(+), 29 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 4b42a37fd33aa..96229d366d2fb 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -667,8 +667,10 @@ def NSReturnsMismatch : DiagGroup<"nsreturns-mismatch">; def IndependentClassAttribute : DiagGroup<"IndependentClass-attribute">; def UnknownAttributes : DiagGroup<"unknown-attributes">; def IgnoredAttributes : DiagGroup<"ignored-attributes">; +def AcceptedAttributes : DiagGroup<"accepted-attributes">; def Attributes : DiagGroup<"attributes", [UnknownAttributes, - IgnoredAttributes]>; + IgnoredAttributes, + AcceptedAttributes]>; def UnknownSanitizers : DiagGroup<"unknown-sanitizers">; def UnnamedTypeTemplateArgs : DiagGroup<"unnamed-type-template-args", [CXX98CompatUnnamedTypeTemplateArgs]>; diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 8548280f848a0..362149229a681 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -11207,6 +11207,9 @@ def warn_attribute_spelling_deprecated : Warning< InGroup; def note_spelling_suggestion : Note< "did you mean to use %0 instead?">; +def warn_attribute_requires_non_negative_integer_argument : Warning< + "%0 attribute requires a non-negative integral compile time constant expression">, + InGroup; // errors of expect.with.probability def err_probability_not_constant_float : Error< diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 2bc2092c90456..5a5a717a5b78a 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -3040,9 +3040,9 @@ static bool handleMaxWorkSizeAttrExpr(Sema &S, const AttrInfo &AI, } if (ArgVal->isNegative()) { - S.Diag(getAttrLoc(AI), diag::warn_attribute_requires_positive_integer) - << &AI << /*non-negative*/ 1; - return false; + S.Diag(getAttrLoc(AI), + diag::warn_attribute_requires_non_negative_integer_argument) << &AI; + return true; } Val = ArgVal->getZExtValue(); diff --git a/clang/test/SemaOpenCL/invalid-kernel-attrs.cl b/clang/test/SemaOpenCL/invalid-kernel-attrs.cl index 9277f45f41306..92f8ca18df69c 100644 --- a/clang/test/SemaOpenCL/invalid-kernel-attrs.cl +++ b/clang/test/SemaOpenCL/invalid-kernel-attrs.cl @@ -42,7 +42,7 @@ kernel __attribute__((intel_reqd_sub_group_size(-1))) void kernel16() {} // expe kernel __attribute__((intel_reqd_sub_group_size(8))) __attribute__((intel_reqd_sub_group_size(16))) void kernel17() {} //expected-warning{{attribute 'intel_reqd_sub_group_size' is already applied with different parameters}} __kernel __attribute__((work_group_size_hint(8,-16,32))) void neg1() {} //expected-error{{'work_group_size_hint' attribute requires a non-negative integral compile time constant expression}} -__kernel __attribute__((reqd_work_group_size(8, 16, -32))) void neg2() {} //expected-warning{{'reqd_work_group_size' attribute requires a non-negative integral compile time constant expression - attribute ignored}} +__kernel __attribute__((reqd_work_group_size(8, 16, -32))) void neg2() {} //expected-warning{{'reqd_work_group_size' attribute requires a non-negative integral compile time constant expression}} // 4294967294 is a negative integer if treated as signed. // Should compile successfully, since we expect an unsigned. diff --git a/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp b/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp index ea2a72093c4e6..cc6361765f46f 100644 --- a/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp +++ b/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp @@ -69,15 +69,21 @@ int main() { h.single_task( []() { func_do_not_ignore(); }); + // CHECK-LABEL: FunctionDecl {{.*}}test_kernel4 + // CHECK: SYCLIntelMaxWorkGroupSizeAttr {{.*}} + // CHECK-NEXT: IntegerLiteral{{.*}}1{{$}} + // CHECK-NEXT: IntegerLiteral{{.*}}8{{$}} + // CHECK-NEXT: UnaryOperator{{.*}} 'int' prefix '-' + // CHECK-NEXT: IntegerLiteral{{.*}}8{{$}} + // expected-warning@+2{{'max_work_group_size' attribute requires a non-negative integral compile time constant expression}} + h.single_task( + []() [[intel::max_work_group_size(-8, 8, 1)]]{}); + #ifdef TRIGGER_ERROR [[intel::max_work_group_size(1, 1, 1)]] int Var = 0; // expected-error{{'max_work_group_size' attribute only applies to functions}} - h.single_task( - []() [[intel::max_work_group_size(0, 1, 3)]]{}); // expected-error{{'max_work_group_size' attribute must be greater than 0}} - - // expected-warning@+2{{'max_work_group_size' attribute requires a non-negative integral compile time constant expression - attribute ignored}} h.single_task( - []() [[intel::max_work_group_size(-8, 8, 1)]]{}); + []() [[intel::max_work_group_size(0, 1, 3)]]{}); // expected-error{{'max_work_group_size' attribute must be greater than 0}} h.single_task( []() [[intel::max_work_group_size(1.2f, 1, 3)]]{}); // expected-error{{'max_work_group_size' attribute requires an integer constant}} diff --git a/clang/test/SemaSYCL/intel-reqd-work-group-size-device.cpp b/clang/test/SemaSYCL/intel-reqd-work-group-size-device.cpp index 70ac41290502a..1b29afff3547e 100644 --- a/clang/test/SemaSYCL/intel-reqd-work-group-size-device.cpp +++ b/clang/test/SemaSYCL/intel-reqd-work-group-size-device.cpp @@ -40,7 +40,7 @@ class Functor32 { class Functor33 { public: - // expected-warning@+1{{'reqd_work_group_size' attribute requires a non-negative integral compile time constant expression - attribute ignored}} + // expected-warning@+1{{'reqd_work_group_size' attribute requires a non-negative integral compile time constant expression}} [[intel::reqd_work_group_size(32, -4)]] void operator()() const {} }; @@ -92,30 +92,33 @@ int main() { FunctorAttr fattr; h.single_task(fattr); - h.single_task([]() [[intel::reqd_work_group_size(32, 32, 32)]] { + Functor33 f33; + h.single_task(f33); + + h.single_task([]() [[intel::reqd_work_group_size(32, 32, 32)]] { f32x32x32(); }); #ifdef TRIGGER_ERROR Functor8 f8; - h.single_task(f8); + h.single_task(f8); - h.single_task([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}} + h.single_task([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}} f4x1x1(); f32x1x1(); }); - h.single_task([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}} + h.single_task([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}} f16x1x1(); f16x16x1(); }); - h.single_task([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}} + h.single_task([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}} f32x32x32(); f32x32x1(); }); // expected-error@+1 {{expected variable name or 'this' in lambda capture list}} - h.single_task([[intel::reqd_work_group_size(32, 32, 32)]][]() { + h.single_task([[intel::reqd_work_group_size(32, 32, 32)]][]() { f32x32x32(); }); @@ -146,6 +149,12 @@ int main() { // CHECK-NEXT: IntegerLiteral{{.*}}128{{$}} // CHECK: FunctionDecl {{.*}} {{.*}}kernel_name5 // CHECK: ReqdWorkGroupSizeAttr {{.*}} +// CHECK-NEXT: IntegerLiteral{{.*}}1{{$}} +// CHECK-NEXT: UnaryOperator{{.*}} 'int' prefix '-' +// CHECK-NEXT: IntegerLiteral{{.*}}4{{$}} +// CHECK-NEXT: IntegerLiteral{{.*}}32{{$}} +// CHECK: FunctionDecl {{.*}} {{.*}}kernel_name6 +// CHECK: ReqdWorkGroupSizeAttr {{.*}} // CHECK-NEXT: IntegerLiteral{{.*}}32{{$}} // CHECK-NEXT: IntegerLiteral{{.*}}32{{$}} // CHECK-NEXT: IntegerLiteral{{.*}}32{{$}} diff --git a/clang/test/SemaSYCL/sycl-device-intel-max-work-group-size-template.cpp b/clang/test/SemaSYCL/sycl-device-intel-max-work-group-size-template.cpp index 16c6ed9b366a9..50cc361c19796 100644 --- a/clang/test/SemaSYCL/sycl-device-intel-max-work-group-size-template.cpp +++ b/clang/test/SemaSYCL/sycl-device-intel-max-work-group-size-template.cpp @@ -28,14 +28,10 @@ constexpr int bar() { return 0; } template class KernelFunctor { public: - // expected-warning@+1{{'max_work_group_size' attribute requires a non-negative integral compile time constant expression - attribute ignored}} [[intel::max_work_group_size(SIZE, SIZE1, SIZE2)]] void operator()() {} }; int main() { - //expected-note@+1{{in instantiation of template class 'KernelFunctor<-1, -1, -1>' requested here}} - KernelFunctor<-1, -1, -1>(); - // no error expected KernelFunctor<4, 4, 4>(); } diff --git a/clang/test/SemaSYCL/sycl-device-intel-reqd-work-group-size-template.cpp b/clang/test/SemaSYCL/sycl-device-intel-reqd-work-group-size-template.cpp index b09b841e44126..0e00286f9a287 100644 --- a/clang/test/SemaSYCL/sycl-device-intel-reqd-work-group-size-template.cpp +++ b/clang/test/SemaSYCL/sycl-device-intel-reqd-work-group-size-template.cpp @@ -28,14 +28,10 @@ constexpr int bar() { return 0; } template class KernelFunctor { public: - // expected-warning@+1{{'reqd_work_group_size' attribute requires a non-negative integral compile time constant expression - attribute ignored}} [[intel::reqd_work_group_size(SIZE, SIZE1, SIZE2)]] void operator()() {} }; int main() { - //expected-note@+1{{in instantiation of template class 'KernelFunctor<-1, -1, -1>' requested here}} - KernelFunctor<-1, -1, -1>(); - // no error expected KernelFunctor<16, 1, 1>(); } diff --git a/clang/test/SemaSYCL/sycl-device-reqd-work-group-size-template.cpp b/clang/test/SemaSYCL/sycl-device-reqd-work-group-size-template.cpp index 03ec14bdbbefb..f46e40933b59f 100644 --- a/clang/test/SemaSYCL/sycl-device-reqd-work-group-size-template.cpp +++ b/clang/test/SemaSYCL/sycl-device-reqd-work-group-size-template.cpp @@ -28,14 +28,10 @@ constexpr int bar() { return 0; } template class KernelFunctor { public: - // expected-warning@+1{{'reqd_work_group_size' attribute requires a non-negative integral compile time constant expression - attribute ignored}} [[cl::reqd_work_group_size(SIZE, SIZE1, SIZE2)]] void operator()() {} }; int main() { - //expected-note@+1{{in instantiation of template class 'KernelFunctor<-1, -1, -1>' requested here}} - KernelFunctor<-1, -1, -1>(); - // no error expected KernelFunctor<16, 1, 1>(); } From 4ead54f26b9ee01214e044113dbdf9af5f7a9e73 Mon Sep 17 00:00:00 2001 From: Soumi Manna Date: Wed, 23 Dec 2020 13:11:16 -0800 Subject: [PATCH 18/21] Fix error Signed-off-by: Soumi Manna --- clang/lib/Sema/SemaDeclAttr.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 5a5a717a5b78a..c1f2771426a7f 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -3041,7 +3041,8 @@ static bool handleMaxWorkSizeAttrExpr(Sema &S, const AttrInfo &AI, if (ArgVal->isNegative()) { S.Diag(getAttrLoc(AI), - diag::warn_attribute_requires_non_negative_integer_argument) << &AI; + diag::warn_attribute_requires_non_negative_integer_argument) + << &AI; return true; } From 0ac937ca9aacfd085e770ad42154f3a0d7cd2dad Mon Sep 17 00:00:00 2001 From: Soumi Manna Date: Thu, 24 Dec 2020 03:20:26 -0800 Subject: [PATCH 19/21] address review comments Signed-off-by: Soumi Manna --- clang/include/clang/Basic/DiagnosticSemaKinds.td | 3 ++- clang/lib/Sema/SemaDeclAttr.cpp | 4 ++-- clang/test/SemaOpenCL/invalid-kernel-attrs.cl | 2 +- clang/test/SemaSYCL/intel-max-work-group-size-device.cpp | 6 +++--- clang/test/SemaSYCL/intel-reqd-work-group-size-device.cpp | 2 +- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 362149229a681..a5067b63e8fb1 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -11208,7 +11208,8 @@ def warn_attribute_spelling_deprecated : Warning< def note_spelling_suggestion : Note< "did you mean to use %0 instead?">; def warn_attribute_requires_non_negative_integer_argument : Warning< - "%0 attribute requires a non-negative integral compile time constant expression">, + "the resulting value of the %0 attribute parameter %1 is always non-negative" + " after implicit conversion">, InGroup; // errors of expect.with.probability diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index c1f2771426a7f..b8584ef9dc1cf 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -3040,9 +3040,9 @@ static bool handleMaxWorkSizeAttrExpr(Sema &S, const AttrInfo &AI, } if (ArgVal->isNegative()) { - S.Diag(getAttrLoc(AI), + S.Diag(Expr->getExprLoc(), diag::warn_attribute_requires_non_negative_integer_argument) - << &AI; + << &AI << Idx << Expr->getSourceRange(); return true; } diff --git a/clang/test/SemaOpenCL/invalid-kernel-attrs.cl b/clang/test/SemaOpenCL/invalid-kernel-attrs.cl index 92f8ca18df69c..89ff872df67c9 100644 --- a/clang/test/SemaOpenCL/invalid-kernel-attrs.cl +++ b/clang/test/SemaOpenCL/invalid-kernel-attrs.cl @@ -42,7 +42,7 @@ kernel __attribute__((intel_reqd_sub_group_size(-1))) void kernel16() {} // expe kernel __attribute__((intel_reqd_sub_group_size(8))) __attribute__((intel_reqd_sub_group_size(16))) void kernel17() {} //expected-warning{{attribute 'intel_reqd_sub_group_size' is already applied with different parameters}} __kernel __attribute__((work_group_size_hint(8,-16,32))) void neg1() {} //expected-error{{'work_group_size_hint' attribute requires a non-negative integral compile time constant expression}} -__kernel __attribute__((reqd_work_group_size(8, 16, -32))) void neg2() {} //expected-warning{{'reqd_work_group_size' attribute requires a non-negative integral compile time constant expression}} +__kernel __attribute__((reqd_work_group_size(8, 16, -32))) void neg2() {} //expected-warning{{the resulting value of the 'reqd_work_group_size' attribute parameter 2 is always non-negative after implicit conversion}} // 4294967294 is a negative integer if treated as signed. // Should compile successfully, since we expect an unsigned. diff --git a/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp b/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp index cc6361765f46f..1c8fe52553319 100644 --- a/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp +++ b/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp @@ -71,13 +71,13 @@ int main() { // CHECK-LABEL: FunctionDecl {{.*}}test_kernel4 // CHECK: SYCLIntelMaxWorkGroupSizeAttr {{.*}} - // CHECK-NEXT: IntegerLiteral{{.*}}1{{$}} + // CHECK-NEXT: IntegerLiteral{{.*}}8{{$}} // CHECK-NEXT: IntegerLiteral{{.*}}8{{$}} // CHECK-NEXT: UnaryOperator{{.*}} 'int' prefix '-' // CHECK-NEXT: IntegerLiteral{{.*}}8{{$}} - // expected-warning@+2{{'max_work_group_size' attribute requires a non-negative integral compile time constant expression}} + // expected-warning@+2{{the resulting value of the 'max_work_group_size' attribute parameter 2 is always non-negative after implicit conversion}} h.single_task( - []() [[intel::max_work_group_size(-8, 8, 1)]]{}); + []() [[intel::max_work_group_size(-8, 8, 8)]]{}); #ifdef TRIGGER_ERROR [[intel::max_work_group_size(1, 1, 1)]] int Var = 0; // expected-error{{'max_work_group_size' attribute only applies to functions}} diff --git a/clang/test/SemaSYCL/intel-reqd-work-group-size-device.cpp b/clang/test/SemaSYCL/intel-reqd-work-group-size-device.cpp index 1b29afff3547e..639eb9d2ce506 100644 --- a/clang/test/SemaSYCL/intel-reqd-work-group-size-device.cpp +++ b/clang/test/SemaSYCL/intel-reqd-work-group-size-device.cpp @@ -40,7 +40,7 @@ class Functor32 { class Functor33 { public: - // expected-warning@+1{{'reqd_work_group_size' attribute requires a non-negative integral compile time constant expression}} + // expected-warning@+1{{the resulting value of the 'reqd_work_group_size' attribute parameter 1 is always non-negative after implicit conversion}} [[intel::reqd_work_group_size(32, -4)]] void operator()() const {} }; From 71edf5f1ddf4977e9aa848ac17564a8a513f323a Mon Sep 17 00:00:00 2001 From: Soumi Manna Date: Thu, 24 Dec 2020 03:24:32 -0800 Subject: [PATCH 20/21] Remove extra space from test Signed-off-by: Soumi Manna --- clang/test/SemaOpenCL/invalid-kernel-attrs.cl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/clang/test/SemaOpenCL/invalid-kernel-attrs.cl b/clang/test/SemaOpenCL/invalid-kernel-attrs.cl index 89ff872df67c9..a2d13db534dc2 100644 --- a/clang/test/SemaOpenCL/invalid-kernel-attrs.cl +++ b/clang/test/SemaOpenCL/invalid-kernel-attrs.cl @@ -30,9 +30,9 @@ void f_kernel_image2d_t( kernel image2d_t image ) { // expected-error {{'kernel' int __kernel x; // expected-error {{'__kernel' attribute only applies to functions}} } -kernel __attribute__((reqd_work_group_size(1, 2, 0))) void kernel11() {} // expected-error {{'reqd_work_group_size' attribute must be greater than 0}} -kernel __attribute__((reqd_work_group_size(1, 0, 2))) void kernel12() {} // expected-error {{'reqd_work_group_size' attribute must be greater than 0}} -kernel __attribute__((reqd_work_group_size(0, 1, 2))) void kernel13() {} // expected-error {{'reqd_work_group_size' attribute must be greater than 0}} +kernel __attribute__((reqd_work_group_size(1,2,0))) void kernel11(){} // expected-error {{'reqd_work_group_size' attribute must be greater than 0}} +kernel __attribute__((reqd_work_group_size(1,0,2))) void kernel12(){} // expected-error {{'reqd_work_group_size' attribute must be greater than 0}} +kernel __attribute__((reqd_work_group_size(0,1,2))) void kernel13(){} // expected-error {{'reqd_work_group_size' attribute must be greater than 0}} __attribute__((intel_reqd_sub_group_size(8))) void kernel14(){} // expected-error {{attribute 'intel_reqd_sub_group_size' can only be applied to an OpenCL kernel}} kernel __attribute__((intel_reqd_sub_group_size(0))) void kernel15() {} // expected-error {{'intel_reqd_sub_group_size' attribute requires a positive integral compile time constant expression}} @@ -46,4 +46,4 @@ __kernel __attribute__((reqd_work_group_size(8, 16, -32))) void neg2() {} //expe // 4294967294 is a negative integer if treated as signed. // Should compile successfully, since we expect an unsigned. -__kernel __attribute__((reqd_work_group_size(8, 16, 4294967294))) void ok1() {} +__kernel __attribute__((reqd_work_group_size(8,16,4294967294))) void ok1(){} From 860b753b9f46e4e6189e8e5d4df3bfd993f69f46 Mon Sep 17 00:00:00 2001 From: Soumi Manna Date: Thu, 24 Dec 2020 04:53:57 -0800 Subject: [PATCH 21/21] Reword of diagnostic message Signed-off-by: Soumi Manna --- clang/include/clang/Basic/DiagnosticSemaKinds.td | 4 ++-- clang/test/SemaOpenCL/invalid-kernel-attrs.cl | 2 +- clang/test/SemaSYCL/intel-max-work-group-size-device.cpp | 6 +++--- clang/test/SemaSYCL/intel-reqd-work-group-size-device.cpp | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index a5067b63e8fb1..fed2ea93d2223 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -11208,8 +11208,8 @@ def warn_attribute_spelling_deprecated : Warning< def note_spelling_suggestion : Note< "did you mean to use %0 instead?">; def warn_attribute_requires_non_negative_integer_argument : Warning< - "the resulting value of the %0 attribute parameter %1 is always non-negative" - " after implicit conversion">, + "the resulting value of the %0 attribute %select{first|second|third}1" + " parameter is always non-negative after implicit conversion">, InGroup; // errors of expect.with.probability diff --git a/clang/test/SemaOpenCL/invalid-kernel-attrs.cl b/clang/test/SemaOpenCL/invalid-kernel-attrs.cl index a2d13db534dc2..fef0d59e4b656 100644 --- a/clang/test/SemaOpenCL/invalid-kernel-attrs.cl +++ b/clang/test/SemaOpenCL/invalid-kernel-attrs.cl @@ -42,7 +42,7 @@ kernel __attribute__((intel_reqd_sub_group_size(-1))) void kernel16() {} // expe kernel __attribute__((intel_reqd_sub_group_size(8))) __attribute__((intel_reqd_sub_group_size(16))) void kernel17() {} //expected-warning{{attribute 'intel_reqd_sub_group_size' is already applied with different parameters}} __kernel __attribute__((work_group_size_hint(8,-16,32))) void neg1() {} //expected-error{{'work_group_size_hint' attribute requires a non-negative integral compile time constant expression}} -__kernel __attribute__((reqd_work_group_size(8, 16, -32))) void neg2() {} //expected-warning{{the resulting value of the 'reqd_work_group_size' attribute parameter 2 is always non-negative after implicit conversion}} +__kernel __attribute__((reqd_work_group_size(8, 16, -32))) void neg2() {} //expected-warning{{the resulting value of the 'reqd_work_group_size' attribute third parameter is always non-negative after implicit conversion}} // 4294967294 is a negative integer if treated as signed. // Should compile successfully, since we expect an unsigned. diff --git a/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp b/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp index 1c8fe52553319..779b85b10cdaa 100644 --- a/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp +++ b/clang/test/SemaSYCL/intel-max-work-group-size-device.cpp @@ -71,13 +71,13 @@ int main() { // CHECK-LABEL: FunctionDecl {{.*}}test_kernel4 // CHECK: SYCLIntelMaxWorkGroupSizeAttr {{.*}} + // CHECK-NEXT: UnaryOperator{{.*}} 'int' prefix '-' // CHECK-NEXT: IntegerLiteral{{.*}}8{{$}} // CHECK-NEXT: IntegerLiteral{{.*}}8{{$}} - // CHECK-NEXT: UnaryOperator{{.*}} 'int' prefix '-' // CHECK-NEXT: IntegerLiteral{{.*}}8{{$}} - // expected-warning@+2{{the resulting value of the 'max_work_group_size' attribute parameter 2 is always non-negative after implicit conversion}} + // expected-warning@+2{{the resulting value of the 'max_work_group_size' attribute first parameter is always non-negative after implicit conversion}} h.single_task( - []() [[intel::max_work_group_size(-8, 8, 8)]]{}); + []() [[intel::max_work_group_size(8, 8, -8)]]{}); #ifdef TRIGGER_ERROR [[intel::max_work_group_size(1, 1, 1)]] int Var = 0; // expected-error{{'max_work_group_size' attribute only applies to functions}} diff --git a/clang/test/SemaSYCL/intel-reqd-work-group-size-device.cpp b/clang/test/SemaSYCL/intel-reqd-work-group-size-device.cpp index 639eb9d2ce506..5e7e9fe900944 100644 --- a/clang/test/SemaSYCL/intel-reqd-work-group-size-device.cpp +++ b/clang/test/SemaSYCL/intel-reqd-work-group-size-device.cpp @@ -40,7 +40,7 @@ class Functor32 { class Functor33 { public: - // expected-warning@+1{{the resulting value of the 'reqd_work_group_size' attribute parameter 1 is always non-negative after implicit conversion}} + // expected-warning@+1{{the resulting value of the 'reqd_work_group_size' attribute second parameter is always non-negative after implicit conversion}} [[intel::reqd_work_group_size(32, -4)]] void operator()() const {} };