Skip to content

Commit

Permalink
Merge from 'sycl' to 'sycl-web' (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
iclsrc committed Jan 22, 2021
2 parents 3ccc691 + 1040b94 commit 94660ed
Show file tree
Hide file tree
Showing 11 changed files with 524 additions and 92 deletions.
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -11197,7 +11197,7 @@ def err_sycl_function_attribute_mismatch : Error<
"SYCL kernel without %0 attribute can't call a function with this attribute">;
def err_sycl_x_y_z_arguments_must_be_one : Error<
"%0 X-, Y- and Z- sizes must be 1 when %1 attribute is used with value 0">;
def err_sycl_attibute_cannot_be_applied_here
def err_sycl_attribute_internal_function
: Error<"%0 attribute cannot be applied to a "
"static function or function in an anonymous namespace">;
def err_sycl_compiletime_property_duplication : Error<
Expand Down
9 changes: 2 additions & 7 deletions clang/lib/Sema/SemaDeclAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4833,7 +4833,7 @@ static void handleOptimizeNoneAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
static void handleSYCLDeviceAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
auto *FD = cast<FunctionDecl>(D);
if (!FD->isExternallyVisible()) {
S.Diag(AL.getLoc(), diag::err_sycl_attibute_cannot_be_applied_here) << AL;
S.Diag(AL.getLoc(), diag::err_sycl_attribute_internal_function) << AL;
return;
}

Expand All @@ -4844,7 +4844,7 @@ static void handleSYCLDeviceIndirectlyCallableAttr(Sema &S, Decl *D,
const ParsedAttr &AL) {
auto *FD = cast<FunctionDecl>(D);
if (!FD->isExternallyVisible()) {
S.Diag(AL.getLoc(), diag::err_sycl_attibute_cannot_be_applied_here) << AL;
S.Diag(AL.getLoc(), diag::err_sycl_attribute_internal_function) << AL;
return;
}

Expand All @@ -4854,11 +4854,6 @@ static void handleSYCLDeviceIndirectlyCallableAttr(Sema &S, Decl *D,

static void handleSYCLRegisterNumAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
auto *VD = cast<VarDecl>(D);
if (!VD->hasGlobalStorage()) {
S.Diag(AL.getLoc(), diag::err_sycl_attibute_cannot_be_applied_here)
<< AL << 0;
return;
}
if (!checkAttributeNumArgs(S, AL, 1))
return;
uint32_t RegNo = 0;
Expand Down
12 changes: 0 additions & 12 deletions clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,20 +178,8 @@ static bool IsSyclMathFunc(unsigned BuiltinID) {
case Builtin::BI__builtin_truncl:
case Builtin::BIlroundl:
case Builtin::BI__builtin_lroundl:
case Builtin::BIfmax:
case Builtin::BI__builtin_fmax:
case Builtin::BIfmin:
case Builtin::BI__builtin_fmin:
case Builtin::BIfmaxf:
case Builtin::BI__builtin_fmaxf:
case Builtin::BIfminf:
case Builtin::BI__builtin_fminf:
case Builtin::BIlroundf:
case Builtin::BI__builtin_lroundf:
case Builtin::BI__builtin_fpclassify:
case Builtin::BI__builtin_isfinite:
case Builtin::BI__builtin_isinf:
case Builtin::BI__builtin_isnormal:
return false;
default:
break;
Expand Down
83 changes: 50 additions & 33 deletions clang/test/SemaSYCL/supported_math.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsyntax-only -Wno-sycl-strict -verify %s
// expected-no-diagnostics
extern "C" float sinf(float);
extern "C" float cosf(float);
extern "C" float floorf(float);
Expand All @@ -8,6 +9,8 @@ extern "C" float rintf(float);
extern "C" float roundf(float);
extern "C" float truncf(float);
extern "C" float copysignf(float, float);
extern "C" float fminf(float, float);
extern "C" float fmaxf(float, float);
extern "C" double sin(double);
extern "C" double cos(double);
extern "C" double floor(double);
Expand All @@ -17,6 +20,8 @@ extern "C" double rint(double);
extern "C" double round(double);
extern "C" double trunc(double);
extern "C" double copysign(double, double);
extern "C" double fmin(double, double);
extern "C" double fmax(double, double);
template <typename name, typename Func>
__attribute__((sycl_kernel)) void kernel(const Func &kernelFunc) {
kernelFunc();
Expand All @@ -26,39 +31,51 @@ int main() {
kernel<class kernel_function>([=]() {
int acc[1] = {5};
acc[0] *= 2;
acc[0] += (int)truncf(1.0f); // expected-no-diagnostics
acc[0] += (int)trunc(1.0); // expected-no-diagnostics
acc[0] += (int)roundf(1.0f); // expected-no-diagnostics
acc[0] += (int)round(1.0); // expected-no-diagnostics
acc[0] += (int)rintf(1.0f); // expected-no-diagnostics
acc[0] += (int)rint(1.0); // expected-no-diagnostics
acc[0] += (int)nearbyintf(0.5f); // expected-no-diagnostics
acc[0] += (int)nearbyint(0.5); // expected-no-diagnostics
acc[0] += (int)floorf(0.5f); // expected-no-diagnostics
acc[0] += (int)floor(0.5); // expected-no-diagnostics
acc[0] += (int)copysignf(1.0f, -0.5f); // expected-no-diagnostics
acc[0] += (int)copysign(1.0, -0.5); // expected-no-diagnostics
acc[0] += (int)sinf(1.0f); // expected-no-diagnostics
acc[0] += (int)sin(1.0); // expected-no-diagnostics
acc[0] += (int)__builtin_sinf(1.0f); // expected-no-diagnostics
acc[0] += (int)__builtin_sin(1.0); // expected-no-diagnostics
acc[0] += (int)cosf(1.0f); // expected-no-diagnostics
acc[0] += (int)cos(1.0); // expected-no-diagnostics
acc[0] += (int)__builtin_cosf(1.0f); // expected-no-diagnostics
acc[0] += (int)__builtin_cos(1.0); // expected-no-diagnostics
acc[0] += (int)logf(1.0f); // expected-no-diagnostics
acc[0] += (int)log(1.0); // expected-no-diagnostics
acc[0] += (int)__builtin_truncf(1.0f); // expected-no-diagnostics
acc[0] += (int)__builtin_trunc(1.0); // expected-no-diagnostics
acc[0] += (int)__builtin_rintf(1.0f); // expected-no-diagnostics
acc[0] += (int)__builtin_rint(1.0); // expected-no-diagnostics
acc[0] += (int)__builtin_nearbyintf(0.5f); // expected-no-diagnostics
acc[0] += (int)__builtin_nearbyint(0.5); // expected-no-diagnostics
acc[0] += (int)__builtin_floorf(0.5f); // expected-no-diagnostics
acc[0] += (int)__builtin_floor(0.5); // expected-no-diagnostics
acc[0] += (int)__builtin_copysignf(1.0f, -0.5f); // expected-no-diagnostics
acc[0] += (int)__builtin_logf(1.0f); // expected-no-diagnostics
acc[0] += (int)__builtin_log(1.0); // expected-no-diagnostics
acc[0] += (int)truncf(1.0f);
acc[0] += (int)trunc(1.0);
acc[0] += (int)roundf(1.0f);
acc[0] += (int)round(1.0);
acc[0] += (int)rintf(1.0f);
acc[0] += (int)rint(1.0);
acc[0] += (int)nearbyintf(0.5f);
acc[0] += (int)nearbyint(0.5);
acc[0] += (int)floorf(0.5f);
acc[0] += (int)floor(0.5);
acc[0] += (int)copysignf(1.0f, -0.5f);
acc[0] += (int)copysign(1.0, -0.5);
acc[0] += (int)fminf(1.5f, 0.5f);
acc[0] += (int)fmin(1.5, 0.5);
acc[0] += (int)fmaxf(1.5f, 0.5f);
acc[0] += (int)fmax(1.5, 0.5);
acc[0] += (int)sinf(1.0f);
acc[0] += (int)sin(1.0);
acc[0] += (int)__builtin_sinf(1.0f);
acc[0] += (int)__builtin_sin(1.0);
acc[0] += (int)cosf(1.0f);
acc[0] += (int)cos(1.0);
acc[0] += (int)__builtin_cosf(1.0f);
acc[0] += (int)__builtin_cos(1.0);
acc[0] += (int)logf(1.0f);
acc[0] += (int)log(1.0);
acc[0] += (int)__builtin_truncf(1.0f);
acc[0] += (int)__builtin_trunc(1.0);
acc[0] += (int)__builtin_rintf(1.0f);
acc[0] += (int)__builtin_rint(1.0);
acc[0] += (int)__builtin_nearbyintf(0.5f);
acc[0] += (int)__builtin_nearbyint(0.5);
acc[0] += (int)__builtin_floorf(0.5f);
acc[0] += (int)__builtin_floor(0.5);
acc[0] += (int)__builtin_copysignf(1.0f, -0.5f);
acc[0] += (int)__builtin_fminf(1.5f, 0.5f);
acc[0] += (int)__builtin_fmin(1.5, 0.5);
acc[0] += (int)__builtin_fmaxf(1.5f, 0.5f);
acc[0] += (int)__builtin_fmax(1.5, 0.5);
acc[0] += (int)__builtin_logf(1.0f);
acc[0] += (int)__builtin_log(1.0);
acc[0] += __builtin_isinf(1.0);
acc[0] += __builtin_isfinite(1.0);
acc[0] += __builtin_isnormal(1.0);
acc[0] += __builtin_fpclassify(0, 1, 4, 3, 2, 1.0);
});
return 0;
}
36 changes: 36 additions & 0 deletions llvm/test/tools/sycl-post-link/ir-output-only.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
; RUN: sycl-post-link --ir-output-only -split=auto -S %s -o %t.ll
; RUN: FileCheck %s -input-file=%t.ll

; This test checks that the --ir-output-only option writes a LLVM IR
; file instead of a table. In comparison with other tests, this one
; checks that the option works OK with -split=auto.

target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
target triple = "spir64-unknown-linux-sycldevice"

declare dso_local spir_func i64 @_Z28__spirv_GlobalInvocationId_xv()

define dso_local spir_kernel void @kernel1() #0 {
entry:
%call = tail call spir_func i64 @_Z28__spirv_GlobalInvocationId_xv()
ret void
}

define dso_local spir_kernel void @kernel2() #0 {
entry:
%call = tail call spir_func i64 @_Z28__spirv_GlobalInvocationId_xv()
ret void
}

attributes #0 = { "sycl-module-id"="a.cpp" }

!llvm.module.flags = !{!0}
!opencl.spir.version = !{!1}
!spirv.Source = !{!2}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 1, i32 2}
!2 = !{i32 0, i32 100000}

; CHECK: define dso_local spir_kernel void @kernel1()
; CHECK: define dso_local spir_kernel void @kernel2()
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
; RUN: sycl-post-link -split-esimd -S %s -o %t.table
; RUN: FileCheck %s -input-file=%t.table
; RUN: FileCheck %s -input-file=%t_0.ll --check-prefixes CHECK-SYCL-IR
; RUN: FileCheck %s -input-file=%t_esimd_0.ll --check-prefixes CHECK-ESIMD-IR

; This is basic test of splitting SYCL and ESIMD kernels into separate
; modules.

target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
target triple = "spir64-unknown-linux-sycldevice"

declare dso_local spir_func i64 @_Z28__spirv_GlobalInvocationId_xv()

define dso_local spir_kernel void @ESIMD_kernel() #0 !sycl_explicit_simd !3{
entry:
%call = tail call spir_func i64 @_Z28__spirv_GlobalInvocationId_xv()
ret void
}

define dso_local spir_kernel void @SYCL_kernel() #0 {
entry:
%call = tail call spir_func i64 @_Z28__spirv_GlobalInvocationId_xv()
ret void
}

attributes #0 = { "sycl-module-id"="a.cpp" }

!llvm.module.flags = !{!0}
!opencl.spir.version = !{!1}
!spirv.Source = !{!2}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 1, i32 2}
!2 = !{i32 0, i32 100000}
!3 = !{}

; CHECK: [Code|Properties]
; CHECK: {{.*}}_0.ll|{{.*}}_0.prop
; CHECK: {{.*}}_esimd_0.ll|{{.*}}_esimd_0.prop

; CHECK-SYCL-IR-DAG: define dso_local spir_kernel void @SYCL_kernel()
; CHECK-SYCL-IR-DAG: declare dso_local spir_func i64 @_Z28__spirv_GlobalInvocationId_xv()

; CHECK-ESIMD-IR-DAG: define dso_local spir_kernel void @ESIMD_kernel()
; CHECK-ESIMD-IR-DAG: declare dso_local spir_func i64 @_Z28__spirv_GlobalInvocationId_xv()
55 changes: 55 additions & 0 deletions llvm/test/tools/sycl-post-link/sycl-esimd/no-sycl-esimd-split.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
; RUN: sycl-post-link -split=source -S %s -o %t.table
; RUN: FileCheck %s -input-file=%t.table
; RUN: FileCheck %s -input-file=%t_0.ll --check-prefixes CHECK-IR-0
; RUN: FileCheck %s -input-file=%t_1.ll --check-prefixes CHECK-IR-1

; This test checks that if no '-split-esimd' provided, ther is no
; splitting of SYCL and ESIMD kernels into separate modules.
; However, the rest of the splitting still happens according to
; the '-split=' option.

target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
target triple = "spir64-unknown-linux-sycldevice"

declare dso_local spir_func i64 @_Z28__spirv_GlobalInvocationId_xv()

define dso_local spir_kernel void @ESIMD_kernel() #0 !sycl_explicit_simd !3{
entry:
%call = tail call spir_func i64 @_Z28__spirv_GlobalInvocationId_xv()
ret void
}

define dso_local spir_kernel void @SYCL_kernel1() #0 {
entry:
%call = tail call spir_func i64 @_Z28__spirv_GlobalInvocationId_xv()
ret void
}

define dso_local spir_kernel void @SYCL_kernel2() #1 {
entry:
%call = tail call spir_func i64 @_Z28__spirv_GlobalInvocationId_xv()
ret void
}

attributes #0 = { "sycl-module-id"="a.cpp" }
attributes #1 = { "sycl-module-id"="b.cpp" }

!llvm.module.flags = !{!0}
!opencl.spir.version = !{!1}
!spirv.Source = !{!2}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 1, i32 2}
!2 = !{i32 0, i32 100000}
!3 = !{}

; CHECK: [Code|Properties]
; CHECK: {{.*}}_0.ll|{{.*}}_0.prop
; CHECK: {{.*}}_1.ll|{{.*}}_1.prop

