From d399540bcf09622e161499b9d6a44bf86df0cf28 Mon Sep 17 00:00:00 2001 From: Sergey Dmitriev Date: Tue, 5 Jan 2021 19:04:34 -0800 Subject: [PATCH 1/2] [SYCL] Do not emit "llvm.used" to output module(s) in the post link tool This special global variable may cause problems for tools runing later in pipeline. Signed-off-by: Sergey Dmitriev --- llvm/test/tools/sycl-post-link/erase_used.ll | 20 ++++++++++++++++++++ llvm/tools/sycl-post-link/sycl-post-link.cpp | 9 +++++++++ 2 files changed, 29 insertions(+) create mode 100644 llvm/test/tools/sycl-post-link/erase_used.ll 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..67cada581d9fe --- /dev/null +++ b/llvm/test/tools/sycl-post-link/erase_used.ll @@ -0,0 +1,20 @@ +; 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..18d6d005a53ba 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 "); + GV->eraseFromParent(); + } + if (OutputFilename.getNumOccurrences() == 0) OutputFilename = (Twine(sys::path::stem(InputFilename)) + ".files").str(); From 3f558733a8c0a3059d420854e601ac6f0d49c1c3 Mon Sep 17 00:00:00 2001 From: Sergey Dmitriev Date: Tue, 5 Jan 2021 19:24:46 -0800 Subject: [PATCH 2/2] Corrected assertion message Signed-off-by: Sergey Dmitriev --- llvm/test/tools/sycl-post-link/erase_used.ll | 1 - llvm/tools/sycl-post-link/sycl-post-link.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/llvm/test/tools/sycl-post-link/erase_used.ll b/llvm/test/tools/sycl-post-link/erase_used.ll index 67cada581d9fe..18b712abc8eab 100644 --- a/llvm/test/tools/sycl-post-link/erase_used.ll +++ b/llvm/test/tools/sycl-post-link/erase_used.ll @@ -17,4 +17,3 @@ define weak_odr spir_kernel void @foo() { 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 18d6d005a53ba..d253c836a2033 100644 --- a/llvm/tools/sycl-post-link/sycl-post-link.cpp +++ b/llvm/tools/sycl-post-link/sycl-post-link.cpp @@ -693,7 +693,7 @@ int main(int argc, char **argv) { // 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 "); + assert(GV->user_empty() && "unexpected llvm.used users"); GV->eraseFromParent(); }