HomeAlgorithms & AIRegister Allocation via Graph Coloring (2D)

Register Allocation via Graph Coloring (2D)

Interactive 2D interference-graph simulator: watch a compiler's Chaitin simplify/select register-allocation algorithm run over a live planar spring-electrical graph embedding, with configurable physical registers, virtual register count and interference density.

Algorithms & AI2DAdvanced60 FPS📱 Mobile-adapted⇄ 3D version
2d-graph-coloring-register-allocation ↗ Open standalone

Compilers cannot give every variable its own physical register — CPUs only have a handful (K), while a function may juggle dozens of live values. The classic solution, due to Chaitin, models the problem as graph coloring: build an interference graph where virtual registers that are live at the same time are connected, then try to K-color it so connected registers get different physical registers. This 2D simulator runs the real simplify/select algorithm — repeatedly stripping low-degree, guaranteed-colorable nodes onto a stack, optimistically spilling when none remain, then popping the stack and assigning the lowest free color — over a live planar spring-electrical graph embedding computed entirely in two dimensions, so denser or larger graphs visibly tangle and cross the way a true planar layout must, distinct from a free-floating 3D embedding of the same graph. Adjust K, graph size and density to see how allocation pressure changes both the colouring outcome and how crowded the flattened layout becomes.

⚙ Under the hood

Interactive 2D interference-graph simulator: watch a compiler's Chaitin simplify/select register-allocation algorithm run over a live planar spring-electrical graph embedding, with configurable physical registers, virtual register count and interference density.

compilersgraph-coloringregister-allocationalgorithmschaitindata-structuresforce-directed-layout

2D · HTML5 Canvas 2D · 60 FPS target · runs fully client-side, no install

What did you find?

Add reproduction steps (optional)