diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index c6d8acadb8a64..20cdcd394c8f0 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -2895,7 +2895,7 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &Attr, if (const auto *A = D->getAttr()) if (A->getNumber() == 0) Result &= checkZeroDim(A, WGSize[0], WGSize[1], WGSize[2], - /*ReverseAttrs=*/ true); + /*ReverseAttrs=*/true); if (const auto *A = D->getAttr()) { if (!(WGSize[0] <= A->getXDim() && WGSize[1] <= A->getYDim() && @@ -2935,14 +2935,17 @@ static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) { } } - if (!checkWorkGroupSizeValues(S, D, AL, WGSize)) - return; - + // For a SYCLDevice WorkGroupAttr arguments are reversed + if (S.getLangOpts().SYCLIsDevice) { + std::swap(WGSize[0], WGSize[2]); + } WorkGroupAttr *Existing = D->getAttr(); - if (Existing && !(Existing->getXDim() == WGSize[0] && - Existing->getYDim() == WGSize[1] && - Existing->getZDim() == WGSize[2])) + 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])); diff --git a/clang/test/CodeGenSYCL/reqd-work-group-size.cpp b/clang/test/CodeGenSYCL/reqd-work-group-size.cpp index 5fd4f6a84358e..896cb2d997784 100644 --- a/clang/test/CodeGenSYCL/reqd-work-group-size.cpp +++ b/clang/test/CodeGenSYCL/reqd-work-group-size.cpp @@ -27,13 +27,12 @@ void bar() { kernel(f); kernel( - []() [[cl::reqd_work_group_size(8, 8, 8)]] {}); + []() [[cl::reqd_work_group_size(8, 8, 8)]]{}); } // 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: ![[WGSIZE32]] = !{i32 32, i32 16, i32 16} -// CHECK: ![[WGSIZE8]] = !{i32 8, i32 1, i32 1} +// CHECK: ![[WGSIZE32]] = !{i32 16, i32 16, i32 32} +// CHECK: ![[WGSIZE8]] = !{i32 1, i32 1, i32 8} // CHECK: ![[WGSIZE88]] = !{i32 8, i32 8, i32 8} - diff --git a/clang/test/CodeGenSYCL/sycl-multi-kernel-attr.cpp b/clang/test/CodeGenSYCL/sycl-multi-kernel-attr.cpp index 7b1ce6921e105..f0072c196ea53 100644 --- a/clang/test/CodeGenSYCL/sycl-multi-kernel-attr.cpp +++ b/clang/test/CodeGenSYCL/sycl-multi-kernel-attr.cpp @@ -17,5 +17,5 @@ void bar() { } // CHECK: define spir_kernel void @{{.*}}kernel_name() {{.*}} !reqd_work_group_size ![[WGSIZE:[0-9]+]] !intel_reqd_sub_group_size ![[SGSIZE:[0-9]+]] -// CHECK: ![[WGSIZE]] = !{i32 32, i32 16, i32 16} +// CHECK: ![[WGSIZE]] = !{i32 16, i32 16, i32 32} // CHECK: ![[SGSIZE]] = !{i32 4} diff --git a/clang/test/SemaSYCL/intel-max-global-work-dim.cpp b/clang/test/SemaSYCL/intel-max-global-work-dim.cpp index 26f43ef1a5f92..6b196c75331aa 100644 --- a/clang/test/SemaSYCL/intel-max-global-work-dim.cpp +++ b/clang/test/SemaSYCL/intel-max-global-work-dim.cpp @@ -82,8 +82,8 @@ int main() { kernel( TRIFuncObjGood2()); // CHECK-LABEL: FunctionDecl {{.*}} _ZTSZ4mainE12test_kernel5 - // CHECK: ReqdWorkGroupSizeAttr {{.*}} 4 1 1 - // CHECK: SYCLIntelMaxWorkGroupSizeAttr {{.*}} 8 1 1 + // CHECK: ReqdWorkGroupSizeAttr {{.*}} 1 1 4 + // CHECK: SYCLIntelMaxWorkGroupSizeAttr {{.*}} 1 1 8 // CHECK: SYCLIntelMaxGlobalWorkDimAttr {{.*}} 3 #ifdef TRIGGER_ERROR diff --git a/clang/test/SemaSYCL/reqd-work-group-size.cpp b/clang/test/SemaSYCL/reqd-work-group-size.cpp index d2336fa4ffcce..4daa3c08227a6 100644 --- a/clang/test/SemaSYCL/reqd-work-group-size.cpp +++ b/clang/test/SemaSYCL/reqd-work-group-size.cpp @@ -7,7 +7,6 @@ class Functor { public: [[cl::reqd_work_group_size(4, 1, 1)]] void operator()() {} - }; template @@ -24,17 +23,25 @@ void bar() { // expected-note@-1 {{conflicting attribute is here}} [[cl::reqd_work_group_size(32, 1, 1)]] void f32x1x1() {} // expected-note {{conflicting attribute is here}} -[[cl::reqd_work_group_size(16, 1, 1)]] void f16x1x1() {} // expected-note {{conflicting attribute is here}} +[[cl::reqd_work_group_size(16, 1, 1)]] void f16x1x1() {} // expected-note {{conflicting attribute is here}} [[cl::reqd_work_group_size(16, 16, 1)]] void f16x16x1() {} // expected-note {{conflicting attribute is here}} -[[cl::reqd_work_group_size(32, 32, 1)]] void f32x32x1() {} // expected-note {{conflicting attribute is here}} +[[cl::reqd_work_group_size(32, 32, 1)]] void f32x32x1() {} // expected-note {{conflicting attribute is here}} [[cl::reqd_work_group_size(32, 32, 32)]] void f32x32x32() {} // expected-note {{conflicting attribute is here}} class Functor16 { public: - [[cl::reqd_work_group_size(16, 1, 1)]] void operator()() {} + [[cl::reqd_work_group_size(16, 1, 1)]] [[cl::reqd_work_group_size(16, 1, 1)]] void operator()() {} }; +#ifdef TRIGGER_ERROR +class Functor32 { +public: + //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()() {} +}; +#endif class Functor16x16x16 { public: [[cl::reqd_work_group_size(16, 16, 16)]] void operator()() {} @@ -42,7 +49,7 @@ class Functor16x16x16 { class Functor8 { // expected-error {{conflicting attributes applied to a SYCL kernel}} public: - [[cl::reqd_work_group_size(8, 1, 1)]] void operator()() { // expected-note {{conflicting attribute is here}} + [[cl::reqd_work_group_size(1, 1, 8)]] void operator()() { // expected-note {{conflicting attribute is here}} f4x1x1(); } }; @@ -77,15 +84,17 @@ void bar() { FunctorAttr fattr; kernel(fattr); - kernel([]() [[cl::reqd_work_group_size(32, 32, 32)]] { - f32x32x32(); + kernel([]() [[cl::reqd_work_group_size(32, 32, 32), cl::reqd_work_group_size(32, 32, 32)]] { + f32x32x32(); }); - #ifdef TRIGGER_ERROR Functor8 f8; kernel(f8); + Functor32 f32; + kernel(f32); + kernel([]() { // expected-error {{conflicting attributes applied to a SYCL kernel}} f4x1x1(); f32x1x1(); @@ -102,7 +111,7 @@ void bar() { }); // expected-error@+1 {{expected variable name or 'this' in lambda capture list}} - kernel([[cl::reqd_work_group_size(32, 32, 32)]] []() { + kernel([[cl::reqd_work_group_size(32, 32, 32)]][]() { f32x32x32(); }); @@ -110,9 +119,9 @@ void bar() { } // CHECK: FunctionDecl {{.*}} {{.*}}kernel_name1 -// CHECK: ReqdWorkGroupSizeAttr {{.*}} 16 1 1 +// CHECK: ReqdWorkGroupSizeAttr {{.*}} 1 1 16 // CHECK: FunctionDecl {{.*}} {{.*}}kernel_name2 -// CHECK: ReqdWorkGroupSizeAttr {{.*}} 4 1 1 +// CHECK: ReqdWorkGroupSizeAttr {{.*}} 1 1 4 // CHECK: FunctionDecl {{.*}} {{.*}}kernel_name3 // CHECK: ReqdWorkGroupSizeAttr {{.*}} 16 16 16 // CHECK: FunctionDecl {{.*}} {{.*}}kernel_name4