diff --git a/llvm/test/tools/sycl-post-link/erase_used.ll b/llvm/test/tools/sycl-post-link/erase_used.ll new file mode 100644 index 0000000000000..18b712abc8eab --- /dev/null +++ b/llvm/test/tools/sycl-post-link/erase_used.ll @@ -0,0 +1,19 @@ +; This test checks that the post-link tool does not add "llvm.used" global to +; the output modules when splitting kernels. +; +; RUN: sycl-post-link -split=kernel -S %s -o %T/files.table +; RUN: FileCheck %s -input-file=%T/files_0.ll +; RUN: FileCheck %s -input-file=%T/files_1.ll + +target triple = "spir64-unknown-unknown-sycldevice" + +; CHECK-NOT: llvm.used +@llvm.used = appending global [2 x i8*] [i8* bitcast (void ()* @foo to i8*), i8* bitcast (void ()* @bar to i8*)], section "llvm.metadata" + +define weak_odr spir_kernel void @foo() { + ret void +} + +define weak_odr spir_kernel void @bar() { + ret void +} diff --git a/llvm/tools/sycl-post-link/sycl-post-link.cpp b/llvm/tools/sycl-post-link/sycl-post-link.cpp index 257ff7a8598d4..d253c836a2033 100644 --- a/llvm/tools/sycl-post-link/sycl-post-link.cpp +++ b/llvm/tools/sycl-post-link/sycl-post-link.cpp @@ -688,6 +688,15 @@ int main(int argc, char **argv) { Err.print(argv[0], errs()); return 1; } + + // Special "llvm.used" variable which holds references to global values in the + // module is known to cause problems for tools which run later in pipeline, so + // remove it from the module before perfroming any other actions. + if (GlobalVariable *GV = MPtr->getGlobalVariable("llvm.used")) { + assert(GV->user_empty() && "unexpected llvm.used users"); + GV->eraseFromParent(); + } + if (OutputFilename.getNumOccurrences() == 0) OutputFilename = (Twine(sys::path::stem(InputFilename)) + ".files").str();