Page MenuHomePhabricator

[SPIR-V] Add a tool chain for SPIR-V (incomplete)
Needs ReviewPublic

Authored by linjamaki on Oct 25 2021, 12:15 AM.
This revision needs review, but there are no reviewers specified.

Details

Reviewers
None
Summary

This patch adds a tool chain (TC) for SPIR-V for demonstration purposes. The TC is not complete but it is functional enough for producing SPIR-V assembly*1 and object code directly via clang from a language of choice, for example:

clang -target spirv64 foo.cl -c -o foo.spv
clang -target spirv64 baz.clcpp -c -o baz.spv
clang -target spirv64 bar.c -S -o bar.spt

The SPIR-V code is generated by the SPIRV-LLVM translator tool or other compatible tool named as llvm-spirv that is sought in PATH.

List of things the TC is missing but not limited to:

  • Linking and image generation.
  • Complete and proper overrides from the base TC.
  • Proper SPIR-V assembly output *1.
  • Complete command line interface laid out in [1].

*1: The output from the SPIRV-LLVM Translator is its internal text presentation.

Changes in the Driver and base ToolChain and Tool:
Added a mechanism to work with the lack of SPIR-V backend in LLVM for SPIR-V TC. Until SPIR-V backend lands on LLVM, compilation phases/actions should be bound for SPIR-V in the meantime as following:

  • compile -> tools::Clang
  • backend -> tools::SPIRV::Translator
  • assemble -> tools::SPIRV::Translator

However, Driver’s ToolSelector collapses compile-backend-assemble and compile-backend sequences to tools::Clang. To prevent this, added new {use,has}IntegratedBackend properties in ToolChain and Tool to which the ToolSelector reacts on, and which SPIR-V TC overrides.

We contributed this patch and the previous one in the stack (D112404 - [SPIR-V] Add translator tool) to address Anastasia’s feedback in (https://reviews.llvm.org/D110618#3062078) and other concerns around the SPIR-V tool chain adoption for languages other than HIP. However, we do not currently have the resources to allocate for continuing much further work in this patch unrelated to the needs of the HIP frontend. Thus, please consider this as a potentially useful starting point for further work needed to support other frontends, hopefully good enough minimal code to get this side started with and our patch set integrated to the master.

[1]: https://github.com/KhronosGroup/SPIRV-LLVM-Translator/wiki/SPIRV-Toolchain-for-Clang

Diff Detail

Event Timeline

linjamaki created this revision.Oct 25 2021, 12:15 AM
linjamaki published this revision for review.Oct 25 2021, 12:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 25 2021, 12:23 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Cool. I like the direction... In the end it probably makes sense to separate clang compilation flow into more separate steps. This makes it more suitable to non-LLVM based backends or even MLIR towards Clang Intermediate Language. This looks like a fairly good starting point! Thanks!

Thus, please consider this as a potentially useful starting point for further work needed to support other frontends, hopefully good enough minimal code to get this side started with and our patch set integrated to the master.

Do I read it correctly that you would have no objections for others to rework this patch if needed? :)

Do I read it correctly that you would have no objections for others to rework this patch if needed? :)

Yes, anyone can work on this patch.

linjamaki updated this revision to Diff 383019.Oct 28 2021, 6:27 AM

Rebase on updated llvm-spirv tool (D112404).