about summary refs log tree commit diff
path: root/src/librustc_trans
AgeCommit message (Collapse)AuthorLines
2017-10-08Auto merge of #45012 - Gankro:noalias, r=arielb1bors-1/+12
Add -Zmutable-noalias flag We disabled noalias on mutable references a long time ago when it was clear that llvm was incorrectly handling this in relation to unwinding edges. Since then, a few things have happened: * llvm has cleaned up a bunch of the issues (I'm told) * we've added a nounwind codegen option As such, I would like to add this -Z flag so that we can evaluate if the codegen bugs still exist, and if this significantly affects the codegen of different projects, with an eye towards permanently re-enabling it (or at least making it a stable option).
2017-10-07rustc: Don't inline in CGUs at -O0Alex Crichton-81/+129
This commit tweaks the behavior of inlining functions into multiple codegen units when rustc is compiling in debug mode. Today rustc will unconditionally treat `#[inline]` functions by translating them into all codegen units that they're needed within, marking the linkage as `internal`. This commit changes the behavior so that in debug mode (compiling at `-O0`) rustc will instead only translate `#[inline]` functions into *one* codegen unit, forcing all other codegen units to reference this one copy. The goal here is to improve debug compile times by reducing the amount of translation that happens on behalf of multiple codegen units. It was discovered in #44941 that increasing the number of codegen units had the adverse side effect of increasing the overal work done by the compiler, and the suspicion here was that the compiler was inlining, translating, and codegen'ing more functions with more codegen units (for example `String` would be basically inlined into all codegen units if used). The strategy in this commit should reduce the cost of `#[inline]` functions to being equivalent to one codegen unit, which is only translating and codegen'ing inline functions once. Collected [data] shows that this does indeed improve the situation from [before] as the overall cpu-clock time increases at a much slower rate and when pinned to one core rustc does not consume significantly more wall clock time than with one codegen unit. One caveat of this commit is that the symbol names for inlined functions that are only translated once needed some slight tweaking. These inline functions could be translated into multiple crates and we need to make sure the symbols don't collideA so the crate name/disambiguator is mixed in to the symbol name hash in these situations. [data]: https://github.com/rust-lang/rust/issues/44941#issuecomment-334880911 [before]: https://github.com/rust-lang/rust/issues/44941#issuecomment-334583384
2017-10-07rustc: Implement ThinLTOAlex Crichton-132/+634
This commit is an implementation of LLVM's ThinLTO for consumption in rustc itself. Currently today LTO works by merging all relevant LLVM modules into one and then running optimization passes. "Thin" LTO operates differently by having more sharded work and allowing parallelism opportunities between optimizing codegen units. Further down the road Thin LTO also allows *incremental* LTO which should enable even faster release builds without compromising on the performance we have today. This commit uses a `-Z thinlto` flag to gate whether ThinLTO is enabled. It then also implements two forms of ThinLTO: * In one mode we'll *only* perform ThinLTO over the codegen units produced in a single compilation. That is, we won't load upstream rlibs, but we'll instead just perform ThinLTO amongst all codegen units produced by the compiler for the local crate. This is intended to emulate a desired end point where we have codegen units turned on by default for all crates and ThinLTO allows us to do this without performance loss. * In anther mode, like full LTO today, we'll optimize all upstream dependencies in "thin" mode. Unlike today, however, this LTO step is fully parallelized so should finish much more quickly. There's a good bit of comments about what the implementation is doing and where it came from, but the tl;dr; is that currently most of the support here is copied from upstream LLVM. This code duplication is done for a number of reasons: * Controlling parallelism means we can use the existing jobserver support to avoid overloading machines. * We will likely want a slightly different form of incremental caching which integrates with our own incremental strategy, but this is yet to be determined. * This buys us some flexibility about when/where we run ThinLTO, as well as having it tailored to fit our needs for the time being. * Finally this allows us to reuse some artifacts such as our `TargetMachine` creation, where all our options we used today aren't necessarily supported by upstream LLVM yet. My hope is that we can get some experience with this copy/paste in tree and then eventually upstream some work to LLVM itself to avoid the duplication while still ensuring our needs are met. Otherwise I fear that maintaining these bindings may be quite costly over the years with LLVM updates!
2017-10-06incr.comp.: Bring back output of -Zincremental-info.Michael Woerister-7/+3
2017-10-05Auto merge of #45019 - aidanhs:aphs-no-trans-worker-panic, r=alexcrichtonbors-13/+6
Don't unwrap work item results as the panic trace is useless Fixes #43402 now there's no multithreaded panic printouts Also update a comment -------- Likely regressed in #43506, where the code was changed to panic in worker threads on error. Unwrapping gives zero extra information since the stack trace is so short, so we may as well just surface that there was an error and exit the thread properly. Because there are then no multithreaded printouts, I think it should mean the output of the test for #26199 is deterministic and not interleaved (thanks to @philipc https://github.com/rust-lang/rust/issues/43402#issuecomment-333835271 for a hint). Sadly the output is now: ``` thread '<unnamed>' panicked at 'aborting due to worker thread panic', src/librustc_trans/back/write.rs:1643:20 note: Run with `RUST_BACKTRACE=1` for a backtrace. error: could not write output to : No such file or directory error: aborting due to previous error ``` but it's an improvement over the multi-panic situation before. r? @alexcrichton
2017-10-04rustc: Don't create empty codegen unitsAlex Crichton-12/+0
This'll end up just creating a bunch of object files that otherwise wouldn't exist, so skip that extra work if possible.
2017-10-05rustc_trans: do not set NoCapture for anonymous lifetime &T arguments.Eduard-Mihai Burtescu-10/+1
2017-10-04Make -Cpanic=abort imply -Zmutable-noaliasAlexis Beingessner-1/+3
2017-10-04Auto merge of #44901 - michaelwoerister:on-demand-eval, r=nikomatsakisbors-182/+120
incr.comp.: Switch to red/green change tracking, remove legacy system. This PR finally switches incremental compilation to [red/green tracking](https://github.com/rust-lang/rust/issues/42293) and completely removes the legacy dependency graph implementation -- which includes a few quite costly passes that are simply not needed with the new system anymore. There's still some documentation to be done and there's certainly still lots of optimizing and tuning ahead -- but the foundation for red/green is in place with this PR. This has been in the making for a long time `:)` r? @nikomatsakis cc @alexcrichton, @rust-lang/compiler
2017-10-04Don't unwrap work item results as the panic trace is uselessAidan Hobson Sayers-13/+6
Fixes #43402 now there's no multithreaded panic printouts Also update a comment
2017-10-03Add -Zmutable-noalias flagAlexis Beingessner-1/+10
2017-10-03Auto merge of #44896 - qmx:move-resolve-to-librustc, r=arielb1bors-125/+45
Move monomorphize::resolve() to librustc this moves `monomorphize::resolve(..)` to librustc, and re-enables inlining for some trait methods, fixing #44389 @nikomatsakis I've kept the calls to the new `ty::Instance::resolve(....)` always `.unwrap()`-ing for the moment, how/do you want to add more debugging info via `.unwrap_or()` or something like this? we still have some related `resolve_*` functions on monomorphize, but I wasn't sure moving them was into the scope for this PR too. @eddyb mind to take a look too?
2017-10-03incr.comp.: Fix some merge fallout.Michael Woerister-2/+0
2017-10-02incr.comp.: Do some cleanup.Michael Woerister-2/+0
2017-10-02incr.comp.: Use red/green tracking for CGU re-use.Michael Woerister-180/+109
2017-10-02incr.comp.: Re-execute queries during red/green marking in order to find out ↵Michael Woerister-0/+13
their color.
2017-10-01stray commaDouglas Campos-1/+1
2017-10-01Auto merge of #44906 - dkl:main-signature, r=nagisabors-6/+23
Fix native main() signature on 64bit Hello, in LLVM-IR produced by rustc on x86_64-linux-gnu, the native main() function had incorrect types for the function result and argc parameter: i64, while it should be i32 (really c_int). See also #20064, #29633. So I've attempted a fix here. I tested it by checking the LLVM IR produced with --target x86_64-unknown-linux-gnu and i686-unknown-linux-gnu. Also I tried running the tests (`./x.py test`), however I'm getting two failures with and without the patch, which I'm guessing is unrelated.
2017-09-30weird formattingDouglas Campos-2/+2
2017-09-30rustc: Specify c_int width for each targetDaniel Klauer-1/+6
(all i32 for now, as in liblibc)
2017-09-30rustc: Enable LTO and multiple codegen unitsAlex Crichton-412/+719
This commit is a refactoring of the LTO backend in Rust to support compilations with multiple codegen units. The immediate result of this PR is to remove the artificial error emitted by rustc about `-C lto -C codegen-units-8`, but longer term this is intended to lay the groundwork for LTO with incremental compilation and ultimately be the underpinning of ThinLTO support. The problem here that needed solving is that when rustc is producing multiple codegen units in one compilation LTO needs to merge them all together. Previously only upstream dependencies were merged and it was inherently relied on that there was only one local codegen unit. Supporting this involved refactoring the optimization backend architecture for rustc, namely splitting the `optimize_and_codegen` function into `optimize` and `codegen`. After an LLVM module has been optimized it may be blocked and queued up for LTO, and only after LTO are modules code generated. Non-LTO compilations should look the same as they do today backend-wise, we'll spin up a thread for each codegen unit and optimize/codegen in that thread. LTO compilations will, however, send the LLVM module back to the coordinator thread once optimizations have finished. When all LLVM modules have finished optimizing the coordinator will invoke the LTO backend, producing a further list of LLVM modules. Currently this is always a list of one LLVM module. The coordinator then spawns further work to run LTO and code generation passes over each module. In the course of this refactoring a number of other pieces were refactored: * Management of the bytecode encoding in rlibs was centralized into one module instead of being scattered across LTO and linking. * Some internal refactorings on the link stage of the compiler was done to work directly from `CompiledModule` structures instead of lists of paths. * The trans time-graph output was tweaked a little to include a name on each bar and inflate the size of the bars a little
2017-09-29fix formattingDouglas Campos-4/+9
2017-09-29style fixes as requested by @eddybDouglas Campos-9/+9
2017-09-29stop using monomorphize::resolve()Douglas Campos-125/+40
2017-09-29Auto merge of #44853 - alexcrichton:debug-codegen-units, r=michaelwoeristerbors-6/+11
rustc: Default 32 codegen units at O0 This commit changes the default of rustc to use 32 codegen units when compiling in debug mode, typically an opt-level=0 compilation. Since their inception codegen units have matured quite a bit, gaining features such as: * Parallel translation and codegen enabling codegen units to get worked on even more quickly. * Deterministic and reliable partitioning through the same infrastructure as incremental compilation. * Global rate limiting through the `jobserver` crate to avoid overloading the system. The largest benefit of codegen units has forever been faster compilation through parallel processing of modules on the LLVM side of things, using all the cores available on build machines that typically have many available. Some downsides have been fixed through the features above, but the major downside remaining is that using codegen units reduces opportunities for inlining and optimization. This, however, doesn't matter much during debug builds! In this commit the default number of codegen units for debug builds has been raised from 1 to 32. This should enable most `cargo build` compiles that are bottlenecked on translation and/or code generation to immediately see speedups through parallelization on available cores. Work is being done to *always* enable multiple codegen units (and therefore parallel codegen) but it requires #44841 at least to be landed and stabilized, but stay tuned if you're interested in that aspect!
2017-09-28rustc: Fix main() entry point signature on 64bitDaniel Klauer-6/+14
To match the C signature, main() should be generated with C int type for the argc parameter and result, i.e. i32 instead of i64 on 64bit. That way it no longer relies on the upper 32 bits being zero, which I'm not sure is guaranteed by ABIs or startup code.
2017-09-28rustc: Add Type::c_int()Daniel Klauer-0/+4
Add c_int for use in the compiler, assuming i32 for all targets as in libc.
2017-09-28Update to the `cc` crateAlex Crichton-3/+3
This is the name the `gcc` crate has moved to
2017-09-26Auto merge of #44741 - qmx:trans_fulfill_obligation_should_not_crash, ↵bors-2/+4
r=nikomatsakis use param_env on the trait_cache key We bailed from making trans_fulfill_obligation return `Option` or `Result`, just made it less prone to crashing outside trans r? @nikomatsakis
2017-09-26rustc: Default 32 codegen units at O0Alex Crichton-6/+11
This commit changes the default of rustc to use 32 codegen units when compiling in debug mode, typically an opt-level=0 compilation. Since their inception codegen units have matured quite a bit, gaining features such as: * Parallel translation and codegen enabling codegen units to get worked on even more quickly. * Deterministic and reliable partitioning through the same infrastructure as incremental compilation. * Global rate limiting through the `jobserver` crate to avoid overloading the system. The largest benefit of codegen units has forever been faster compilation through parallel processing of modules on the LLVM side of things, using all the cores available on build machines that typically have many available. Some downsides have been fixed through the features above, but the major downside remaining is that using codegen units reduces opportunities for inlining and optimization. This, however, doesn't matter much during debug builds! In this commit the default number of codegen units for debug builds has been raised from 1 to 32. This should enable most `cargo build` compiles that are bottlenecked on translation and/or code generation to immediately see speedups through parallelization on available cores. Work is being done to *always* enable multiple codegen units (and therefore parallel codegen) but it requires #44841 at least to be landed and stabilized, but stay tuned if you're interested in that aspect!
2017-09-25Auto merge of #44085 - bjorn3:no_llvm_write_metadata, r=arielb1bors-113/+65
Allow writing metadata without llvm # Todo: * [x] Rebase * [x] Fix eventual errors * [x] <strike>Find some crate to write elf files</strike> (will do it later) Cc #43842
2017-09-25fix tidy errorsDouglas Campos-2/+4
2017-09-25expose ParamEnv as a paramDouglas Campos-2/+2
2017-09-23incr.comp.: Serialize and deserialize new DepGraphMichael Woerister-2/+1
2017-09-23Fix some tests with no llvm buildbjorn3-15/+1
2017-09-23Fix for upstream changesbjorn3-9/+13
2017-09-23Merge rustc_trans_trait into rustc_trans_utilsbjorn3-3/+1
2017-09-23Add TransCrate traitbjorn3-0/+56
2017-09-23Fix rustc_trans_utils::find_exported_symbolsbjorn3-53/+1
Fix denied warnings
2017-09-23Allow building stage 2 compiler librariesbjorn3-40/+5
2017-09-23Allow writing metadata without llvmbjorn3-9/+4
2017-09-22Auto merge of #44696 - michaelwoerister:fingerprints-in-dep-graph-3, ↵bors-14/+13
r=nikomatsakis incr.comp.: Move task result fingerprinting into DepGraph. This PR - makes the DepGraph store all `Fingerprints` of task results, - allows `DepNode` to be marked as input nodes, - makes HIR node hashing use the regular fingerprinting infrastructure, - removes the now unused `IncrementalHashesMap`, and - makes sure that `traits_in_scope_map` fingerprints are stable. r? @nikomatsakis cc @alexcrichton
2017-09-20Auto merge of #44707 - GuillaumeGomez:rollup, r=arielb1bors-0/+12
Rollup of 5 pull requests - Successful merges: #44513, #44626, #44689, #44693, #44703 - Failed merges:
2017-09-20incr.comp.: Remove IncrementalHashesMap and calculate_svh module.Michael Woerister-14/+13
2017-09-19Rollup merge of #44626 - MaulingMonkey:lld-link-natvis-regression-fix, ↵Guillaume Gomez-0/+12
r=michaelwoerister Skip passing /natvis to lld-link until supported. ### Overview Teaching rustc about MSVC's undocumented linker flag, /NATVIS, broke rustc's compatability with LLVM's `lld-link` frontend, as it does not recognize the flag. This pull request works around the problem by excluding `lld-link` by name. @retep998 discovered this regression. ### Possible Issues - Other linkers that try to be compatible with the MSVC linker flavor may also be broken and in need of workarounds. - Warning about the workaround may be overkill for a minor reduction in debug functionality. - Depending on how long this workaround sticks around, it may eventually be preferred to version check `lld-link` instead of assuming all versions are incompatible. ### Relevant issues * Broke in https://github.com/rust-lang/rust/pull/43221 Embed MSVC .natvis files into .pdbs and mangle debuginfo for &str, *T, and [T]. * LLVM patched in https://github.com/llvm-mirror/lld/commit/27b9c4285364d8d76bb43839daa100c2f80f8329 to ignore the flag instead of erroring. r? @michaelwoerister
2017-09-19rework the README.md for rustc and add other readmesNiko Matsakis-1/+7
This takes way longer than I thought it would. =)
2017-09-18Rollup merge of #44364 - michaelwoerister:hash-all-the-things2, r=nikomatsakisAlex Crichton-30/+56
incr.comp.: Compute fingerprint for all query results. This PR enables query result fingerprinting in incremental mode. This is an essential piece of infrastructure for red/green tracking. We don't do anything with the fingerprints yet but merging the infrastructure should protect it from bit-rotting and will make it easier to start measuring its performance impact (and thus let us determine if we should switch to a faster hashing algorithm rather sooner than later). Note, this PR also includes the changes from https://github.com/rust-lang/rust/pull/43887 which I'm therefore closing. No need to re-review the first commit though. r? @nikomatsakis
2017-09-18incr.comp.: Fix ICE caused by trying to hash INVALID_CRATE_NUM.Michael Woerister-18/+15
2017-09-18incr.comp.: Fix rebase fallout.Michael Woerister-21/+7
2017-09-18incr.comp.: Remove tcx from StableHashingContext.Michael Woerister-2/+2