Skip to content
ALB Wiki

LLVM

LLVM

LLVM is the most influential compiler infrastructure built in the 21st century — a set of reusable libraries for writing compilers, anchored by a single beautifully-designed intermediate representation (LLVM IR) that has become the de facto lingua franca for new programming languages.

It began as Chris Lattner's 2000 master's project at the University of Illinois Urbana-Champaign — the name originally stood for "Low Level Virtual Machine," though the project formally retired the acronym in 2011 because it had long since stopped being a virtual machine. Apple hired Lattner in 2005 and adopted LLVM as the toolchain for Mac OS X and then the iPhone; the stakes could not have been higher, and the bet paid off.

The IR is the product

LLVM's central contribution is not any single compiler but LLVM IR — a strongly-typed, SSA-form (static single assignment) intermediate representation that sits exactly between "high enough to optimize portably" and "low enough to map directly to machine instructions." An LLVM IR function looks like annotated assembly:

%sum = add i32 %a, %b
%cmp = icmp sgt i32 %sum, 100
br i1 %cmp, label %big, label %small

The IR is what you are writing when you target LLVM: a language front end (Clang for C++, rustc for Rust, a toy compiler for a weekend language) emits IR, LLVM's ~200 composable optimization passes transform it, and a backend lowers it to x86-64, ARM64, RISC-V, WASM, AMDGPU, PTX (NVIDIA GPU), or any of the other targets LLVM ships.

Because the IR is a stable, documented format — not an internal implementation detail — any project can emit it and immediately gain world-class optimization and thirty machine backends. That is the deal that made LLVM dominant: write a front end, get an optimizer and a code generator for free.

What runs on it

The list of production compilers built on LLVM reads like a who's who of modern languages:

  • Clang — C, C++, Objective-C. LLVM's original front end; the default on Apple platforms, Android NDK, and FreeBSD; famous for diagnostics that actually name the mistake.
  • rustc — the Rust compiler. Every cargo build in the world lowers MIR → LLVM IR → machine code.
  • Swift — Apple's language compiles through its own SIL first, then LLVM IR.
  • Zig — embeds Clang as its C/C++ front end and uses LLVM for code generation; zig cc is a full C/C++ compiler with the best cross-compilation UX in the industry.
  • Julia — compiles numerical code through LLVM to achieve "Python syntax, C speed."
  • flang — the modern LLVM Fortran front end (successor to f18).
  • ldc — the D language compiler.
  • Emscripten — the LLVM→WebAssembly bridge that made C/C++ runnable in browsers.
  • NVCC — NVIDIA's CUDA compiler is Clang-based on the front end.
  • MLIR — LLVM's own next-generation multi-level IR, built for AI accelerators and domain-specific compilers.

LLVM vs GCC — the design split

The comparison with GCC is instructive:

LLVMGCC
Designlibraries + composable passesmonolithic compiler
IRsingle stable SSA IR, documentedtwo internal IRs (GIMPLE, RTL)
LicenseApache 2.0 (permissive)GPLv3
New-language adoptionnearly universalrare
Embedded/GPU targetsstrong (WASM, AMDGPU, PTX)strong on exotic CPUs
Diagnosticsdesigned-in clarityimproved but older

The deepest difference is architectural: GCC grew as a compiler that gained front ends; LLVM was designed from the start as a toolkit for building compilers. LLVM's optimizer passes, its IR parser, its JIT engine (ORC JIT, successor to MCJIT), its linker (LLD), its debugger (LLDB), its C++ standard library (libc++), and its runtime (compiler-rt) are all separate reusable components — you can link a JIT compiler into your application in 200 lines of C++.

GCC still wins on exotic embedded targets (decades of .md files) and is the reference toolchain for the Linux kernel and certified Ada; LLVM wins everywhere a new language, a new hardware target, or a browser is involved. They coexist: most Linux systems install both.

The JIT angle

LLVM is also a just-in-time compilation engine. Its ORC JIT lets a running program compile LLVM IR to native code on the fly — which is how Julia gets "compiled" speed without a separate build step, how some database engines compile queries into machine code, how shader languages compile on the fly inside GPU drivers, and how interpreted languages embed a "compiler escape hatch."

MLIR — the successor in progress

Inside LLVM itself a newer project, MLIR (Multi-Level Intermediate Representation), is extending the LLVM philosophy to problems LLVM IR can't express cleanly: tensor operations for AI hardware, domain-specific compilers, hardware synthesis. MLIR is where much of the industry's new compiler research is happening — Google's TPUs, Apple's ML accelerators, and the AI-stack compilers (XLA, Torch-MLIR, IREE) are MLIR-based.

See also

References

  1. Lattner, Chris, and Vikram Adve. "LLVM: A Compilation Framework for Lifelong Program Analysis & Transformation." International Symposium on Code Generation and Optimization (CGO 2004) — the foundational paper.
  2. llvm.org — documentation, IR reference, pass list.
  3. Lattner, Chris. "LLVM" chapter in The Architecture of Open Source Applications (2011).
  4. Clang documentation — clang.llvm.org.
  5. Emscripten documentation — emscripten.org.
Categories: Programming · Technology
This page was last edited 2026-10-20 13:00:48 UTC by ALB Team. What links here