-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Support LTO #10741
Comments
cc @thestinger |
I have this implemented, but there's a few caveats. First, right now our linkage model makes it such that LTO is only a reasonable option for a staticlib and binary output. This doesn't make sense for rlibs or for dylibs. This also means that when running LTO, it requires all upstream dependencies to be available as rlibs. This is how I implemented it:
Optimization-wise, this appears to work as well as one would expect. I got Sadly this comes with a caveat, and that caveat is that this is about the slowest possible thing the compiler can do. Here's a breakdown of the timing:
The total runtime of the compiler was 9.655s. Remember that the program in question is I don't think that this means we shouldn't have LTO support, but we would seriously need to look into optimizing this. This is an absurd runtime. If we could in theory make loading the bc libraries and preparing the new rlib libraries have 0 runtime (we can certainly optimize them more than I implemented), we're still looking at at least an 8s runtime. What do others think about this? Did I make a fundamental misdirection somewhere? Is this actually a reasonable runtime for an LTO optimization? As reference, my work in progress can be found at alexcrichton@e5416c8 |
@alexcrichton I tried running that branch locally (x64 linux), and I met with:
in linking. (Also, how did you get those fine grained numbers?) |
I used a bit of an ad-hoc method to get those numbers (manual instrumentation with the I think I fixed that problem in alexcrichton@2ba6426, although I'm a little scared that it ran successfully on OSX in the first place... |
@alexcrichton: The individual crates are supposed to be somewhat optimized (not the full regular module pass) before the final LTO pass. Look at what |
Interesting! I was hoping to avoid a "compile this library for LTO-enabled linkage" flag, but perhaps that may end up being inevitable. Sadly though I don't think that it will help the compile times at all (it'll probably just end up slowing them down a little with more optimizations being run at the end). |
[`large_stack_arrays`]: check array initializer expressions Fixes rust-lang#10741. Prior to this PR, the lint only checked array repeat expressions (ie. `[T; n]`). Now it also checks array initializer expressions. changelog: [`large_stack_arrays`]: check array initializer expressions
A "static rust library" is simply just an 'rlib' file, which in turns is just an
ar
archive. Right now the archive includes thecrate.o
and all native static dependencies. There's no reason that this file couldn't also includecrate.bc
to allow for LTO.I would imagine that a
--lto
option would be specified when creating an executable and for when creating a dynamic library (I don't think this makes sense for static libraries?). When--lto
is specified, then we don't load thebc
files from all of the upstreamrlib
archives and throw it all into LLVM, then we tell LLVM to run its LTO passes.Basically this would mean perhaps shoving more things into
rlib
archives by default (need to make sure that using rlib files still works), and then implementing the--lto
option to load thebc
files from archives.Note that native libraries should all still "just work" to the greatest extent possible.
Not quite an easy bug, but certainly an interesting project!
The text was updated successfully, but these errors were encountered: