Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SYCL] Don't emit exception handling code for device #449

Merged
merged 1 commit into from
Aug 6, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clang/lib/CodeGen/CGException.cpp
Original file line number Diff line number Diff line change
@@ -717,8 +717,8 @@ llvm::BasicBlock *CodeGenFunction::getInvokeDestImpl() {
return nullptr;
}

// CUDA device code doesn't have exceptions.
if (LO.CUDA && LO.CUDAIsDevice)
// CUDA and SYCL device code doesn't have exceptions.
if (LO.CUDA && LO.CUDAIsDevice || LO.SYCLIsDevice)
return nullptr;

// Check the innermost scope for a cached landing pad. If this is
53 changes: 53 additions & 0 deletions clang/test/CodeGenSYCL/noexcept.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// RUN: %clang_cc1 -triple spir64-unknown-linux-sycldevice -I%S -fsycl-is-device \
// RUN: -std=c++11 -fcxx-exceptions -fexceptions -disable-llvm-passes -x c++ \
// RUN: -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-DEVICE
//
// RUN: %clang_cc1 -I%S -std=c++11 -fcxx-exceptions -fexceptions -disable-llvm-passes \
// RUN: -x c++ -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-HOST

// The test checks that exception handling code is generated only for host and not for device.

void f1() {}
void f2() {}
void f3() {}

void foo_noexcept() noexcept {
// CHECK-DEVICE: call spir_func void @_Z2f1v()
// CHECK-HOST: invoke void @_Z2f1v()
f1();
}

void foo_throw() throw() {
// CHECK-DEVICE: call spir_func void @_Z2f2v()
// CHECK-HOST: invoke void @_Z2f2v()
f2();
}

struct A {
// Non-trivial destructor to force generation of cleanup code
~A(){}
};

void foo_cleanup() {
A a;
// CHECK-DEVICE: call spir_func void @_Z2f3v()
// CHECK-HOST: invoke void @_Z2f3v()
f3();
// CHECK-DEVICE: call spir_func void @_ZN1AD1Ev
// Regular + exception cleanup
// CHECK-HOST: call void @_ZN1AD1Ev
// CHECK-HOST: call void @_ZN1AD1Ev
}

template <typename name, typename Func>
__attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) {
kernelFunc();
}

int main() {
kernel_single_task<class kernel>([=](){
foo_noexcept();
foo_throw();
foo_cleanup();
});
}