What: a new pass, spirv::outline, runs on every module after rolling and hoisting. It finds a set
of regions of one function that are the same code (one sequence of the function's spine, loop
bodies included; entered only at the start and left only at the end), each of at least 500
instructions with a call of a kept routine counting one, writes the first as a new kept routine
(Function::kept, declared DontInline, the form ModuleBuilder::kept_routine makes) and replaces
every region with a call of it, then looks again, at most 64 times. Values from before a region
are parameters (one per distinct set of the regions' values; a constant that differs only where
any value may stand); a pointer parameter is a Function, Private, Workgroup or UniformConstant
variable itself or a PhysicalStorageBuffer pointer; values read after a region are the routine's
results (several in a struct). A Function variable only its region uses becomes the routine's
own where the region is in no loop or its first use stores the whole variable in a block the
region always runs; otherwise it is passed. Anything else that differs keeps the regions in line.
Candidates come from the spine's keys (16-item windows hashed, extended both ways); a set whose
exact comparison fails at an operand or result is compared again without that item. The spine
(roll::spine) takes a flag to walk loop bodies as sequences; rolling passes false and is
unchanged. SEMANTICS_VERSION 2259. API.md and ARCHITECTURE.md say the routines exist.
Why: NVIDIA's driver compiles a DontInline routine once and Mesa's drivers inline it either way.
On the RTX 3090 (620.70.06, job m3-max-64453) a generated kernel calling a 1,984-instruction
function from 50 places was created in 21.5 s inlined and 52 ms as a kept routine (51.8 s and
75 ms with 64 values live across every call); its dispatch GPU time was the same with few values
live and 20.6% lower as a routine with 64 live. A 497-instruction function: 0.1% and 19.7% lower.
500 is the smallest size measured within 3%. RADV and ANV (Mesa 26.2.6) compiled identical code
for the call, DontInline and inlined forms (jobs m3-max-64357, m3-max-64379).
How verified: spirv::outline::tests build kernels with three equal regions (a variable, a
selection's phi, a counting loop), a chain where each region reads the previous one's result, a
middle region that differs, and two regions in a loop whose accumulator is read before it is
written; each checks the routine and call counts, the module through the verifier and spirv-val,
and the words the interpreter writes against the unrewritten module's and the expected ones.