Adding a new LLVM target to llvmlite

155 Views Asked by At

Is it possible to add a new target to llvmlite (python library)? For a new hardware (e.g. ASIC), I need to have a new and custom LLVM target. This is not very clear from the documentation.

If it is not possible to add a new target in llvmlite, can I generate IR in llvmlite and do the rest with another method?

1

There are 1 best solutions below

1
On

The answer is mixed.

It's possible that the new target isn't truly new, but something that LLVM can put together if you call llvmlite's create_target_machine() with the right arguments. Many ASICs aren't really unique.

If the target is truly new, you're 99% likely to require writing some C++. Backends subclass LLVM classes, and I'm not brave enough to try that in python. The amount of code required will be at least a hundred lines even if there already is a backend for your ASIC's CPU, and if you have to write a code generator for a complex CPU then you're really out of luck.

However, once you have the new target, then llvmlite should be able to use it without direct reference to any of the target- or backend-specific code. Your python code asks llvmlite to create_target_machine and then calls LLVM's pass manager via existing llvmlite calls, which in turn calls the right backend.