Code generation and JIT compilation
Problems
- Instruction scheduling
Order the instructions of a block or region so that dependences and machine resources are respected and the run time is least.
core - Instruction selection
Cover the IR of a program with patterns of target machine instructions so that the total cost of the chosen instructions is least.
core - Register allocation
Assign the values of a program to a fixed number of machine registers, storing the rest in memory at least cost.
core - Register coalescing
Merge the nodes of copy-related values in the interference graph to remove copies, while keeping the graph colorable; NP-complete in general.
advanced
Algorithms
- Maximal munch instruction selection
Tiles an expression tree top-down by always choosing the largest pattern that matches at the root, then tiling the subtrees.
1 languagesintro - Aho-Johnson dynamic programming code generation
Computes, bottom-up, the cheapest cost of each subtree for every number of free registers and for memory, then emits code that stores whole subtrees only where that is cheaper.
1 languagescore - Chaitin register allocation
Simplifies the interference graph by removing nodes of degree less than k, spills when none is left, and colors in reverse order.
1 languagescore - Iterated register coalescing
Interleaves simplification with conservative coalescing of move-related nodes and freezes moves when stuck, removing many copies safely.
1 languagescore - Linear scan register allocation
Sorts live intervals by start and assigns registers in one pass, spilling the interval that ends last when registers run out.
1 languagescore - Local register allocation
Allocates registers in one basic block in order, and when none is free spills the value whose next use is farthest away.
1 languagescore - Optimistic coloring
Pushes a spill candidate on the stack instead of spilling it at once and spills only if no color is free when it is popped.
1 languagescore - Sethi-Ullman algorithm
Labels each node of an expression tree with the fewest registers that evaluate it, then emits code that evaluates the child with the larger label first and stores only when registers run out.
1 languagescore - Bottom-up rewrite system
Precomputes the dynamic programming of optimal tree tiling into tables, so a code generator labels each node by table lookup.
1 languagesadvanced - Iterative modulo scheduling
Software pipelines a loop by trying initiation intervals from a lower bound up, placing operations in a modulo reservation table with backtracking.
1 languagesadvanced - Superblock scheduling
Forms traces with one entry by tail duplication and schedules each as a block, with no compensation code at side entries.
1 languagesadvanced - Trace scheduling
Schedules a likely path through several blocks as one block and adds compensation code where other paths enter or leave it.
1 languagesadvanced - Copy-and-patch compilation
Generates code very fast by copying precompiled binary stencils for each operation and patching holes with operands and addresses.
1 languagesresearch - Linear scan register allocation on SSA form
Runs linear scan directly on SSA form with lifetime intervals and resolves phi-functions after allocation, without leaving SSA first.
1 languagesresearch - SSA-based register allocation
Spills until register pressure is at most k everywhere, then colors the chordal SSA interference graph with no further spills.
1 languagesresearch
Data structures
- Activation record
The block of stack memory for one call of a procedure, with its arguments, return address, saved registers and local variables.
1 languagesintro - Hidden classes
Shared descriptors of object layout for dynamic languages, so that objects with the same fields have fixed offsets for fast access.
1 languagesadvanced - Polymorphic inline cache
An inline cache that holds several receiver types and their targets at a call site, and records the types seen for later optimization.
1 languagesadvanced
Techniques
- Inline caching
Caches at each call site the receiver type and method found last time and checks the type on the next call before using it.
core - Software pipelining
Overlaps iterations of a loop so that a new iteration starts before the previous ends, with a prologue, steady kernel and epilogue.
core - Spill code placement
Keeps a value in memory and inserts stores after its definitions and loads before its uses when it cannot have a register.
core - Threaded code
Represents an interpreted program as a list of addresses of routines, each ending with a jump to the next, to cut dispatch cost.
core - Adaptive optimization
Starts in an interpreter or quick compiler and recompiles methods with more optimization as profiles show them to be hot.
advanced - Conservative coalescing
Coalesces two nodes only when a degree test proves that the merged graph stays as colorable as before.
advanced - Deoptimization
Falls back from optimized code to the interpreter or less optimized code when a speculative assumption fails, rebuilding the frames.
advanced - Live range splitting
Splits the live range of a value into pieces with copies between them, so each piece can get its own register or be spilled.
advanced - On-stack replacement
Moves a running method from one compiled version to another in the middle of its execution, by mapping the live state of its frame.
advanced - Register rematerialization
Recomputes a spilled value that is cheap to compute, such as a constant, instead of reloading it from memory.
advanced - Tracing JIT compilation
Records the operations of a hot loop path as a linear trace, optimizes it with guards for exits, and compiles it to machine code.
advanced - Type feedback
Uses the receiver types recorded by inline caches to inline the likely targets of dynamic calls when recompiling hot code.
advanced - Meta-tracing
Traces the interpreter that runs a user program instead of the program, so a JIT compiler is derived from an annotated interpreter.
research - Self-optimizing AST interpreter
An AST interpreter whose nodes rewrite themselves to specialized forms from observed types, then are compiled by partial evaluation.
research
Concepts
- Just-in-time compilation
Compiles code while the program runs, so the compiler can use the actual types, values and profile seen so far.
intro
Definitions
- Interference graph
An undirected graph with one vertex per name of a program and an edge between two names that cannot share a register, because one is live where the other is defined.
core
Theorems
- NP-completeness of register allocation
Every graph is the interference graph of some program, so deciding whether a program fits in k registers, each name keeping one register, is NP-complete for every fixed k >= 3.
core - Chordality of SSA interference graphs
The interference graph of a strict SSA program is chordal, so it is colored optimally in polynomial time and its clique size gives the bound.
advanced - NP-completeness of code generation for DAGs
Generating optimal code for an expression DAG on a register machine is NP-complete, unlike for trees.
advanced