The Tempo team shows how to specialize a C function around an input it already knows. Their example is a tiny printf that parses a format string on every call. Fix the format at <%d,%d> and the generated function can go straight to printing two integers and the punctuation.
- First, Tempo traces which operations depend on known inputs. In C, that means checking whether pointers share storage and whether a call can change a value elsewhere.
- Then it uses the actual input values to generate a function that does only the remaining work. One analysis can produce versions for several different format strings.
- Tempo can generate C at build time or machine code at runtime. If the format becomes known after startup, the program can specialize the formatter then and reuse it across calls.
Look for inputs that stay fixed across many calls. If a hot loop keeps parsing the same format or making the same dispatch decision, try preparing that work once. For generated code, measure whether the repeated calls pay back the cost of generating and storing each version.