[llvm-dev] [SPIR-V] SPIR-V in LLVM

Nicholas Wilson via llvm-dev llvm-dev at lists.llvm.org
Wed May 3 08:11:43 PDT 2017


>Hi,

>
>I actively working on LLVM project with SPIR (no V here), and would love to see SPIR-V get integrated into LLVM.
>
>Does this SPIR-V "backend" support reading SPIR-V and generate LLVM IR in-memory representation?

Yes it does.

>Alternatively:
>Since SPIR-V is very close to LLVM IR, it may be a bad idea to translate LLVM IR to machine IR then to SPIR-V, direct LLVM >IR/SPIR-V translation maybe simpler.
 Having a look through the GlobalISel page makes me think the same, at least without looking at how web assembly/NVPTX deal with register banks.

>In this case, we consider SPIR-V as an IO format instead of a backend. we can introduce a special IR writer and IR reader >that write SPIR-V from LLVM IR in-memory representation and read SPIR-V to generated LLVM IR in-memory >representation. This is also not hard to integrate into clang/opt and I had done similar things (not SPIR-V though)
>
>In this case, it will be opt that read and generate SPIR-V, instead of llc.
>This allow us to read SPIR-V into the pass pipeline and optimize them.

That sounds like a good idea, except that it would have to be a target I/O hybrid because an I/O format having its own intrinsics I think is even weirder than a target that doesn’t use ISel/MC (all of the previous points about reasons for being a target still stand). Though a target I/O hybrid is pretty weird. A target for the forward compilation, I/O for reverse? Also take a look at llvm-spirv [1], which does the interconversions, well delegates the interconversions to the library.

The only problem for opt would be the target triple, i.e. want to output for AMDGPU need the triple to be correct and then also translate all the intrinsics over. Perhaps for the reverse i.e. consumption of SPIR-V, something like libclc[2] would be the way to go (and an equivalent for Vulkan)?

It is also worth noting that all these same quandaries would apply if/when MS decide to upstream their DXIL, since it is effective the same thing but different.

[1]:https://github.com/thewilsonator/llvm-tool-spirv

[2]:http://libclc.llvm.org<http://libclc.llvm.org/>


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170503/a009e1e1/attachment.html>


More information about the llvm-dev mailing list