/programming-language-development:language-irs-optimization-and-backendsfrom programming-language-development
Covers compiler middle and back ends: IR design (SSA, CPS/ANF, MLIR), optimization passes, backend selection (LLVM, Cranelift, GCC, custom), instruction selection, register allocation, ABI, and WebAssembly as a target.
Ships in programming-language-development. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Part 2 of 5 of the Programming Language Development reference (plugin
programming-language-development), covering §5–§7. Sibling skills:language-design-parsing-and-types(§0–§4),language-runtimes-interpreters-and-jits(§8–§9),language-diagnostics-tooling-and-evolution(§10–§14),language-development-reference(§15–§20). Section numbers are shared across the set; a reference written as §N →skillpoints into that sibling skill.Currency: Verified August 2026. See §17 →
language-development-referencefor the currency snapshot and what goes stale first.
How to read this. Reference, not tutorial. Sections are independent. Three markers:
- [DURABLE] — theory, algorithms, or a lesson every language implementation has independently learned. Does not expire.
- [VERSIONED] — depends on a specific toolchain, standard, or project's current state. Verify against its docs.
- [CONTESTED] — competent language designers disagree, publicly and permanently. Both cases given.
⚠️ GOTCHA boxes mark the design mistakes that are cheap to make on day one and impossible to undo on day one thousand.
The framing that organizes everything below: a language is a set of promises you can never take back. Syntax you can deprecate. Semantics you cannot. Every hard decision in this document is really the question "what am I willing to be permanently responsible for?" — and the languages people love and the languages people resent are distinguished mostly by how carefully their designers answered it early.
[DURABLE] Every serious compiler has at least three IR levels, because the transformations you want at each level need different information:
AST source-shaped. Names, sugar, full spans. For type checking & diagnostics.
↓ desugar, resolve
HIGH IR typed, desugared, still source-ish. For borrow checking, exhaustiveness,
source-level optimizations. (rustc: HIR → THIR)
↓ lower
MID IR explicit control flow (CFG), explicit memory ops, SSA. THE optimization IR.
(rustc: MIR · Swift: SIL · Go: SSA · LLVM IR)
↓ lower
LOW IR machine-shaped, target types, still virtual registers. (LLVM MachineIR)
↓
MACHINE CODE
The rule of thumb: lower when the information you're about to discard is no longer needed, and no sooner. Lowering too early loses the ability to give good errors and to do high-level optimizations; lowering too late means every pass has to handle sugar.
[DURABLE] SSA is the dominant mid-level IR form and has been since the early 1990s. Every variable is assigned exactly once; control-flow merges use φ (phi) functions.
entry:
x = 1 x₁ = 1
if c: x = 2 br c, then, join
y = x + 1 then:
x₂ = 2
br join
join:
x₃ = φ(x₁ from entry, x₂ from then)
y₁ = x₃ + 1
Why it matters: def-use chains are explicit and immediate, so constant propagation, dead code elimination, GVN, and register allocation all become dramatically simpler. You no longer need separate reaching-definitions analysis — SSA is that analysis, cached in the IR.
Construction: the classic algorithm is Cytron et al. (1991) using dominance frontiers to place φ-nodes. The modern practical alternative is Braun et al. (2013), "Simple and Efficient Construction of Static Single Assignment Form" — builds SSA directly during AST-to-IR translation without a separate dominance computation. If you're writing a compiler today, use Braun; it is far simpler and produces comparable results.
Destruction: φ-nodes aren't real instructions. Converting out of SSA means inserting copies on incoming edges, and doing it naively causes the lost-copy and swap problems. Sreedhar et al.'s method is the standard correct approach. This is where subtle miscompiles live.
[DURABLE] CPS/ANF/SSA are the same thing viewed differently. Appel's "SSA is Functional Programming" (1998) is the paper that makes this click: an SSA φ-node is a function parameter of a basic block, and a basic block is a continuation.
[VERSIONED] MLIR generalizes "have several IRs" into a framework: instead of one fixed IR, you define dialects — extensible sets of operations, types, and attributes — and write progressive lowering passes between them. A single module can hold operations from several dialects at once.
Why it matters: it's the substrate for the ML-compiler ecosystem (TensorFlow, IREE, Triton), for Mojo (Chris Lattner's language, explicitly built on MLIR), for Flang's OpenMP lowering, and increasingly for hardware-adjacent domains. It ships inside the LLVM monorepo, so it moves with LLVM's release train.
When MLIR is right: you have multiple abstraction levels, domain-specific optimizations, heterogeneous targets (CPU/GPU/accelerator), or you want to reuse a large pass and infrastructure ecosystem. When it isn't: a straightforward language targeting CPUs — MLIR's conceptual overhead and build weight are substantial, and plain LLVM IR is a much shorter path.
.ll format is the
reason LLVM is debuggable at all.language-diagnostics-tooling-and-evolution).| Category | Passes |
|---|---|
| Local / peephole | Constant folding, algebraic simplification, strength reduction, instruction combining |
| Data-flow | Constant propagation (SCCP), dead code elimination, common subexpression elimination, GVN, copy propagation |
| Control-flow | Branch folding, jump threading, block merging, tail duplication, loop rotation |
| Loop | LICM (loop-invariant code motion), unrolling, fusion/fission, interchange, strength reduction of induction variables, vectorization |
| Interprocedural | Inlining (the most important one), specialization, IPO/LTO, devirtualization, escape analysis |
| Memory | SROA/mem2reg (scalar replacement of aggregates — promoting memory to SSA registers), alias analysis, load/store forwarding |
| Layout | Basic-block placement, PGO-driven hot/cold splitting |
[DURABLE] The 80/20 of optimization is inlining plus mem2reg/SROA plus constant folding plus DCE. Inlining exposes opportunities for everything else — it's a meta-optimization. mem2reg turns naive stack-slot-per-variable codegen into real SSA, which is why a front end can emit dumb, obviously-correct code and still get fast output.
-O0 should be a genuinely
different, minimal pipeline, not the same pipeline with fewer passes.Modern systems do it at several levels, and it matters which:
language-runtimes-interpreters-and-jits).| Backend | Best for | Trade-offs |
|---|---|---|
| LLVM | Production compilers wanting best-in-class optimization and broad targets | Excellent codegen; slow compilation; a very large C++ dependency; API churn across versions |
| Cranelift | Fast compilation, JIT, WebAssembly, debug builds | Written in Rust; fast; less optimization than LLVM; used by Wasmtime and as rustc's alternative backend |
| GCC (libgccjit / gccrs-style frontend) | Targets LLVM doesn't support; GPL ecosystem | Fewer frontends use it; different integration model |
| Custom | Full control, no dependency, fast debug builds, unusual targets | You now own instruction selection, register allocation, and every target |
| WebAssembly | Portability, sandboxing, plugins | §7.5 |
| Transpile to C | Maximum portability, bootstrap | You inherit C's UB and lose debuggability |
| Bytecode + interpreter | Fastest path to a working language | Slow; see §9 → language-runtimes-interpreters-and-jits |
[VERSIONED — a live and instructive case study.] The LLVM-dependency question is being tested in public right now by two projects:
rustc_codegen_ssa.[DURABLE] The generalizable lesson: LLVM gives you world-class output slowly. If your
users' dominant pain is edit-compile-test latency rather than runtime performance, a
second, fast, dumb backend is a better investment than optimizing your LLVM usage — and
architecting for two backends from the start (as rustc did with rustc_codegen_ssa) is
much cheaper than retrofitting.
Map IR operations to target instructions. Approaches: macro expansion (one IR op → a fixed instruction sequence; simple, poor code), tree pattern matching with dynamic programming (Aho–Johnson / BURS / iburg; optimal per-tree), DAG-based (LLVM SelectionDAG — handles shared subexpressions), and GlobalISel (LLVM's newer IR-to-machine-IR framework, designed to be faster and more incremental than SelectionDAG).
[DURABLE] Optimal register allocation is NP-complete (it's graph colouring — Chaitin's 1981 reduction). The practical approaches:
| Algorithm | Notes |
|---|---|
| Linear scan | Fast, decent output. The right choice for a JIT or a debug-build backend. Poletto & Sarkar |
| Graph colouring (Chaitin–Briggs) | Better output, slower. Traditional AOT choice |
| SSA-based | Interference graphs of SSA programs are chordal, so colouring is polynomial. An elegant and increasingly common result worth knowing |
| PBQP | Partitioned boolean quadratic programming; handles irregular architectures |
The hard parts are always: spilling (choosing what to evict — usually by loop depth and next-use distance), coalescing (removing redundant moves without making the graph uncolourable), live-range splitting, and calling-convention and register-class constraints (which are far more of the real work than the colouring algorithm).
[DURABLE] The ABI is the hardest under-appreciated part of a back end, and getting it wrong produces bugs that only appear when crossing a language boundary. You must specify: calling convention (argument registers, stack layout, who cleans up), struct passing rules (by value in registers? by hidden pointer? the System V x86-64 classification algorithm is genuinely intricate), return values (including small aggregates), name mangling, stack alignment (16 bytes on x86-64 SysV — violate it and SSE code faults), varargs, exception unwinding tables, and TLS.
⚠️ GOTCHA — you cannot invent your own ABI and also interoperate. If you want C FFI (you do — §8.5 →
language-runtimes-interpreters-and-jits), you must implement the platform ABI exactly, including its ugly corners. Most new languages have at least one embarrassing "we passed a small struct wrong on Windows ARM64" bug.
[VERSIONED — this changed materially in 2026.] Wasm is a genuinely good compilation target: a stack machine with structured control flow, a linear memory, and strong sandboxing guarantees.
WASI 0.3.0 was released on 11 June 2026, and the change is architectural rather than
incremental: native async is moved down into the Component Model's canonical ABI, with
async func, stream<T>, and future<T> as primitives. The wasi:io package —
pollables, input-streams, output-streams — is removed entirely, absorbed into the
canonical ABI. The motivating problem is worth understanding because it's a general
lesson in interface design: under WASI 0.2, a pollable was a resource scoped to a single
component instance, so in a chain A→B→host, component B could not forward the host's
wake-ups to A and had to actively poll just to relay readiness. In 0.2 every component
needed its own event loop with no way to coordinate. Most 0.2→0.3 signature changes are
described as mechanical.
What this means for a language implementer: the Component Model plus WIT (the interface definition language) plus the canonical ABI turns Wasm from "a module with ad-hoc host glue" into a typed, language-agnostic service boundary — a component declares what it needs and provides, and the host or linker wires the edges. Bindings generators can now emit idiomatic async bindings per language. Wasmtime 45 ran the RC; Wasmtime 46 ships 0.3.0. A formally specified Component Model 1.0 is the next milestone, previewed at the Bytecode Alliance Plumbers Summit and Wasm I/O 2026.
The honest caveats, which the ecosystem states openly: WASI still has no native
multi-threading, which quietly rules out whole categories of compute-heavy server
workloads; WASI 1.0 is planned but not shipped; and adoption remains concentrated in
specific niches (edge functions, plugin systems) rather than general server compute —
Fermyon's edge platform and wasmCloud deployments are real, but they are chosen niches.
Note also that reporting on WASI versions is unusually inconsistent — you will find
sources in 2026 simultaneously describing 0.3 as "released," "in preview," and "the next
milestone." Check wasi.dev directly.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub the-vibey-project/vibey --plugin programming-language-development5 skills in this plugin
/language-design-parsing-and-typesUse when designing a language or building a compiler front end: the questions that determine everything else, the design principles that hold up, syntax; lexing, parsing approaches (recursive descent, Pratt, LR, generators), error recovery, CST vs AST; name resolution and modules; and type systems — the design space, inference (Hindley–Milner, bidirectional), unification and the occurs check, traits, type classes, and interfaces, generics (monomorphize or erase), ownership, borrowing, and linearity, the other static analyses, compile-time execution and metaprogramming, and effects. Includes the router for the whole programming-language-development reference./language-development-referenceUse when reviewing a language or compiler design for known anti-patterns, weighing contested questions (static vs dynamic typing, monomorphization vs erasure, GC vs ownership, async/await vs green threads, LLVM or not, Safe C++ vs Profiles, sea of nodes, batteries-included standard library, formal verification's cost/benefit, how much syntax novelty), checking whether a toolchain or language-version claim is still current (snapshot verified August 2026), finding the books, papers, and primary sources, or needing the build-it-in-order checklist, numbers, and compiler-bug triage. Companion to the other programming-language-development skills./language-diagnostics-tooling-and-evolutionUse when making a language usable and durable: what a good diagnostic contains and the rules for error messages, warnings, source locations; incremental compilation and IDE support (query-based compilation, salsa-style memoization, what the LSP needs from you); the compiler test pyramid and formal verification; standard library and ecosystem design; and language evolution — backward compatibility, editions as the best mechanism we have, governance (BDFL, committees, RFC processes), and multiple implementations./language-runtimes-interpreters-and-jitsUse when building a language runtime or execution engine. Covers memory management and garbage collection (tracing, generational, reference counting, ownership), the object model, concurrency models (threads, async/await, green threads, actors), errors and unwinding, FFI, the interpreter performance ladder, interpreter techniques worth knowing (bytecode design, dispatch, inline caching), JIT compilation (baseline and optimizing tiers, tracing, deoptimization), and the bootstrapping and trust problem.Other plugins' skills for the same job