Generating SPIR

I am already successfully generating SPIR-V with a forward port of Khronos’ SPIR-V LLVM.
What does one need in order to generate SPIR?

From what I gather it is based on a specific LLVM IR version (3.4?) with a bunch of metadata.
Is it possible to generate SPIR from LLVM trunk? If so how?

Thanks
Nic

For SPIR 1.2 you can use this repo + the instructions in it https://github.com/KhronosGroup/SPIR

I don't believe there is a way to generate SPIR from LLVM trunk.

Cheers,
-Neil.

That really should change, at least for SPIR-V.

Cheers, Jakob.

SPIR-V is no problem.
see https://github.com/thewilsonator/llvm-target-spirv (a submodule of below)
and https://github.com/thewilsonator/llvm
they are kept reasonably up to date with trunk (API breakage compatible).

I do want to merge it into trunk, but I need to make it use LLVM intrinsics instead of mangled Itanium C++ with extensions.
This will hopefully happen (at least get in motion) at IWOCL.

Nic

Well, I guess there are some companies like Codeplay with this in
house, but it is not open-source...

If you use the current Clang/LLVM to generate SPIR from OpenCL, it will
generate actualy a SPIR-ish output (what I call SPIR "de facto"),
basically something that looks like SPIR but that is actually not
compliant, since SPIR 1.2 standard states that it has to be based on LLVM
3.2 IR and SPIR 2.0 has to be based on LLVM 3.4 IR.

Interestingly, the LLVM metadata are generated by... Clang in
tools/clang/lib/CodeGen/CodeGenFunction.cpp by
clang::CodeGen::CodeGenFunction::EmitOpenCLKernelMetadata when compiling
OpenCL.

Inside triSYCL https://github.com/triSYCL/triSYCL (a prototype for SYCL,
the single-source modern C++ standard from Khronos on top of OpenCL) I
have a hack for LLVM 3.9 to generate some SPIR "de-facto" directly at
the LLVM level, since I do not use the Clang OpenCL front-end. Look at
https://github.com/triSYCL/llvm/blob/ronan/sycl/lib/SYCL/inSPIRation.cpp

In my case, even if it is not compliant, it seems to work with PoCL or
Xilinx SDx/xocc for FPGA.
It should not be difficult to migrate this to ToT if it can help your
use case.

Then remains the question about how to generate real compliant SPIR from
both possible paths.
There are some open-source LLVM IR downgrading writer around as already discussed on
this mailing list
http://lists.llvm.org/pipermail/llvm-dev/2016-August/103395.html

So to conclude, the big picture is a little bit messy for now... :frowning:

Well it’s better than nothing! Thanks I will see what I can do with that.

Also that code looks suspiciously like the stuff for clang and LDC SPIR-V
frontend metadata emission. Looks like it shouldn’t be too much effort.