Skip to content

Commit 9b07d11

Browse files
authored
[SYCL] Do not emit llvm.used to output module(s) in the post link tool (#2995)
This special global variable may cause problems for tools running later in pipeline. Corrected assertion message Signed-off-by: Sergey Dmitriev <[email protected]>
1 parent 0b9a749 commit 9b07d11

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; This test checks that the post-link tool does not add "llvm.used" global to
2+
; the output modules when splitting kernels.
3+
;
4+
; RUN: sycl-post-link -split=kernel -S %s -o %T/files.table
5+
; RUN: FileCheck %s -input-file=%T/files_0.ll
6+
; RUN: FileCheck %s -input-file=%T/files_1.ll
7+
8+
target triple = "spir64-unknown-unknown-sycldevice"
9+
10+
; CHECK-NOT: llvm.used
11+
@llvm.used = appending global [2 x i8*] [i8* bitcast (void ()* @foo to i8*), i8* bitcast (void ()* @bar to i8*)], section "llvm.metadata"
12+
13+
define weak_odr spir_kernel void @foo() {
14+
ret void
15+
}
16+
17+
define weak_odr spir_kernel void @bar() {
18+
ret void
19+
}

llvm/tools/sycl-post-link/sycl-post-link.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,15 @@ int main(int argc, char **argv) {
688688
Err.print(argv[0], errs());
689689
return 1;
690690
}
691+
692+
// Special "llvm.used" variable which holds references to global values in the
693+
// module is known to cause problems for tools which run later in pipeline, so
694+
// remove it from the module before perfroming any other actions.
695+
if (GlobalVariable *GV = MPtr->getGlobalVariable("llvm.used")) {
696+
assert(GV->user_empty() && "unexpected llvm.used users");
697+
GV->eraseFromParent();
698+
}
699+
691700
if (OutputFilename.getNumOccurrences() == 0)
692701
OutputFilename = (Twine(sys::path::stem(InputFilename)) + ".files").str();
693702

0 commit comments

Comments
 (0)