Thread overview
Link-time optimisation (LTO)
Mar 30, 2018
Cecil Ward
Mar 30, 2018
Johan Engelen
Mar 31, 2018
Kagamin
March 30, 2018
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?

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.)
March 30, 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


March 31, 2018
On Friday, 30 March 2018 at 10:23:15 UTC, Cecil Ward wrote:
> 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.)

If you compile for lto, ldc compiles code to IR and linker generates machine code from IR with inlining, at the IR level most information about source code is lost, only the actual code remains, declarations are purely source code items. But it only inline IR code, machine code can't be inlined.