Skip to content

[SYCL][NFC] Add more details why llvm.used need to be removed from the IR #3012

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions llvm/tools/sycl-post-link/sycl-post-link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 performing any other
// actions.
if (GlobalVariable *GV = MPtr->getGlobalVariable("llvm.used")) {
assert(GV->user_empty() && "unexpected llvm.used users");
GV->eraseFromParent();
Expand Down