-
-
Notifications
You must be signed in to change notification settings - Fork 264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add LTO support (full and thin), with -flto=thin|full
.
#1840
Conversation
Yes, using clang's options seems like the obvious choice.
Only have a vague idea what this fthinlto-index option is, also see [ThinLTO] Option to invoke ThinLTO backend passes and importing. |
|
||
unsigned char opt = optLevel(); | ||
static char optChars[15] = "-plugin-opt=O0"; | ||
optChars[13] = '0' + (opt & 0x03); // the plugin O-level ranges from 0 to 3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you considered just making this min(optLevel(), 3)
? -O4
and -O5
are currently documented as being equal to -O3
, and it doesn't seem like resetting to 0
resp. 1
would be intuitive for these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How stupid, thanks for catching this bug. Trying to optimize something that doesn't need optimizing.
namespace { | ||
|
||
std::string getLTOGoldPluginPath() { | ||
// TODO: cmdline option for plugin path, or in ldc.conf? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Command-line option which can then be set from ldc2.conf? ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to self: the plugin path is also useful for OS X.
@MartinNowak See http://blog.llvm.org/2016/06/thinlto-scalable-and-incremental-lto.html for -fthinlto-index . I'm leaving that out for now. |
afa648b
to
fece3f9
Compare
Bug : When there are module ctors/dtors in different modules, not all of them are run :( Edit: I think I found the cause. There is a latent bug in our llvm.used emission. ThinLTO is very aggressively optimizing and thus things break. Working on a fix. (edit: #1855) Edit2: nice! With that fix, I managed to build LDC with LTO, mixing C++ and D LTO! In other words: cross-language cross-module inlining. |
Pretty cool. :) |
e9e291e
to
756fd59
Compare
LTO testing is now enabled on CircleCI |
Any concerns before I merge this? |
LTO needs linker support: I am only aware of support on OS X and Linux (through the LLVMgold plugin). Resolves ldc-developers#693
Merging when green. |
LTO needs linker support: I am only aware of support on OS X and Linux (through the LLVMgold plugin).
I chose the cmdline option
flto=thin|full
that mimics Clang's option (also Martin was looking forflto
in the issue #693 he reported).Resolves #693 .
For OS X, additional logic could be added later to point to a newer libLTO.dylib (see clang'sDone: addeddarwin::Linker::AddLinkArgs
).flto-binary
for that purpose. Also, CMake installs LLVM's LTO libs when it can find them; the LTO lib is installed in LDC's /lib/, and that's the first path searched when adding LTO linker flags.