Skip to content

Commit

Permalink
[SYCL] Remove noreturn function attribute (#2165)
Browse files Browse the repository at this point in the history
This is a follow-up to:
74aa9a0 [SYCL] Remove "unreachable" instruction from LLVM IR for SYCL
devices (#1789)

Noreturn function attribute gives LLVM optimization passes an
opportunity to re-structure code and insert an unreachable
instruction.

This happens when optimizations are turned on by
-fsycl-enable-optimizations, so noreturn function attribute must be
removed.

Signed-off-by: Andrew Savonichev <[email protected]>
  • Loading branch information
Andrew Savonichev authored Jul 28, 2020
1 parent a6465c9 commit c93fa93
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 12 additions & 1 deletion clang/lib/CodeGen/CGCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4971,10 +4971,21 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,

// 4. Finish the call.

// SYCL does not support C++ exceptions or termination in device code, so all
// functions have to return.
bool SyclSkipNoReturn = false;
if (getLangOpts().SYCLIsDevice && CI->doesNotReturn()) {
if (auto *F = CI->getCalledFunction())
F->removeFnAttr(llvm::Attribute::NoReturn);
CI->removeAttribute(llvm::AttributeList::FunctionIndex,
llvm::Attribute::NoReturn);
SyclSkipNoReturn = true;
}

// If the call doesn't return for non-sycl devices, finish the basic block and
// clear the insertion point; this allows the rest of IRGen to discard
// unreachable code.
if (CI->doesNotReturn() && !getLangOpts().SYCLIsDevice) {
if (!SyclSkipNoReturn && CI->doesNotReturn()) {
if (UnusedReturnSizePtr)
PopCleanupBlock();

Expand Down
4 changes: 3 additions & 1 deletion clang/test/CodeGenSYCL/remove-ur-inst.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 -fsycl -fsycl-is-device -triple spir64-unknown-unknown-sycldevice -emit-llvm %s -o - | FileCheck %s
// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsycl-enable-optimizations -triple spir64-unknown-unknown-sycldevice -emit-llvm %s -o - | FileCheck %s

SYCL_EXTERNAL void doesNotReturn() throw() __attribute__((__noreturn__));

Expand All @@ -11,6 +12,7 @@ int main() {
kernel<class test>([]() {
doesNotReturn();
// CHECK-NOT: unreachable
// CHECK-NOT: noreturn
});
return 0;
}
}

0 comments on commit c93fa93

Please sign in to comment.