numba/llvmlite

A lightweight LLVM python binding for writing JIT compilers

What it solves

llvmlite provides a lightweight, stable, and memory-safe Python binding for LLVM, specifically designed for those building Just-In-Time (JIT) compilers. It avoids the complexity and instability of full LLVM C++ API bindings, which are often error-prone and difficult to maintain across different LLVM versions.

How it works

The project uses a three-layered approach to interface with LLVM:

  1. C Wrapper: A small wrapper around specific LLVM C++ API parts not available in the C API.
  2. ctypes Wrapper: A Python wrapper around the LLVM C API using ctypes to avoid the need for Python C-extensions.
  3. Pure Python IR Builder: A Python implementation of a subset of the LLVM Intermediate Representation (IR) builder, which decouples the IR building process from the frequently changing C++ APIs.

Who it’s for

Developers creating JIT compilers or software that requires LLVM's IR builder, optimizer, and JIT compiler APIs within a Python environment.

Highlights

  • Stability: Uses the stable LLVM C API to ensure low maintenance when upgrading LLVM versions.
  • Performance: Features a simpler architecture that is faster than previous bindings like llvmpy.
  • Memory Management: Implements sane memory management to prevent common C++-style errors.
  • Ease of Installation: Provided as a plain DLL accessed via ctypes, removing the need for complex C++ 11 compatibility or compiler requirements during installation.

Related

  • Project
  • Project
  • Project
  • Project
  • Project