Integrating with LLVM

Many compilers are now being outfitted with LLVM backends. There are a variety of ways to do this, and we'll take a look at some of them here.

Calling LLVM APIs Directly

One common and easy way to integrate with LLVM is to directly link against the LLVM libraries and invoke the LLVM API directly.


LLVM's native APIs are C++. Examples of languages that talk to LLVM via the C++ APIs are Julia and CLASP.

This is also the approach taken by Clang, however, Clang lives within the same code repository as LLVM and shares many developers. It is part of the LLVM project rather than a separate compiler that is using LLVM as a backend.

While this seems like an attractive option, there are some issues with it:

  • Your code must either be written in C++ or be able to invoke C++ code via an FFI (foreign function interface).
  • You are tied to a particular version of the LLVM API at compile time.
  • It is harder to re-use someone's existing installation of LLVM as you are tied to a particular version.


LLVM also provides a C wrapper around the C++ APIs. This ...

read more »

There are comments.