SPIR-V compiler target

Is it possible to generate Spirv with swiftc?
I tried llvm-spirv ("InvalidTargetTriple: Expects spir-unknown-unknown or spir64-unknown-unknown. Actual target triple is x86_64-unknown-linux-gnu") and swiftc -target spir64-unknown-unknown ("error: unknown target 'spir64-unknown-unknown'"). And if it is not possible how complex would it be to add to swiftc? I am just trying to compile a very simple function (func add(Float, Float) -> Float).

1 Like

*-unknown-unknown targets are currently not supported. There's a PR that could add it, but it needs separate driver code to fully work. If you'd like to experiment with it right now, you'll need to build your own toolchain off this patch (and maybe modify it to your needs) for this triple to be recognized. I'm currently working on support for bare metal triples, so eventually I hope this will be available upstream. You will still need proper runtime and stdlib for anything to work. I guess uSwift could be more suitable for SPIR-V than the usual stdlib, which depends on libc and other things not relevant for your use case.

2 Likes

There's also a bigger question of SPIR-V support in LLVM. I don't think it's there yet, and before LLVM and Clang fully support it, it's probably unrealistic to expect the Swift target to work.

2 Likes