[clang] 6b86813 - [SYCL] Always set NoUnwind attribute for SYCL.
Harald van Dijk via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 29 18:19:26 PDT 2023
Author: Harald van Dijk
Date: 2023-03-30T02:18:52+01:00
New Revision: 6b868139458d258c1ed4c0279e8f4374556c1c1e
URL: https://github.com/llvm/llvm-project/commit/6b868139458d258c1ed4c0279e8f4374556c1c1e
DIFF: https://github.com/llvm/llvm-project/commit/6b868139458d258c1ed4c0279e8f4374556c1c1e.diff
LOG: [SYCL] Always set NoUnwind attribute for SYCL.
Like CUDA and OpenCL, the SYCL specification says that throwing and
catching exceptions in device functions is not supported, so this change
extends the logic for adding the NoUnwind attribute to SYCL.
The existing convergent.cpp test, which tests that the convergent
attribute is added to functions by default, is renamed and reused to
test that the nounwind attribute is added by default. This test now has
-fexceptions added to it, which the driver adds by default as well.
The obvious question here is why not simply change the driver to remove
-fexceptions. This change follows the direction given by the TODO
comment because removing -fexceptions would also disable the
__EXCEPTIONS macro, which should reflect whether exceptions are enabled
on the host, rather than on the device, to avoid conflicts in types
shared between host and device.
Reviewed By: bader
Differential Revision: https://reviews.llvm.org/D147097
Added:
clang/test/CodeGenSYCL/function-attrs.cpp
Modified:
clang/lib/CodeGen/CGCall.cpp
Removed:
clang/test/CodeGenSYCL/convergent.cpp
################################################################################
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index aaa5d4e70d7db..63296aeec5b9f 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1971,10 +1971,9 @@ void CodeGenModule::getDefaultFunctionAttributes(StringRef Name,
}
// TODO: NoUnwind attribute should be added for other GPU modes HIP,
- // SYCL, OpenMP offload. AFAIK, none of them support exceptions in device
- // code.
+ // OpenMP offload. AFAIK, neither of them support exceptions in device code.
if ((getLangOpts().CUDA && getLangOpts().CUDAIsDevice) ||
- getLangOpts().OpenCL) {
+ getLangOpts().OpenCL || getLangOpts().SYCLIsDevice) {
FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
}
diff --git a/clang/test/CodeGenSYCL/convergent.cpp b/clang/test/CodeGenSYCL/convergent.cpp
deleted file mode 100644
index 779f1592da0e0..0000000000000
--- a/clang/test/CodeGenSYCL/convergent.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-// RUN: %clang_cc1 -fsycl-is-device -emit-llvm -disable-llvm-passes \
-// RUN: -triple spir64 -emit-llvm %s -o - | FileCheck %s
-
-// CHECK-DAG: Function Attrs:
-// CHECK-DAG-SAME: convergent
-// CHECK-DAG-NEXT: define void @_Z3foov
-void foo() {
- int a = 1;
-}
-
-template <typename Name, typename Func>
-__attribute__((sycl_kernel)) void kernel_single_task(const Func &kernelFunc) {
- kernelFunc();
-}
-
-int main() {
- kernel_single_task<class fake_kernel>([] { foo(); });
- return 0;
-}
diff --git a/clang/test/CodeGenSYCL/function-attrs.cpp b/clang/test/CodeGenSYCL/function-attrs.cpp
new file mode 100644
index 0000000000000..8f5c0ea5c512c
--- /dev/null
+++ b/clang/test/CodeGenSYCL/function-attrs.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -fsycl-is-device -emit-llvm -disable-llvm-passes \
+// RUN: -triple spir64 -fexceptions -emit-llvm %s -o - | FileCheck %s
+
+int foo();
+
+// CHECK: define dso_local spir_func void @_Z3barv() [[BAR:#[0-9]+]]
+// CHECK: attributes [[BAR]] =
+// CHECK-SAME: convergent
+// CHECK-SAME: nounwind
+void bar() {
+ int a = foo();
+}
+
+int foo() {
+ return 1;
+}
+
+template <typename Name, typename Func>
+__attribute__((sycl_kernel)) void kernel_single_task(const Func &kernelFunc) {
+ kernelFunc();
+}
+
+int main() {
+ kernel_single_task<class fake_kernel>([] { bar(); });
+ return 0;
+}
More information about the cfe-commits
mailing list