about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src
AgeCommit message (Collapse)AuthorLines
2023-06-15Fix comment for ptr alignment checks in codegenNilstrieb-1/+1
2023-06-15Remap dylib paths into the sysroot to be relative to the sysrootdanakj-16/+22
Like for rlibs, the paths on the linker command line need to be relative paths if the sysroot was specified by the user to be a relative path. Dylibs put the path in /LIBPATH instead of into the file path of the library itself, so we rehome the libpath and adjust the rehoming function to be able to support both use cases, rlibs and dylibs.
2023-06-14Move the comment on fixing paths to where it belongsdanakj-3/+2
2023-06-14Avoid absolute sysroot paths in the MSVC linker command linedanakj-2/+27
When the `--sysroot` is specified as relative to the current working directory, the sysroot's rlibs should also be specified as relative paths. Otherwise, the current working directory ends up in the absolute paths, and in the linker command line. And the entire linker command line appears in the PDB file generated by the MSVC linker. When adding an rlib to the linker command line, if the rlib's canonical path is in the sysroot's canonical path, then use the current sysroot path + filename instead of the full absolute path to the rlib. This means that when `--sysroot=foo` is specified, the linker command line will contain `foo/rustlib/target/lib/lib*.rlib` instead of the full absolute path to the same. This addresses https://github.com/rust-lang/rust/issues/112586
2023-06-14Introduce a minimum CGU size in non-incremental builds.Nicholas Nethercote-3/+3
Because tiny CGUs make compilation less efficient *and* result in worse generated code. We don't do this when the number of CGUs is explicitly given, because there are times when the requested number is very important, as described in some comments within the commit. So the commit also introduces a `CodegenUnits` type that distinguishes between default values and user-specified values. This change has a roughly neutral effect on walltimes across the rustc-perf benchmarks; there are some speedups and some slowdowns. But it has significant wins for most other metrics on numerous benchmarks, including instruction counts, cycles, binary size, and max-rss. It also reduces parallelism, which is good for reducing jobserver competition when multiple rustc processes are running at the same time. It's smaller benchmarks that benefit the most; larger benchmarks already have CGUs that are all larger than the minimum size. Here are some example before/after CGU sizes for opt builds. - html5ever - CGUs: 16, mean size: 1196.1, sizes: [3908, 2992, 1706, 1652, 1572, 1136, 1045, 948, 946, 938, 579, 471, 443, 327, 286, 189] - CGUs: 4, mean size: 4396.0, sizes: [6706, 3908, 3490, 3480] - libc - CGUs: 12, mean size: 35.3, sizes: [163, 93, 58, 53, 37, 8, 2 (x6)] - CGUs: 1, mean size: 424.0, sizes: [424] - tt-muncher - CGUs: 5, mean size: 1819.4, sizes: [8508, 350, 198, 34, 7] - CGUs: 1, mean size: 9075.0, sizes: [9075] Note that CGUs of size 100,000+ aren't unusual in larger programs.
2023-06-12loongarch: Fix ELF header flagsWANG Rui-2/+13
2023-06-10Support 128-bit enum variant in debuginfo codegenDonoughLiu-0/+1
2023-06-09Auto merge of #111626 - pjhades:output, r=b-naberbors-7/+46
Write to stdout if `-` is given as output file With this PR, if `-o -` or `--emit KIND=-` is provided, output will be written to stdout instead. Binary output (those of type `obj`, `llvm-bc`, `link` and `metadata`) being written this way will result in an error unless stdout is not a tty. Multiple output types going to stdout will trigger an error too, as they will all be mixded together. This implements https://github.com/rust-lang/compiler-team/issues/431 The idea behind the changes is to introduce an `OutFileName` enum that represents the output - be it a real path or stdout - and to use this enum along the code paths that handle different output types.
2023-06-08Auto merge of #112415 - GuillaumeGomez:rollup-5pa9frd, r=GuillaumeGomezbors-5/+7
Rollup of 9 pull requests Successful merges: - #112034 (Migrate `item_opaque_ty` to Askama) - #112179 (Avoid passing --cpu-features when empty) - #112309 (bootstrap: remove dependency `is-terminal`) - #112388 (Migrate GUI colors test to original CSS color format) - #112389 (Add a test for #105709) - #112392 (Fix ICE for while loop with assignment condition with LHS place expr) - #112394 (Remove accidental comment) - #112396 (Track more diagnostics in `rustc_expand`) - #112401 (Don't `use compile_error as print`) r? `@ghost` `@rustbot` modify labels: rollup
2023-06-08Rollup merge of #112179 - tamird:no-empty-cpu-features, r=petrochenkovGuillaume Gomez-5/+7
Avoid passing --cpu-features when empty Added in 12ac719b99560072cbe52a957f22d3fe6946cf2a, this logic always passed --cpu-features, even when the value was the empty string.
2023-06-08Auto merge of #110040 - ndrewxie:issue-84447-partial-1, r=lcnr,michaelwoeristerbors-6/+6
Removed use of iteration through a HashMap/HashSet in rustc_incremental and replaced with IndexMap/IndexSet This allows for the `#[allow(rustc::potential_query_instability)]` in rustc_incremental to be removed, moving towards fixing #84447 (although a LOT more modules have to be changed to fully resolve it). Only HashMaps/HashSets that are being iterated through have been modified (although many structs and traits outside of rustc_incremental had to be modified as well, as they had fields/methods that involved a HashMap/HashSet that would be iterated through) I'm making a PR for just 1 module changed to test for performance regressions and such, for future changes I'll either edit this PR to reflect additional modules being converted, or batch multiple modules of changes together and make a PR for each group of modules.
2023-06-07Auto merge of #111698 - Amanieu:force-static-lib, r=petrochenkovbors-4/+34
Force all native libraries to be statically linked when linking a static binary Previously, `#[link]` without an explicit `kind = "static"` would confuse the linker and end up producing a dynamically linked library because of the `-Bdynamic` flag. However this binary would not work correctly anyways since it was linked with startup code for a static binary. This PR solves this by forcing all native libraries to be statically linked when the output is a static binary that cannot link to dynamic libraries anyways. Fixes #108878 Fixes #102993
2023-06-07Force all native libraries to be statically linked when linking a static binaryAmanieu d'Antras-4/+34
2023-06-07wasm exception handlingJan-Mirko Otter-6/+28
2023-06-07add commentJan-Mirko Otter-0/+9
2023-06-07wasm target feature: exception handlingJan-Mirko Otter-0/+1
2023-06-06Write to stdout if `-` is given as output fileJing Peng-7/+46
If `-o -` or `--emit KIND=-` is provided, output will be written to stdout instead. Binary output (`obj`, `llvm-bc`, `link` and `metadata`) being written this way will result in an error unless stdout is not a tty. Multiple output types going to stdout will trigger an error too, as they will all be mixded together.
2023-06-06Auto merge of #111999 - scottmcm:codegen-less-memcpy, r=compiler-errorsbors-1/+35
Use `load`+`store` instead of `memcpy` for small integer arrays I was inspired by #98892 to see whether, rather than making `mem::swap` do something smart in the library, we could update MIR assignments like `*_1 = *_2` to do something smarter than `memcpy` for sufficiently-small types that doing it inline is going to be better than a `memcpy` call in assembly anyway. After all, special code may help `mem::swap`, but if the "obvious" MIR can just result in the correct thing that helps everything -- other code like `mem::replace`, people doing it manually, and just passing around by value in general -- as well as makes MIR inlining happier since it doesn't need to deal with all the complicated library code if it just sees a couple assignments. LLVM will turn the short, known-length `memcpy`s into direct instructions in the backend, but that's too late for it to be able to remove `alloca`s. In general, replacing `memcpy`s with typed instructions is hard in the middle-end -- even for `memcpy.inline` where it knows it won't be a function call -- is hard [due to poison propagation issues](https://rust-lang.zulipchat.com/#narrow/stream/187780-t-compiler.2Fwg-llvm/topic/memcpy.20vs.20load-store.20for.20MIR.20assignments/near/360376712). So because we know more about the type invariants -- these are typed copies -- rustc can emit something more specific, allowing LLVM to `mem2reg` away the `alloca`s in some situations. #52051 previously did something like this in the library for `mem::swap`, but it ended up regressing during enabling mir inlining (https://github.com/rust-lang/rust/commit/cbbf06b0cd39dc93033568f1e65f5363cbbdebcd), so this has been suboptimal on stable for ≈5 releases now. The code in this PR is narrowly targeted at just integer arrays in LLVM, but works via a new method on the [`LayoutTypeMethods`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_codegen_ssa/traits/trait.LayoutTypeMethods.html) trait, so specific backends based on cg_ssa can enable this for more situations over time, as we find them. I don't want to try to bite off too much in this PR, though. (Transparent newtypes and simple things like the 3×usize `String` would be obvious candidates for a follow-up.) Codegen demonstrations: <https://llvm.godbolt.org/z/fK8hT9aqv> Before: ```llvm define void `@swap_rgb48_old(ptr` noalias nocapture noundef align 2 dereferenceable(6) %x, ptr noalias nocapture noundef align 2 dereferenceable(6) %y) unnamed_addr #1 { %a.i = alloca [3 x i16], align 2 call void `@llvm.lifetime.start.p0(i64` 6, ptr nonnull %a.i) call void `@llvm.memcpy.p0.p0.i64(ptr` noundef nonnull align 2 dereferenceable(6) %a.i, ptr noundef nonnull align 2 dereferenceable(6) %x, i64 6, i1 false) tail call void `@llvm.memcpy.p0.p0.i64(ptr` noundef nonnull align 2 dereferenceable(6) %x, ptr noundef nonnull align 2 dereferenceable(6) %y, i64 6, i1 false) call void `@llvm.memcpy.p0.p0.i64(ptr` noundef nonnull align 2 dereferenceable(6) %y, ptr noundef nonnull align 2 dereferenceable(6) %a.i, i64 6, i1 false) call void `@llvm.lifetime.end.p0(i64` 6, ptr nonnull %a.i) ret void } ``` Note it going to stack: ```nasm swap_rgb48_old: # `@swap_rgb48_old` movzx eax, word ptr [rdi + 4] mov word ptr [rsp - 4], ax mov eax, dword ptr [rdi] mov dword ptr [rsp - 8], eax movzx eax, word ptr [rsi + 4] mov word ptr [rdi + 4], ax mov eax, dword ptr [rsi] mov dword ptr [rdi], eax movzx eax, word ptr [rsp - 4] mov word ptr [rsi + 4], ax mov eax, dword ptr [rsp - 8] mov dword ptr [rsi], eax ret ``` Now: ```llvm define void `@swap_rgb48(ptr` noalias nocapture noundef align 2 dereferenceable(6) %x, ptr noalias nocapture noundef align 2 dereferenceable(6) %y) unnamed_addr #0 { start: %0 = load <3 x i16>, ptr %x, align 2 %1 = load <3 x i16>, ptr %y, align 2 store <3 x i16> %1, ptr %x, align 2 store <3 x i16> %0, ptr %y, align 2 ret void } ``` still lowers to `dword`+`word` operations, but has no stack traffic: ```nasm swap_rgb48: # `@swap_rgb48` mov eax, dword ptr [rdi] movzx ecx, word ptr [rdi + 4] movzx edx, word ptr [rsi + 4] mov r8d, dword ptr [rsi] mov dword ptr [rdi], r8d mov word ptr [rdi + 4], dx mov word ptr [rsi + 4], cx mov dword ptr [rsi], eax ret ``` And as a demonstration that this isn't just `mem::swap`, a `mem::replace` on a small array (since replace doesn't use swap since #83022), which used to be `memcpy`s in LLVM changes in IR ```llvm define void `@replace_short_array(ptr` noalias nocapture noundef sret([3 x i32]) dereferenceable(12) %0, ptr noalias noundef align 4 dereferenceable(12) %r, ptr noalias nocapture noundef readonly dereferenceable(12) %v) unnamed_addr #0 { start: %1 = load <3 x i32>, ptr %r, align 4 store <3 x i32> %1, ptr %0, align 4 %2 = load <3 x i32>, ptr %v, align 4 store <3 x i32> %2, ptr %r, align 4 ret void } ``` but that lowers to reasonable `dword`+`qword` instructions still ```nasm replace_short_array: # `@replace_short_array` mov rax, rdi mov rcx, qword ptr [rsi] mov edi, dword ptr [rsi + 8] mov dword ptr [rax + 8], edi mov qword ptr [rax], rcx mov rcx, qword ptr [rdx] mov edx, dword ptr [rdx + 8] mov dword ptr [rsi + 8], edx mov qword ptr [rsi], rcx ret ```
2023-06-05Auto merge of #107583 - EsmeYi:aix_xcoff_metadata, r=bjorn3bors-11/+140
Support the rustc metadata for AIX Support the rustc metadata for rlibs and dylibs on AIX. XCOFF is the object file format on AIX.
2023-06-05Address @bjorn3's comments.Esme Yi-1/+3
2023-06-04Removed use of iteration through a HashMap/HashSet in rustc_incremental and ↵Andrew Xie-6/+6
replaced with IndexMap/IndexSet
2023-06-04Use `load`-`store` instead of `memcpy` for short integer arraysScott McMurray-1/+35
2023-06-02Rollup merge of #112168 - scottmcm:lower-div-rem-unchecked-to-mir, r=oli-obkMichael Goulet-16/+0
Lower `unchecked_div`/`_rem` to MIR's `BinOp::Div`/`Rem` As described in <https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/enum.BinOp.html#variant.Div>, the ordinary `BinOp`s for these are already UB for division by zero ([or overflow](https://llvm.org/docs/LangRef.html#sdiv-instruction), [demo](https://rust.godbolt.org/z/71e7P7Exh)), as MIR building is responsible for inserting code to panic for those cases regardless of whether the overflow checks are enabled. So we can lower these in the same arm that lowers `wrapping_add` to MIR `BinOp::Add` and such, as all these cases turn into ordinary `Rvalue::BinaryOp`s.
2023-06-02Add trustzone and virtualization target features for aarch32.Andrew Walbran-0/+2
These are LLVM target features which allow the `smc` and `hvc` instructions respectively to be used in inline assembly.
2023-06-01Avoid passing --cpu-features when emptyTamir Duberstein-5/+7
Added in 12ac719b99560072cbe52a957f22d3fe6946cf2a, this logic always passed --cpu-features, even when the value was the empty string.
2023-06-01Use translatable diagnostics in `rustc_const_eval`Deadbeef-2/+1
2023-06-01remove unchecked_div/_rem from cg_ssaScott McMurray-16/+0
2023-05-31Add a distinct `OperandValue::ZeroSized` variant for ZSTsScott McMurray-66/+82
These tend to have special handling in a bunch of places anyway, so the variant helps remember that. And I think it's easier to grok than non-Scalar Aggregates sometimes being `Immediates` (like I got wrong and caused 109992). As a minor bonus, it means we don't need to generate poison LLVM values for them to pass around in `OperandValue::Immediate`s.
2023-05-31Auto merge of #110807 - petrochenkov:strictflavor, r=lqd,wesleywiserbors-40/+3
linker: Report linker flavors incompatible with the current target The linker flavor is checked for target compatibility even if linker is never used (e.g. we are producing a rlib). If it causes trouble, we can move the check to `link.rs` so it will run if the linker (flavor) is actually used. And also feature gate explicitly specifying linker flavors for tier 3 targets. The next step is supporting all the internal linker flavors in user-visible interfaces (command line and json).
2023-05-31Rollup merge of #112069 - clubby789:offset-of-sized-fields, r=WaffleLapkinMatthias Krüger-3/+8
offset_of: don't require type to be `Sized` Fixes #112051 ~~The RFC [explicitly forbids](https://rust-lang.github.io/rfcs/3308-offset_of.html#limitations) non-`Sized` types, but it looks like only the fields being recursed into were checked. The sized check also seemed to have been completely missing for tuples~~
2023-05-31Auto merge of #112070 - lcnr:disjoint-closure-capture-ub, r=oli-obkbors-1/+0
change `BorrowKind::Unique` to be a mutating `PlaceContext` fixes #112056 I believe that `BorrowKind::Unique` is a footgun in general, so I added a FIXME and opened https://github.com/rust-lang/rust/issues/112072. This is a bit too involved for this PR though.
2023-05-30Auto merge of #112102 - Nilstrieb:rollup-ivu1hmc, r=Nilstriebbors-1/+1
Rollup of 7 pull requests Successful merges: - #107916 (fix comment on Allocator trait) - #111543 (Uplift `clippy::invalid_utf8_in_unchecked` lint) - #111872 (fix: dedup `static_candidates` before report) - #111955 (bootstrap: Various Step refactors) - #112060 (`EarlyBinder::new` -> `EarlyBinder::bind`) - #112064 (Migrate GUI colors test to original CSS color format) - #112100 (Don't typecheck recovered method call from suggestion) r? `@ghost` `@rustbot` modify labels: rollup
2023-05-30Auto merge of #111768 - oli-obk:pair_const_llvm, r=cjgillotbors-12/+75
Optimize scalar and scalar pair representations loaded from ByRef in llvm in https://github.com/rust-lang/rust/pull/105653 I noticed that we were generating suboptimal LLVM IR if we had a `ConstValue::ByRef` that could be represented by a `ScalarPair`. Before https://github.com/rust-lang/rust/pull/105653 this is probably rare, but after it, every slice will go down this suboptimal code path that requires LLVM to untangle a bunch of indirections and translate static allocations that are only used once to read a scalar pair from.
2023-05-29offset_of: Don't require type to be sizedclubby789-3/+8
2023-05-29rustc_target: Refactor linker flavor inferenceVadim Petrochenkov-40/+3
Go through an intermediate pair of `cc`and `lld` hints instead of mapping CLI options to `LinkerFlavor` directly, and use the target's default linker flavor as a reference.
2023-05-29unique borrows are mutating useslcnr-1/+0
2023-05-29EarlyBinder::new -> EarlyBinder::bindlcnr-1/+1
2023-05-29Use `Cow` in `{D,Subd}iagnosticMessage`.Nicholas Nethercote-5/+7
Each of `{D,Subd}iagnosticMessage::{Str,Eager}` has a comment: ``` // FIXME(davidtwco): can a `Cow<'static, str>` be used here? ``` This commit answers that question in the affirmative. It's not the most compelling change ever, but it might be worth merging. This requires changing the `impl<'a> From<&'a str>` impls to `impl From<&'static str>`, which involves a bunch of knock-on changes that require/result in call sites being a little more precise about exactly what kind of string they use to create errors, and not just `&str`. This will result in fewer unnecessary allocations, though this will not have any notable perf effects given that these are error paths. Note that I was lazy within Clippy, using `to_string` in a few places to preserve the existing string imprecision. I could have used `impl Into<{D,Subd}iagnosticMessage>` in various places as is done in the compiler, but that would have required changes to *many* call sites (mostly changing `&format("...")` to `format!("...")`) which didn't seem worthwhile.
2023-05-28Replace EarlyBinder(x) with EarlyBinder::new(x)Kyle Matsuda-1/+1
2023-05-28Auto merge of #112000 - wesleywiser:safestack, r=Amanieubors-0/+3
Add support for LLVM SafeStack Adds support for LLVM [SafeStack] which provides backward edge control flow protection by separating the stack into two parts: data which is only accessed in provable safe ways is allocated on the normal stack (the "safe stack") and all other data is placed in a separate allocation (the "unsafe stack"). SafeStack support is enabled by passing `-Zsanitizer=safestack`. [SafeStack]: https://clang.llvm.org/docs/SafeStack.html cc `@rcvalle` #39699
2023-05-27Rollup merge of #111952 - cjgillot:drop-replace, r=WaffleLapkinGuillaume Gomez-1/+1
Remove DesugaringKind::Replace. A simple boolean flag is enough.
2023-05-26Add SafeStack support to rustcWesley Wiser-0/+3
Adds support for LLVM [SafeStack] which provides backward edge control flow protection by separating the stack into two parts: data which is only accessed in provable safe ways is allocated on the normal stack (the "safe stack") and all other data is placed in a separate allocation (the "unsafe stack"). SafeStack support is enabled by passing `-Zsanitizer=safestack`. [SafeStack]: https://clang.llvm.org/docs/SafeStack.html
2023-05-26Stop creating intermediate places just to immediate convert them to operandsOli Scherer-12/+75
2023-05-26Rollup merge of #111384 - bmisiak:issue-106021-fix, r=petrochenkovMatthias Krüger-0/+32
Fix linking Mac Catalyst by including LC_BUILD_VERSION in object files Hello. My first rustc PR! Issue #106021 prevents Rust code from being linked into Mac Catalyst applications. Apple's LD has started requiring object files to contain version information about the platform they were built for, such as: * the "deployment target" (minimum supported OS version), * the SDK version * the type of the platform (macOS/iOS/catalyst/tvOS/watchOS all have a different number). This is currently only enforced when building for Mac Catalyst. Rust uses the `object` crate which added support for including this information starting with `0.31.0`. ~~I upgraded it along with `thorin-dwp` so that everything depends on 0.31. Apparently 0.31 [pulls in](https://github.com/gimli-rs/object/issues/463) `ruzstd` due to a [new ELF standard](https://maskray.me/blog/2022-09-09-zstd-compressed-debug-sections) because its `compression` feature is enabled by thorin. If you find this objectionable, let me know what the best way to avoid pulling in those dependencies might be.~~ **(`object` upgraded in https://github.com/rust-lang/rust/pull/111413)** I then added two commits: * The first one adds very basic, hard-coded support for calling `set_macho_build_version` for `-macabi` (Catalyst) targets, where it claims deployment target of Catalyst 14.0 and SDK of 16.2. * The second weaves the versioning through `rust_target::spec::TargetOptions`, so that we can stick to specifying all target-related info in one place. Kudos to ``@ara4n`` for writing [this gist](https://gist.github.com/ara4n/320a53ea768aba51afad4c9ed2168536).
2023-05-25Rollup merge of #111950 - cjgillot:expn-noinline, r=oli-obkMichael Goulet-5/+1
Remove ExpnKind::Inlined. Suggested in https://github.com/rust-lang/rust/pull/111815#issuecomment-1561903339 r? ``@oli-obk``
2023-05-25Remove DesugaringKind::Replace.Camille GILLOT-1/+1
2023-05-25Auto merge of #86844 - bjorn3:global_alloc_improvements, r=pnkfelixbors-1/+12
Support #[global_allocator] without the allocator shim This makes it possible to use liballoc/libstd in combination with `--emit obj` if you use `#[global_allocator]`. This is what rust-for-linux uses right now and systemd may use in the future. Currently they have to depend on the exact implementation of the allocator shim to create one themself as `--emit obj` doesn't create an allocator shim. Note that currently the allocator shim also defines the oom error handler, which is normally required too. Once `#![feature(default_alloc_error_handler)]` becomes the only option, this can be avoided. In addition when using only fallible allocator methods and either `--cfg no_global_oom_handling` for liballoc (like rust-for-linux) or `--gc-sections` no references to the oom error handler will exist. To avoid this feature being insta-stable, you will have to define `__rust_no_alloc_shim_is_unstable` to avoid linker errors. (Labeling this with both T-compiler and T-lang as it originally involved both an implementation detail and had an insta-stable user facing change. As noted above, the `__rust_no_alloc_shim_is_unstable` symbol requirement should prevent unintended dependence on this unstable feature.)
2023-05-25Remove ExpnKind::Inlined.Camille GILLOT-5/+1
2023-05-25Fix Mac Catalyst linking by adding build versionBrian M-0/+32
Issue #106021 Apple LD requires build versions in object files for Catalyst
2023-05-24Rollup merge of #111912 - WaffleLapkin:is_some_and_in_the_compiler, ↵Manish Goregaokar-1/+1
r=petrochenkov Use `Option::is_some_and` and `Result::is_ok_and` in the compiler `.is_some_and(..)`/`.is_ok_and(..)` replace `.map_or(false, ..)` and `.map(..).unwrap_or(false)`, making the code more readable. This PR is a sibling of https://github.com/rust-lang/rust/pull/111873#issuecomment-1561316515