Enabling SPIR target in LLVM 3.3

Hi.

I am looking into generating SPIR from within a JIT compiler for a
high level language using LLVM C++ API. The first step is to of course
build LLVM with SPIR backend support and I am currently using LLVM
3.3.

For reference, the host system is a x86-64 Linux. I first tried
building LLVM 3.3 without specifying any targets, and it built many
targets including aarch64, arm, x86, x86_64, nvptx etc but no spir or
spir64 targets.

Next, I tried to explicitly configure targets as follows:
--enable-targets=x86_64,spir,spir64 but I got "unrecognized target
spir".

Any idea how to proceed? Do I need to apply some patches to LLVM?

(Note that Clang is not involved, this is purely a LLVM question).

rahul

Hi Rahul,

I am looking into generating SPIR from within a JIT compiler for a
high level language using LLVM C++ API. The first step is to of course
build LLVM with SPIR backend support and I am currently using LLVM
3.3.

As far as I know, there's no such thing as a SPIR backend, or the
ability to translate fully generic LLVM IR into SPIR. If you want to
generate SPIR, you have to know the restrictions it imposes and follow
them.

Where LLVM gets involved is that OpenCL compilers which accept SPIR
input will (probably) pass it on to the usual LLVM backends (x86, ARM,
bizare-GPU-43712) to translate into the appropriate machine code.

Also, be aware that LLVM changes quickly. SPIR still seems to be based
on version 3.2 which was nearly 2 years ago. You'd certainly hit
issues trying to mix it with modern LLVM IR, and I'd not want to risk
it with 3.3 either.

Cheers.

Tim.

Thanks. I am not trying to modify convert generic LLVM IR and know the
requirements (such as specifying address spaces etc.). I guess I just
need to ensure that I am sticking to LLVM 3.2 and the SPIR specified
subset+ metadata annotations etc.

Anyway, I was confused partly because there are references to a SPIR
backend in LLVM code (eg: include/llvm/ADT/Triple.h lists spir and
spir64 as possible architectures)

rahui

SPIR/SPIR64 are IR triples, but not backend targets, which is why enabling them as targets failed. SPIR binaries can be loaded into the llvm infrastructure as of LLVM 3.2, though I'm not sure about compatibility with later versions. The loaded module still needs to be lowered to their target specific version before anything is done in order to produce valid code.

Micah

Thanks Micah! I have switched to LLVM 3.2 instead of using 3.3 and now
attempting to generate SPIR.