; CHECK-IR-0-DAG: define dso_local spir_kernel void @SYCL_kernel1()
; CHECK-IR-0-DAG: define dso_local spir_kernel void @ESIMD_kernel()
; CHECK-IR-0-DAG: declare dso_local spir_func i64 @_Z28__spirv_GlobalInvocationId_xv()

; CHECK-IR-1-DAG: define dso_local spir_kernel void @SYCL_kernel2()
; CHECK-IR-1-DAG: declare dso_local spir_func i64 @_Z28__spirv_GlobalInvocationId_xv()
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
; RUN: sycl-post-link -split-esimd -split=kernel -S %s -o %t.table
; RUN: FileCheck %s -input-file=%t.table
; RUN: FileCheck %s -input-file=%t_0.ll --check-prefixes CHECK-SYCL-IR-0
; RUN: FileCheck %s -input-file=%t_1.ll --check-prefixes CHECK-SYCL-IR-1
; RUN: FileCheck %s -input-file=%t_esimd_0.ll --check-prefixes CHECK-ESIMD-IR-0
; RUN: FileCheck %s -input-file=%t_esimd_1.ll --check-prefixes CHECK-ESIMD-IR-1

; This test checks that after we split SYCL and ESIMD kernels into
; separate modules, we split those two modules further according to
; -split option. In this case we have 2 SYCL and 2 ESIMD kernels, which
; are split into a total of 4 separate modules.

target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
target triple = "spir64-unknown-linux-sycldevice"

declare dso_local spir_func i64 @_Z28__spirv_GlobalInvocationId_xv()

define dso_local spir_kernel void @ESIMD_kernel1() #0 !sycl_explicit_simd !3{
entry:
%call = tail call spir_func i64 @_Z28__spirv_GlobalInvocationId_xv()
ret void
}

define dso_local spir_kernel void @ESIMD_kernel2() #0 !sycl_explicit_simd !3{
entry:
%call = tail call spir_func i64 @_Z28__spirv_GlobalInvocationId_xv()
ret void
}

define dso_local spir_kernel void @SYCL_kernel1() #1 {
entry:
%call = tail call spir_func i64 @_Z28__spirv_GlobalInvocationId_xv()
ret void
}

define dso_local spir_kernel void @SYCL_kernel2() #1 {
entry:
%call = tail call spir_func i64 @_Z28__spirv_GlobalInvocationId_xv()
ret void
}

attributes #0 = { "sycl-module-id"="a.cpp" }
attributes #1 = { "sycl-module-id"="a.cpp" }

!llvm.module.flags = !{!0}
!opencl.spir.version = !{!1}
!spirv.Source = !{!2}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 1, i32 2}
!2 = !{i32 0, i32 100000}
!3 = !{}

; CHECK: [Code|Properties]
; CHECK: {{.*}}_0.ll|{{.*}}_0.prop
; CHECK: {{.*}}_1.ll|{{.*}}_1.prop
; CHECK: {{.*}}_esimd_0.ll|{{.*}}_esimd_0.prop
; CHECK: {{.*}}_esimd_1.ll|{{.*}}_esimd_1.prop

; CHECK-SYCL-IR-0-DAG: define dso_local spir_kernel void @SYCL_kernel1()
; CHECK-SYCL-IR-0-DAG: declare dso_local spir_func i64 @_Z28__spirv_GlobalInvocationId_xv()

; CHECK-SYCL-IR-1-DAG: define dso_local spir_kernel void @SYCL_kernel2()
; CHECK-SYCL-IR-1-DAG: declare dso_local spir_func i64 @_Z28__spirv_GlobalInvocationId_xv()

; CHECK-ESIMD-IR-0-DAG: define dso_local spir_kernel void @ESIMD_kernel1()
; CHECK-ESIMD-IR-0-DAG: declare dso_local spir_func i64 @_Z28__spirv_GlobalInvocationId_xv()

; CHECK-ESIMD-IR-1-DAG: define dso_local spir_kernel void @ESIMD_kernel2()
; CHECK-ESIMD-IR-1-DAG: declare dso_local spir_func i64 @_Z28__spirv_GlobalInvocationId_xv()
Loading

0 comments on commit 94660ed

Please sign in to comment.