Skip to content

[SYCL] Do not emit "llvm.used" to output module(s) in the post link tool #2995

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

Conversation

sndmitriev
Copy link
Contributor

This special global variable may cause problems for tools runing later in pipeline.

Signed-off-by: Sergey Dmitriev [email protected]

This special global variable may cause problems for tools runing later in pipeline.

Signed-off-by: Sergey Dmitriev <[email protected]>
kbobrovs
kbobrovs previously approved these changes Jan 6, 2021
Signed-off-by: Sergey Dmitriev <[email protected]>
@sndmitriev
Copy link
Contributor Author

/summary:run

@pvchupin pvchupin merged commit 9b07d11 into intel:sycl Jan 6, 2021
@pvchupin
Copy link
Contributor

pvchupin commented Jan 6, 2021

@AlexeySachkov, @bader, please review as soon as return from holidays.

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sndmitriev, could you clarify what kind of problems might be caused, please?

Copy link
Contributor Author

@sndmitriev sndmitriev Jan 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 (with -fsycl-device-code-split=per_kernel option) 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

$ cat test.ll
target triple = "spir64-unknown-unknown-sycldevice"

@llvm.used = appending global [2 x i8*] [i8* bitcast (void ()* @foo to i8*), i8* bitcast (void ()* @bar to i8*)], section "llvm.metadata"

declare spir_kernel void @foo()

define spir_kernel void @bar() {
  ret void
}
$ llvm-as -o test.bc test.ll
$ llvm-spirv -o test.spv -spirv-max-version=1.1 -spirv-debug-info-version=legacy -spirv-allow-extra-diexpressions -spirv-ext=+all,-SPV_INTEL_usm_storage_classes test.bc
llvm-spirv: …/llvm/llvm-spirv/lib/SPIRV/SPIRVWriter.cpp:3438: void SPIRV::LLVMToSPIRV::transFPContract(): Assertion `FPC != FPContract::UNDEF' failed.
…

Copy link
Contributor

@AlexeySachkov AlexeySachkov Jan 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused with the reasoning.

That FP-contract related assertion seems like an unhandled situation in the translator which should be fixed there.
However, I do agree that @llvm.used might cause problems with the translation, because it contains function pointers and can't be translated into SPIR-V without corresponding extension (SPV_INTEL_function_pointers) enabled

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not argue with that, the problem needs to be fixed in the translator as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we get this metadata in device code? It's not emitted in SYCL mode: aa35161. Is it emitted in other modes?
If so, shouldn't we drop @llvm.used during FE IR generation?

Anyway, it would be nice if we add clarification with reasoning to drop @llvm.used in sycl-post-link tool from this comment: #2995 (comment).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we get this metadata in device code?

"llvm.used" variable may appear in the IR after linking with "deps" bitcode file (please see #2872 for more details).

Anyway, it would be nice if we add clarification with reasoning to drop @llvm.used in sycl-post-link tool from this comment: #2995 (comment).

I have created #3012 to address your comment. Please review it.

sndmitriev added a commit to sndmitriev/llvm that referenced this pull request Jan 11, 2021
@sndmitriev sndmitriev deleted the public/sndmitriev/post-link-erase-used branch January 12, 2021 01:46
romanovvlad pushed a commit that referenced this pull request Jan 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants