Link-time code generation (LTCG) enables cross source-file optimization by delaying code generation until the link stage. This can significantly reduce code size. To enable LTCG, compile your source with -c --ltcg to create objects in an intermediate format.
Whether something is inline or not is part of code generation. That's the compiler's job. Ergo, inlining is done at compile time.
The linker can inline small functions in place of a branch instruction to that function. For the linker to be able to do this, the function (without the return instruction) must fit in the four bytes of the branch instruction.
An inline function is one for which the compiler copies the code from the function definition directly into the code of the calling function rather than creating a separate set of instructions in memory. This eliminates call-linkage overhead and can expose significant optimization opportunities.
Up till a while a ago my code base was very close to #include
hell. Every time I changed an even mildly important .h file practically all the files got recompiled.
The main reason for such high header dependency was that I have many small functions that need to be inline and I was under the impression that for inline to work they need to be in the same translation unit as the calling code, so they need to be in the header. For the inline function to even compile other headers need to be included in the header as well, ad infimum.
Enter link-time code generation (in Visual Studio). One of the main stated advantages of this is that now inline function can cross translation units.
But I'm still iffy. How can I really be sure that these functions really get inlined? I realize that the compiler can basically do whatever the hell it wants no matter where I define the function.
Is there a way to check what gets inlined?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With