IT lexicon › Programming › Basic block placement

Basic block placement

Programming På svenska → Updated: 2026-11-07

Choosing the order in which a function's basic blocks are laid out in memory, so the common path falls straight through without taking a single jump.

A control-flow graph has no order, but machine code does: one of a branch's two targets has to sit right after it, and the other is reached by a jump. Taken jumps cost something — a redirected fetch, another entry in the branch predictor, often a fresh cache line. Using frequencies from block frequency analysis or a profile, the compiler chains blocks so hot successors sit next to each other and cold blocks drift to the end.

Karl Pettis and Robert Hansen described the greedy chain-merging approach in 1990, and it's still the foundation. Later work cast the problem as a variant of the travelling salesman problem, ext-TSP, which accounts for short forward jumps being cheaper than long ones. LLVM lays out blocks using such a model, and BOLT redoes the job after linking with real measurements. Where hot/cold splitting moves cold code out of the function entirely, block placement arranges what's left.

← Back to the lexicon