Link-time optimisation (LTO)

Johan Engelen j at j.nl
Fri Mar 30 11:07:37 UTC 2018


On Friday, 30 March 2018 at 10:23:15 UTC, Cecil Ward wrote:
> Say that I use say GDC or LDC. I want to declare a routine as 
> public in one compilation unit (.d src file) and be able to 
> access it from other compilation units.
>
> Do I simply declare the routine with the word keyword public 
> before the usual declaration?
>
> Or maybe that is the default, like not using the keyword static 
> with function declarations in C?

Global functions in a module have default "public" visibility 
indeed.
https://dlang.org/spec/attribute.html#visibility_attributes

> My principal question: If I successfully do this, with GCC or 
> LDC, will I be able to get the code for the externally defined 
> short routine expanded inline and fully integrated into the 
> generated code that corresponds to the calling source code? (So 
> no ‘call’ instruction is even found.)

What you want is "cross-module inlining".
As far as I know, DMD and GDC will do cross-module inlining (if 
inlining is profitable).

LDC does not, unless `-enable-cross-module-inlining` is enabled 
(which is aggressive and may result in linking errors in specific 
cases, https://github.com/ldc-developers/ldc/pull/1737).
LDC with LTO enabled will definitely give you cross-module 
inlining (also for private functions).

You can force inlining with `pragma(inline, true)`, but it is 
usually better to leave that decision up to the compiler.
https://dlang.org/spec/pragma.html#inline

-Johan




More information about the Digitalmars-d-learn mailing list