[PATCH] D112410: [SPIR-V] Add a tool chain for SPIR-V (incomplete)

Henry Linjamäki via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 25 00:23:48 PDT 2021


linjamaki created this revision.
Herald added a subscriber: ThomasRaoux.
linjamaki published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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 <https://reviews.llvm.org/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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112410

Files:
  clang/include/clang/Driver/Tool.h
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/Clang.h
  clang/lib/Driver/ToolChains/SPIRV.cpp
  clang/lib/Driver/ToolChains/SPIRV.h
  clang/test/Driver/spirv-toolchain.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112410.381863.patch
Type: text/x-patch
Size: 11361 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211025/97bcc1df/attachment-0001.bin>


More information about the cfe-commits mailing list