From c4474e28467f6a01b5c6b520ccddf2d3ea1cab2c Mon Sep 17 00:00:00 2001 From: Sergey Dmitriev Date: Mon, 11 Jan 2021 01:07:04 -0800 Subject: [PATCH 1/2] [SYCL][NFC] Add more details why llvm.used need to be removed from the IR To address review comment https://github.com/intel/llvm/pull/2995#discussion_r554889102 Signed-off-by: Sergey Dmitriev --- llvm/tools/sycl-post-link/sycl-post-link.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/llvm/tools/sycl-post-link/sycl-post-link.cpp b/llvm/tools/sycl-post-link/sycl-post-link.cpp index d253c836a203..ffba5ed41e51 100644 --- a/llvm/tools/sycl-post-link/sycl-post-link.cpp +++ b/llvm/tools/sycl-post-link/sycl-post-link.cpp @@ -689,9 +689,13 @@ int main(int argc, char **argv) { 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. + // After linking device bitcode "llvm.used" holds references to the kernels + // that are defined in the device image. But after splitting device image into + // separate kernels we may end up with having references to kernel declaration + // originating from "llvm.used" in the IR that is passed to llvm-spirv tool, + // and these declarations cause an assertion in llvm-spirv. To workaround this + // issue remove "llvm.used" from the input module before perfroming any other + // actions. if (GlobalVariable *GV = MPtr->getGlobalVariable("llvm.used")) { assert(GV->user_empty() && "unexpected llvm.used users"); GV->eraseFromParent(); From b9df7dffb20d25aad0c08f8e421bcdb130969feb Mon Sep 17 00:00:00 2001 From: Alexey Bader Date: Mon, 11 Jan 2021 20:23:01 +0300 Subject: [PATCH 2/2] Update llvm/tools/sycl-post-link/sycl-post-link.cpp --- llvm/tools/sycl-post-link/sycl-post-link.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/tools/sycl-post-link/sycl-post-link.cpp b/llvm/tools/sycl-post-link/sycl-post-link.cpp index ffba5ed41e51..2d606ce7ef04 100644 --- a/llvm/tools/sycl-post-link/sycl-post-link.cpp +++ b/llvm/tools/sycl-post-link/sycl-post-link.cpp @@ -694,7 +694,7 @@ int main(int argc, char **argv) { // separate kernels we may end up with having references to kernel declaration // originating from "llvm.used" in the IR that is passed to llvm-spirv tool, // and these declarations cause an assertion in llvm-spirv. To workaround this - // issue remove "llvm.used" from the input module before perfroming any other + // issue remove "llvm.used" from the input module before performing any other // actions. if (GlobalVariable *GV = MPtr->getGlobalVariable("llvm.used")) { assert(GV->user_empty() && "unexpected llvm.used users");