A lightweight LLVM python binding for writing JIT compilers
The old llvmpy binding exposes a lot of LLVM APIs but the mapping of
C++-style memory management to Python is error prone. Numba and many JIT
compilers do not need a full LLVM API. Only the IR builder, optimizer,
and JIT compiler APIs are necessary.
llvmlite is a project originally tailored for Numba’s needs, using the
A small C wrapper around the parts of the LLVM C++ API we need that are
not already exposed by the LLVM C API.
A ctypes Python wrapper around the C API.
A pure Python implementation of the subset of the LLVM IR builder that we
need for Numba.
The IR builder is pure Python code and decoupled from LLVM’s
frequently-changing C++ APIs.
Materializing a LLVM module calls LLVM’s IR parser which provides
better error messages than step-by-step IR building through the C++
API (no more segfaults or process aborts).
Most of llvmlite uses the LLVM C API which is small but very stable
(low maintenance when changing LLVM version).
The binding is not a Python C-extension, but a plain DLL accessed using
ctypes (no need to wrestle with Python’s compiler requirements and C++ 11
The Python binding layer has sane memory management.
llvmlite is quite faster than llvmpy’s thanks to a much simpler architeture
(the Numba test suite is twice faster than it was).
llvmpy Compatibility Layer
The llvmlite.llvmpy namespace provides a minimal llvmpy compatibility
llvmlite works with Python 3.6 and greater.
As of version 0.29.0, llvmlite requires LLVM 7.0.x or later