Master the fundamental concepts of compiler optimization techniques through this focused micro-challenge.
You have read the whole brief, and the concepts above stay free on every task. Writing and running the code needs a plan.
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
Every task includes starter code, theory, and hidden tests so you can implement and verify locally in the browser.
How it worksLink-Time Optimization (LTO) stores LLVM bitcode or GCC GIMPLE in .o files and runs optimization when linking. Cross-module inlining and devirtualization become possible. Chrome and Rust release builds rely on thin LTO for large link times.
Clang: -flto=thin at compile and link. GCC: -flto plus use gcc driver for the final link. Static libraries must be built with LTO objects too.
bashLoading…
-g at LTO link for usable stacksnm symbol counts before/after cross-module inlineKeep the relevant documentation open while you implement. When your output disagrees with the reference, trace one failing case by hand before changing random lines.
You will build a two-file project with and without LTO and measure call overhead across translation units. This exercise asks you to show one function inlined only in the LTO build.
Without link-time optimisation, each .c file is compiled on its own. The compiler can inline only functions whose bodies are in the same file, and it must keep every non-static function because some other object file might call it. With LTO, the whole program is optimised at once, so small functions inline across files, and anything main can no longer reach is deleted. Model both builds and compare code size and the number of call instructions left.
cLoading…
static function of the same unit if one exists, otherwise to the non-static function with that name. An unresolved name prints undefined reference to NAME (from CALLER) and link failed, and so does a missing non-static main (undefined reference to main).caller += callee - 5.main alone (with LTO).cLoading…
Each kept function's call count includes the calls inside bodies inlined into it. Kept and removed functions are listed in definition order (removed: none if nothing was removed). A func before any unit prints func NAME: no unit.
Input:
cLoading…
Output:
cLoading…
Hidden tests cover a static helper inlined within its own file, an inlined body that still calls a large function, recursion (never inlined), a raised and a zero threshold, an unreachable exported function (only LTO removes it), same-named static functions in two units, and undefined references.