about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src
AgeCommit message (Collapse)AuthorLines
2023-07-31Remove unnecessary semicolon.Nicholas Nethercote-1/+1
2023-07-31Clean up `generate_lto_work`.Nicholas Nethercote-22/+23
This function has some shared code for the thin LTO and fat LTO cases, but those cases have so little in common that it's actually clearer to treat them fully separately.
2023-07-31Fix LLVM thread names on Windows.Nicholas Nethercote-3/+3
PR #112946 tweaked the naming of LLVM threads, but messed things up slightly, resulting in threads on Windows having names like `optimize module {} regex.f10ba03eb5ec7975-cgu.0`. This commit removes the extraneous `{} `.
2023-07-31Introduce `running_with_any_token` closure.Nicholas Nethercote-7/+10
It makes things a little clearer.
2023-07-31Use standard Rust capitalization rules for names containing "LTO".Nicholas Nethercote-11/+11
2023-07-31Tweak structure of the message loop.Nicholas Nethercote-17/+20
The main loop has a *very* complex condition, which includes two mentions of `codegen_state`. The body of the loop then immediately switches on the `codegen_state`. I find it easier to understand if it's a `loop` and we check for exit conditions after switching on `codegen_state`. We end up with a tiny bit of code duplication, but it's clear that (a) we never exit in the `Ongoing` case, (b) we exit in the `Completed` state only if several things are true (and there's interaction with LTO there), and (c) we exit in the `Aborted` state if a couple of things are true. Also, the exit conditions are all simple conjunctions.
2023-07-31Tweak a loop condition.Nicholas Nethercote-7/+11
This loop condition involves `codegen_state`, `work_items`, and `running_with_own_token`. But the body of the loop cannot modify `codegen_state`, so repeatedly checking it is unnecessary.
2023-07-31Move `maybe_start_llvm_timer`'s body into `spawn_work`.Nicholas Nethercote-26/+18
The two functions are alway called together. This commit factors out the repeated code.
2023-07-31Remove `CodegenContext::worker`.Nicholas Nethercote-24/+12
`CodegenContext` is immutable except for the `worker` field - we clone `CodegenContext` in multiple places, changing the `worker` field each time. It's simpler to move the `worker` field out of `CodegenContext`.
2023-07-31Remove `ExtraBackendMethods::spawn_thread`.Nicholas Nethercote-9/+0
It's no longer used, and `spawn_named_thread` is preferable, because naming threads is helpful when profiling.
2023-07-31Give the coordinator thread a name.Nicholas Nethercote-3/+4
This is useful when profiling with a profiler like Samply.
2023-07-31Remove some unused values in `codegen_crate`.Nicholas Nethercote-3/+0
2023-07-31Remove an unnecessary `pub`.Nicholas Nethercote-1/+1
2023-07-31Rename `MainThreadWorkerState`.Nicholas Nethercote-25/+25
The `Worker` is unnecessary, and just makes it longer than necessary.
2023-07-31Rename things related to the main thread's operations.Nicholas Nethercote-30/+46
It took me some time to understand how the main thread can lend a jobserver token to an LLVM thread. This commit renames a couple of things to make it clearer. - Rename the `LLVMing` variant as `Lending`, because that is a clearer description of what is happening. - Rename `running` as `running_with_own_token`, which makes it clearer that there might be one additional LLVM thread running (with a loaned token). Also add a comment to its definition.
2023-07-31Add some assertions.Nicholas Nethercote-0/+4
- Thin and fat LTO can't happen together. - `NeedsLink` and (non-allocator) `Compiled` work item results can't happen together.
2023-07-31Add comments to `WorkItemResult`.Nicholas Nethercote-4/+14
And rename the `Compiled` variant as `Finished`, because that name makes it clearer there is nothing left to do, contrasting nicely with the `Needs*` variants.
2023-07-31Inline and remove `submit_pre_codegened_module_to_llvm`.Nicholas Nethercote-15/+9
It has a single callsite, and provides little value.
2023-07-30inline format!() args up to and including rustc_codegen_llvmMatthias Krüger-82/+75
2023-07-29cg_ssa: remove pointee types and pointercast/bitcast-of-ptrErik Desjardins-169/+44
2023-07-27Rollup merge of #113872 - nnethercote:tweak-cgu-sorting, r=pnkfelixMatthias Krüger-2/+3
Tweak CGU sorting in a couple of places. In `base.rs`, tweak how the CGU size interleaving works. Since #113777, it's much more common to have multiple CGUs with identical sizes. With the existing code these same-sized items ended up in the opposite-to-desired order due to the stable sorting. The code now starts with a reverse sort (like is done in `partitioning.rs`) which gives the behaviour we want. This doesn't matter much for perf, but makes profiles in `samply` look more like what we expect. In `partitioning.rs`, we can use `sort_by_key` instead of `sort_by_cached_key` because `CGU::size_estimate()` is cheap. (There is an identical CGU sort earlier in that function that already uses `sort_by_key`.) r? `@pnkfelix`
2023-07-25Use a builder instead of boolean/option argumentsOli Scherer-1/+1
2023-07-23remove redundant clonesMatthias Krüger-1/+1
2023-07-23Auto merge of #111836 - calebzulawski:target-feature-closure, r=workingjubileebors-1/+16
Fix #[inline(always)] on closures with target feature 1.1 Fixes #108655. I think this is the most obvious solution that isn't overly complicated. The comment includes more justification, but I think this is likely better than demoting the `#[inline(always)]` to `#[inline]`, since existing code is unaffected.
2023-07-21Auto merge of #113892 - RalfJung:uninit-undef-poison, r=wesleywiserbors-0/+6
clarify MIR uninit vs LLVM undef/poison In [this LLVM discussion](https://discourse.llvm.org/t/rfc-load-instruction-uninitialized-memory-semantics/67481) I learned that mapping our uninitialized memory in MIR to poison in LLVM would be quite problematic due to the lack of a byte type. I am not sure where to write down this insight but this seems like a reasonable start.
2023-07-21Rollup merge of #113780 - dtolnay:printkindpath, r=b-naberMatthias Krüger-13/+56
Support `--print KIND=PATH` command line syntax As is already done for `--emit KIND=PATH` and `-L KIND=PATH`. In the discussion of #110785, it was pointed out that `--print KIND=PATH` is nicer than trying to apply the single global `-o` path to `--print`'s output, because in general there can be multiple print requests within a single rustc invocation, and anyway `-o` would already be used for a different meaning in the case of `link-args` and `native-static-libs`. I am interested in using `--print cfg=PATH` in Buck2. Currently Buck2 works around the lack of support for `--print KIND=PATH` by [indirecting through a Python wrapper script](https://github.com/facebook/buck2/blob/d43cf3a51a31f00be2c2248e78271b0fef0452b4/prelude/rust/tools/get_rustc_cfg.py) to redirect rustc's stdout into the location dictated by the build system. From skimming Cargo's usages of `--print`, it definitely seems like it would benefit from `--print KIND=PATH` too. Currently it is working around the lack of this by inserting `--crate-name=___ --print=crate-name` so that it can look for a line containing `___` as a delimiter between the 2 other `--print` informations it actually cares about. This is commented as a "HACK" and "abuse". https://github.com/rust-lang/cargo/blob/31eda6f7c360d9911f853b3014e057db61238f3e/src/cargo/core/compiler/build_context/target_info.rs#L242 (FYI `@weihanglo` as you dealt with this recently in https://github.com/rust-lang/cargo/pull/11633.) Mentioning reviewers active in #110785: `@fee1-dead` `@jyn514` `@bjorn3`
2023-07-21Rollup merge of #113723 - khei4:khei4/llvm-stats, r=oli-obk,nikicMatthias Krüger-0/+5
Resurrect: rustc_llvm: Add a -Z `print-codegen-stats` option to expose LLVM statistics. This resurrects PR https://github.com/rust-lang/rust/pull/104000, which has sat idle for a while. And I want to see the effect of stack-move optimizations on LLVM (like https://reviews.llvm.org/D153453) :). I have applied the changes requested by `@oli-obk` and `@nagisa` https://github.com/rust-lang/rust/pull/104000#discussion_r1014625377 and https://github.com/rust-lang/rust/pull/104000#discussion_r1014642482 in the latest commits. r? `@oli-obk` ----- LLVM has a neat [statistics](https://llvm.org/docs/ProgrammersManual.html#the-statistic-class-stats-option) feature that tracks how often optimizations kick in. It's very handy for optimization work. Since we expose the LLVM pass timings, I thought it made sense to expose the LLVM statistics too. ----- (Edit: fix broken link (Edit2: fix segmentation fault and use malloc If `rustc` is built with ```toml [llvm] assertions = true ``` Then you can see like ``` rustc +stage1 -Z print-codegen-stats -C opt-level=3 tmp.rs ===-------------------------------------------------------------------------=== ... Statistics Collected ... ===-------------------------------------------------------------------------=== 3 aa - Number of MayAlias results 193 aa - Number of MustAlias results 531 aa - Number of NoAlias results ... ``` And the current default build emits only ``` $ rustc +stage1 -Z print-codegen-stats -C opt-level=3 tmp.rs ===-------------------------------------------------------------------------=== ... Statistics Collected ... ===-------------------------------------------------------------------------=== $ ``` This might be better to emit the message to tell assertion flag necessity, but now I can't find how to do that...
2023-07-20Add note about writing native-static-libs to fileDavid Tolnay-1/+12
2023-07-20Implement printing to file for link-args and native-static-libsDavid Tolnay-10/+22
2023-07-20Implement printing to file in llvm_utilDavid Tolnay-1/+3
2023-07-20Implement printing to file in codegen_backend.printDavid Tolnay-2/+20
2023-07-20Store individual output file name with every PrintRequestDavid Tolnay-4/+4
2023-07-20clarify MIR uninit vs LLVM undef/poisonRalf Jung-0/+6
2023-07-20Rollup merge of #113529 - oli-obk:simd_shuffle_evaluated, r=wesleywiserMatthias Krüger-1/+15
Permit pre-evaluated constants in simd_shuffle fixes https://github.com/rust-lang/rust/issues/113500
2023-07-20Auto merge of #113695 - bjorn3:fix_rlib_cdylib_metadata_handling, ↵bors-13/+7
r=pnkfelix,petrochenkov Verify that all crate sources are in sync This ensures that rustc will not attempt to link against a cdylib as if it is a rust dylib when an rlib for the same crate is available. Previously rustc didn't actually check if any further formats of a crate which has been loaded are of the same version and if they are actually valid. This caused a cdylib to be interpreted as rust dylib as soon as the corresponding rlib was loaded. As cdylibs don't export any rust symbols, linking would fail if rustc decides to link against the cdylib rather than the rlib. Two crates depended on the previous behavior by separately compiling a test crate as both rlib and dylib. These have been changed to capture their original spirit to the best of my ability while still working when rustc verifies that all crates are in sync. It is unlikely that build systems depend on the current behavior and in any case we are taking a lot of measures to ensure that any change to either the source or the compilation options (including crate type) results in rustc rejecting it as incompatible. We merely didn't do this check here for now obsolete perf reasons. Fixes https://github.com/rust-lang/rust/issues/10786 Fixes https://github.com/rust-lang/rust/issues/82151 Fixes https://github.com/rust-lang/rust/issues/82972 Closes https://github.com/bevy-cheatbook/bevy-cheatbook/issues/114
2023-07-20Monomorphize constants before inspecting themOli Scherer-1/+1
2023-07-20Auto merge of #108714 - estebank:ice_dump, r=oli-obkbors-1/+1
On nightly, dump ICE backtraces to disk Implement rust-lang/compiler-team#578. When an ICE is encountered on nightly releases, the new rustc panic handler will also write the contents of the backtrace to disk. If any `delay_span_bug`s are encountered, their backtrace is also added to the file. The platform and rustc version will also be collected. <img width="1032" alt="Screenshot 2023-03-03 at 2 13 25 PM" src="https://user-images.githubusercontent.com/1606434/222842420-8e039740-4042-4563-b31d-599677171acf.png"> The current behavior will *always* write to disk on nightly builds, regardless of whether the backtrace is printed to the terminal, unless the environment variable `RUSTC_ICE_DISK_DUMP` is set to `0`. This is a compromise and can be changed.
2023-07-20Tweak CGU sorting in a couple of places.Nicholas Nethercote-2/+3
In `base.rs`, tweak how the CGU size interleaving works. Since #113777, it's much more common to have multiple CGUs with identical sizes. With the existing code these same-sized items ended up in the opposite-to-desired order due to the stable sorting. The code now starts with a reverse sort (like is done in `partitioning.rs`) which gives the behaviour we want. This doesn't matter much for perf, but makes profiles in `samply` look more like what we expect. In `partitioning.rs`, we can use `sort_by_key` instead of `sort_by_cached_key` because `CGU::size_estimate()` is cheap. (There is an identical CGU sort earlier in that function that already uses `sort_by_key`.)
2023-07-19Rollup merge of #113716 - DianQK:add-no_builtins-to-function, r=pnkfelixDylan DPC-1/+9
Add the `no-builtins` attribute to functions when `no_builtins` is applied at the crate level. **When `no_builtins` is applied at the crate level, we should add the `no-builtins` attribute to each function to ensure it takes effect in LTO.** This is also the reason why no_builtins does not take effect in LTO as mentioned in #35540. Now, `#![no_builtins]` should be similar to `-fno-builtin` in clang/gcc, see https://clang.godbolt.org/z/z4j6Wsod5. Next, we should make `#![no_builtins]` participate in LTO again. That makes sense, as LTO also takes into consideration function-level instruction optimizations, such as the MachineOutliner. More importantly, when a user writes a large `#![no_builtins]` crate, they would like this crate to participate in LTO as well. We should also add a function-level no_builtins attribute to allow users to have more control over it. This is similar to Clang's `__attribute__((no_builtin))` feature, see https://clang.godbolt.org/z/Wod6KK6eq. Before implementing this feature, maybe we should discuss whether to support more fine-grained control, such as `__attribute__((no_builtin("memcpy")))`. Related discussions: - #109821 - #35540 Next (a separate pull request?): - [ ] Revert #35637 - [ ] Add a function-level `no_builtin` attribute?
2023-07-19Fix review commentsbjorn3-7/+7
2023-07-19Don't compress dylib metadatabjorn3-8/+2
2023-07-19On nightly, dump ICE backtraces to diskEsteban Küber-1/+1
Implement rust-lang/compiler-team#578. When an ICE is encountered on nightly releases, the new rustc panic handler will also write the contents of the backtrace to disk. If any `delay_span_bug`s are encountered, their backtrace is also added to the file. The platform and rustc version will also be collected.
2023-07-18Add the `no-builtins` attribute to functions when `no_builtins` is applied ↵DianQK-1/+9
at the crate level. When `no_builtins` is applied at the crate level, we should add the `no-builtins` attribute to each function to ensure it takes effect in LTO.
2023-07-18support for mips32r6 as a target_arch valuechenx97-2/+2
2023-07-18merge patternschenx97-2/+1
2023-07-18support for mips64r6 as a target_arch valuechenx97-1/+2
2023-07-18Permit pre-evaluated constants in simd_shuffleOli Scherer-0/+14
2023-07-17Introduce `MonoItemData`.Nicholas Nethercote-3/+3
It replaces `(Linkage, Visibility)`, making the code nicer. Plus the next commit will add another field.
2023-07-16rustc_llvm: Add a `-Z print-llvm-stats` option to expose LLVM statistics.Patrick Walton-0/+5
LLVM has a neat [statistics] feature that tracks how often optimizations kick in. It's very handy for optimization work. Since we expose the LLVM pass timings, I thought it made sense to expose the LLVM statistics too. [statistics]: https://llvm.org/docs/ProgrammersManual.html#the-statistic-class-stats-option
2023-07-16Auto merge of #113626 - Urgau:dedup-native-static-libs, r=petrochenkovbors-0/+5
De-duplicate consecutive libs when printing native-static-libs This PR adds a de-duplicate step just before printing the `native-static-libs`. This step de-duplicates all the consecutive libs based only on the relevant comparison elements (this exclude spans, ast elements, ...). Fixes https://github.com/rust-lang/rust/issues/113209