From 845ff48268e0c228af3b3503bcab4276fb90c155 Mon Sep 17 00:00:00 2001 From: Elizabeth Andrews Date: Mon, 1 Feb 2021 12:21:31 -0800 Subject: [PATCH] [SYCL] Remove arbitrary range Part 1 Remove arbitrary range for SYCLIntelSchedulerTargetFmaxMhz and SYCLIntelLoopFuse attributes. Signed-off-by: Elizabeth Andrews --- clang/include/clang/Basic/Attr.td | 16 ---------------- clang/include/clang/Sema/Sema.h | 7 +++++++ clang/lib/Sema/SemaDeclAttr.cpp | 12 ++++++++---- clang/test/SemaSYCL/loop_fusion.cpp | 7 ++++--- .../test/SemaSYCL/scheduler_target_fmax_mhz.cpp | 12 ++++-------- 5 files changed, 23 insertions(+), 31 deletions(-) diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index ead6e7952b80c..a62a80518c1f6 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -1269,14 +1269,6 @@ def SYCLIntelSchedulerTargetFmaxMhz : InheritableAttr { let LangOpts = [SYCLIsDevice, SYCLIsHost]; let Subjects = SubjectList<[Function], ErrorDiag>; let Documentation = [SYCLIntelSchedulerTargetFmaxMhzAttrDocs]; - let AdditionalMembers = [{ - static unsigned getMinValue() { - return 0; - } - static unsigned getMaxValue() { - return 1024*1024; - } - }]; } def SYCLIntelMaxWorkGroupSize : InheritableAttr { @@ -1331,14 +1323,6 @@ def SYCLIntelLoopFuse : InheritableAttr { let Accessors = [Accessor<"isIndependent", [CXX11<"intel", "loop_fuse_independent">]>]; let Documentation = [SYCLIntelLoopFuseDocs]; - let AdditionalMembers = [{ - static unsigned getMinValue() { - return 0; - } - static unsigned getMaxValue() { - return 1024*1024; - } - }]; } def C11NoReturn : InheritableAttr { diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index faa6af40ebe87..7dfb77fede0ee 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -12970,6 +12970,13 @@ void Sema::addIntelSYCLSingleArgFunctionAttr(Decl *D, return; } } + if (CI.getParsedKind() == ParsedAttr::AT_SYCLIntelSchedulerTargetFmaxMhz) { + if (ArgInt < 0) { + Diag(E->getExprLoc(), diag::err_attribute_requires_positive_integer) + << CI.getAttrName() << /*non-negative*/ 1; + return; + } + } } D->addAttr(::new (Context) AttrType(Context, CI, E)); diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 6851053a96e75..33497e83ebc39 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -3210,7 +3210,8 @@ static void handleSchedulerTargetFmaxMhzAttr(Sema &S, Decl *D, S.Diag(AL.getLoc(), diag::note_spelling_suggestion) << "'intel::scheduler_target_fmax_mhz'"; - S.AddOneConstantValueAttr(D, AL, E); + S.addIntelSYCLSingleArgFunctionAttr( + D, AL, E); } // Handles max_global_work_dim. @@ -3287,10 +3288,13 @@ static bool checkSYCLIntelLoopFuseArgument(Sema &S, return true; } - SYCLIntelLoopFuseAttr TmpAttr(S.Context, CI, E); - ExprResult ICE; + if (!ArgVal->isNonNegative()) { + S.Diag(E->getExprLoc(), diag::err_attribute_requires_positive_integer) + << CI << /*non-negative*/ 1; + return true; + } - return S.checkRangedIntegralArgument(E, &TmpAttr, ICE); + return false; } void Sema::addSYCLIntelLoopFuseAttr(Decl *D, const AttributeCommonInfo &CI, diff --git a/clang/test/SemaSYCL/loop_fusion.cpp b/clang/test/SemaSYCL/loop_fusion.cpp index 389b3f3d98317..e92b7c99110db 100644 --- a/clang/test/SemaSYCL/loop_fusion.cpp +++ b/clang/test/SemaSYCL/loop_fusion.cpp @@ -4,8 +4,8 @@ [[intel::loop_fuse("foo")]] void func() {} // expected-error{{'loop_fuse' attribute requires an integer constant}} -[[intel::loop_fuse(1048577)]] void func1() {} // expected-error{{'loop_fuse' attribute requires integer constant between 0 and 1048576 inclusive}} -[[intel::loop_fuse_independent(-1)]] void func2() {} // expected-error{{'loop_fuse_independent' attribute requires integer constant between 0 and 1048576 inclusive}} +[[intel::loop_fuse(1048577)]] void func1() {} // OK +[[intel::loop_fuse_independent(-1)]] void func2() {} // expected-error{{'loop_fuse_independent' attribute requires a non-negative integral compile time constant expression}} [[intel::loop_fuse(0, 1)]] void func3() {} // expected-error{{'loop_fuse' attribute takes no more than 1 argument}} [[intel::loop_fuse_independent(2, 3)]] void func4() {} // expected-error{{'loop_fuse_independent' attribute takes no more than 1 argument}} @@ -48,13 +48,14 @@ [[intel::loop_fuse]] void func16(); template -[[intel::loop_fuse(N)]] void func17(); // expected-error{{'loop_fuse' attribute requires integer constant between 0 and 1048576 inclusive}} +[[intel::loop_fuse(N)]] void func17(); // expected-error{{'loop_fuse' attribute requires a non-negative integral compile time constant expression}} template [[intel::loop_fuse(Ty{})]] void func18() {} // expected-error{{'loop_fuse' attribute requires an integer constant}} void checkTemplates() { func17<-1>(); // expected-note{{in instantiation of}} + func17<0>(); // OK func18(); // expected-note{{in instantiation of}} } diff --git a/clang/test/SemaSYCL/scheduler_target_fmax_mhz.cpp b/clang/test/SemaSYCL/scheduler_target_fmax_mhz.cpp index d0203e41447d6..379cf57d7b23c 100644 --- a/clang/test/SemaSYCL/scheduler_target_fmax_mhz.cpp +++ b/clang/test/SemaSYCL/scheduler_target_fmax_mhz.cpp @@ -10,20 +10,16 @@ template [[intel::scheduler_target_fmax_mhz(N)]] void zoo() {} int main() { - // CHECK-LABEL: FunctionDecl {{.*}}test_kernel1 'void ()' + // CHECK: FunctionDecl {{.*}}test_kernel1 'void ()' // CHECK: SYCLIntelSchedulerTargetFmaxMhzAttr {{.*}} - // CHECK-NEXT: ConstantExpr {{.*}} 'int' - // CHECK-NEXT: value: Int 5 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 5 // expected-warning@+3 {{attribute 'intelfpga::scheduler_target_fmax_mhz' is deprecated}} // expected-note@+2 {{did you mean to use 'intel::scheduler_target_fmax_mhz' instead?}} cl::sycl::kernel_single_task( []() [[intelfpga::scheduler_target_fmax_mhz(5)]]{}); - // CHECK-LABEL: FunctionDecl {{.*}}test_kernel2 'void ()' + // CHECK: FunctionDecl {{.*}}test_kernel2 'void ()' // CHECK: SYCLIntelSchedulerTargetFmaxMhzAttr {{.*}} - // CHECK-NEXT: ConstantExpr {{.*}} 'int' - // CHECK-NEXT: value: Int 2 // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 2 cl::sycl::kernel_single_task( []() { func(); }); @@ -39,10 +35,10 @@ int main() { [[intel::scheduler_target_fmax_mhz(0)]] int Var = 0; // expected-error{{'scheduler_target_fmax_mhz' attribute only applies to functions}} cl::sycl::kernel_single_task( - []() [[intel::scheduler_target_fmax_mhz(1048577)]]{}); // expected-error{{'scheduler_target_fmax_mhz' attribute requires integer constant between 0 and 1048576 inclusive}} + []() [[intel::scheduler_target_fmax_mhz(1048577)]]{}); // OK cl::sycl::kernel_single_task( - []() [[intel::scheduler_target_fmax_mhz(-4)]]{}); // expected-error{{'scheduler_target_fmax_mhz' attribute requires integer constant between 0 and 1048576 inclusive}} + []() [[intel::scheduler_target_fmax_mhz(-4)]]{}); // expected-error{{'scheduler_target_fmax_mhz' attribute requires a non-negative integral compile time constant expression}} cl::sycl::kernel_single_task( []() [[intel::scheduler_target_fmax_mhz(1), intel::scheduler_target_fmax_mhz(2)]]{}); // expected-warning{{attribute 'scheduler_target_fmax_mhz' is already applied with different parameters}}