Thread overview
ThinLTO on OS X!
Sep 27, 2016
Johan Engelen
Sep 27, 2016
Johan Engelen
Sep 27, 2016
Johan Engelen
Oct 07, 2016
Marco Leise
Oct 07, 2016
Johan Engelen
Oct 26, 2016
Johan Engelen
September 27, 2016
Hi all,
  The new XCode 8 features LLVM's ThinLTO in the linker. With some patching in LDC, I got it to work pretty easily. The result:

<file b.d>
```
extern(C) void doesNothing() {}
```

<file a.d>
```
extern(C) void doesNothing(); // declaration only

void main() {
    for (ulong i = 0; i < 100_000_000; ++i) {
        doesNothing();
    }
}
```

Separate compilation:
> ../bin/ldc2 -c b.d -O3 -of=b.o
> ../bin/ldc2 a.d b.o -of=a -O3
> time ./a
./a  1.77s user 0.01s system 98% cpu 1.802 total

Separate compilation with ThinLTO:
> ../bin/ldc2 -c b.d -O3 -of=bthin.o -thinlto
> ../bin/ldc2 a.d bthin.o -of=athin -O3 -thinlto
> time ./athin
./athin  0.00s user 0.00s system 61% cpu 0.006 total

BAM!

PR incoming.

I'd like your input for the commandline flag name.


September 27, 2016
On Tuesday, 27 September 2016 at 18:52:46 UTC, Johan Engelen wrote:
> Hi all,
>   The new XCode 8 features LLVM's ThinLTO in the linker.

For more information: http://blog.llvm.org/2016/06/thinlto-scalable-and-incremental-lto.html

September 27, 2016
On Tuesday, 27 September 2016 at 18:52:46 UTC, Johan Engelen wrote:
> 
> PR incoming.

https://github.com/ldc-developers/ldc/pull/1793

October 07, 2016
Does this mean that separate and incremental compilation will now produce the same optimal code as all-at-once compilation? In other words, do we no longer have to do all-at-once compilation to get minimal file size or optimal code gen?

-- 
Marco

October 07, 2016
On Friday, 7 October 2016 at 15:42:08 UTC, Marco Leise wrote:
> Does this mean that separate and incremental compilation will now produce the same optimal code as all-at-once compilation? In other words, do we no longer have to do all-at-once compilation to get minimal file size or optimal code gen?

Yes, almost.
http://blog.llvm.org/2016/06/thinlto-scalable-and-incremental-lto.html

(note: it's still work-in-progress, I'm slowly tackling problems as they arise)
October 26, 2016
On Tuesday, 27 September 2016 at 18:52:46 UTC, Johan Engelen wrote:
> Hi all,
>   The new XCode 8 features LLVM's ThinLTO in the linker. With some patching in LDC, I got it to work pretty easily.

A brief update.

So there were a number of issues to be straightened out, some in LDC, some in LLVM, but now I think things are starting to look good for LTO :)

What is super cool is that when you have mixed C++/D source, and are using Clang/LDC, you get cross-language inlining with LTO! ^_^

<file b.cpp>
```
void doesNothing() {}
```

<file a.d>
```
extern(C++) void doesNothing(); // declaration only

void main() {
    for (ulong i = 0; i < 100_000_000; ++i) {
        doesNothing();
    }
}
```

The runtime is zero of the program when using `flto=thin` for both clang and LDC.
Without LTO, it takes a few seconds.

cheers,
  Johan