Can LTO optimize across functions?


It is not clear to me in the clang LTO documentation. Can the
optimization across multiple functions? For example, if a function
turns better to be inlined, will it be inlined? Or if some basicblocks
are the same between functions, will multiple functions use the same
basic block. Thanks.

ThinLTO (as well as regular aka "full" LTO) essentially expand the
scope of the optimizer through link time optimization techniques. So
interprocedural optimizations (IPO) such as inlining functions into
callsites which without LTO would be restricted to the Module (or
Translation Unit) scope, now can be performed across code that was
from different Translation Units (originally different Modules). LTO
also enables some more aggressive whole program optimizations that
aren't available without whole program scope (e.g. whole program dead
stripping, internalization, etc).

Hope that helps.