HomeComputer ScienceRegister Allocation: Graph Coloring Visualizer

Register Allocation: Graph Coloring Visualizer

Watch a compiler back end allocate physical registers to a small program: build the interference graph from real liveness analysis, then run Chaitin's simplify/select graph-coloring algorithm live, spilling a register when no color is left.

Computer Science3DAdvanced60 FPS
compiler-design ↗ Open standalone

Every compiler back end faces the same problem: source code implies an unlimited number of temporary values, but the target CPU has only a handful of physical registers. This simulator runs the classic Chaitin-style solution end to end and shows every step in 3D. First a real backward liveness analysis walks a small three-address-code program to find which virtual registers are simultaneously alive; any two that are alive at the same time become an edge in an interference graph. The allocator then simplifies that graph — repeatedly removing low-degree nodes onto a stack, or optimistically removing a high-degree one when stuck — and finally pops the stack to assign each register the lowest free color among its already-colored neighbours, marking a node red when no physical register is left and it has to spill to memory. Change the program, the number of physical registers, and the playback speed to see exactly when and why a compiler is forced to spill.

⚙ Under the hood

Build the interference graph of a small compiled program from real liveness analysis, then watch Chaitin's simplify/select graph-coloring algorithm assign physical registers step by step in real time -- spilling one to memory whenever it runs out of colors.

Three.jscompilersregister allocationgraph coloringliveness analysisInstancedMesh

3D · Three.js / WebGL renderer · 60 FPS target · runs fully client-side, no install

What did you find?

Add reproduction steps (optional)