about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa
AgeCommit message (Collapse)AuthorLines
2023-07-12De-duplicate consecutive libs when printing native-static-libsUrgau-0/+5
2023-07-11Use constants from object crateCharisee-4/+3
Replace hard-coded values with GNU_PROPERTY_{X86|AARCH64}_FEATURE_1_AND from the object crate.
2023-07-11Rollup merge of #113497 - xSetech:mips_32_abi, r=davidtwcoMatthias Krüger-2/+10
Support explicit 32-bit MIPS ABI for the synthetic object PR #95604 introduced a "synthetic object file to ensure all exported and used symbols participate in the linking". One constraint on this file is that for MIPS-based targets, its architecture-specific ELF flags must be the same as all other object files passed to the linker. That's enforced by LLD, here: https://github.com/llvm/llvm-project/blob/llvmorg-16.0.6/lld/ELF/Arch/MipsArchTree.cpp#L77 The current approach to determining e_flags for 32-bit was implemented in PR #96930, which links to this issue that summarizes the problem well: https://github.com/ayrtonm/psx-sdk-rs/issues/9 > ... the temporary object file is created with an e_flags which is > invalid for 32-bit MIPS targets. The main issue is that it omits the ABI > bits (EF_MIPS_ABI_O32) which implies it uses the N64 ABI. To enable the N32 MIPS ABI (which succeeded O32), this patch enables setting the synthetic object's ABI based on the target "llvm-abiname" field, if it's given; otherwise, the O32 ABI is assumed for 32-bit MIPS targets. More information about the N32 ABI can be found here: https://web.archive.org/web/20160121005457/http://techpubs.sgi.com/library/manuals/2000/007-2816-005/pdf/007-2816-005.pdf
2023-07-10ensure byval allocas are sufficiently alignedErik Desjardins-24/+56
2023-07-09Support explicit 32-bit MIPS ABI for the synthetic objectSeth Junot-2/+10
PR #95604 introduced a "synthetic object file to ensure all exported and used symbols participate in the linking". One constraint on this file is that for MIPS-based targets, its architecture-specific ELF flags must be the same as all other object files passed to the linker. That's enforced by LLD, here: https://github.com/llvm/llvm-project/blob/llvmorg-16.0.6/lld/ELF/Arch/MipsArchTree.cpp#L77 The current approach to determining e_flags for 32-bit was implemented in PR #96930, which links to this issue that summarizes the problem well: https://github.com/ayrtonm/psx-sdk-rs/issues/9 > ... the temporary object file is created with an e_flags which is > invalid for 32-bit MIPS targets. The main issue is that it omits the ABI > bits (EF_MIPS_ABI_O32) which implies it uses the N64 ABI. To enable the N32 MIPS ABI (which succeeded O32), this patch enables setting the synthetic object's ABI based on the target "llvm-abiname" field, if it's given; otherwise, the O32 ABI is assumed for 32-bit MIPS targets. More information about the N32 ABI can be found here: https://web.archive.org/web/20160121005457/http://techpubs.sgi.com/library/manuals/2000/007-2816-005/pdf/007-2816-005.pdf
2023-07-09Rollup merge of #111618 - cjgillot:name-return-place, r=tmiaskoMatthias Krüger-2/+1
Always name the return place. MIR opts more and more consider `_0` as just another local, so there is no point in keeping the special case in debug-info logic.
2023-07-08Always name the return place.Camille GILLOT-2/+1
2023-07-07Rename `adjustment::PointerCast` and variants using it to `PointerCoercion`Nilstrieb-9/+13
It makes it sound like the `ExprKind` and `Rvalue` are supposed to represent all pointer related casts, when in reality their just used to share a some enum variants. Make it clear there these are only coercion to make it clear why only some pointer related "casts" are in the enum.
2023-07-05Move `TyCtxt::mk_x` to `Ty::new_x` where applicableBoxy-14/+20
2023-07-05Move `coverageinfo::ffi` and `coverageinfo::map` out of SSAZalathar-439/+0
2023-07-05Remove trait `CoverageInfoMethods`, since non-LLVM backends don't need itZalathar-21/+1
These methods are only ever called from within `rustc_codegen_llvm`, so they can just be declared there as well.
2023-07-05Narrow trait `CoverageInfoBuilderMethods` down to just one methodZalathar-73/+10
This effectively inlines most of `FunctionCx::codegen_coverage` into the LLVM implementation of `CoverageInfoBuilderMethods`.
2023-07-02Auto merge of #113040 - Kobzol:llvm-remark-streamer, r=tmiaskobors-0/+24
Add `-Zremark-dir` unstable flag to write LLVM optimization remarks to YAML This PR adds an option for `rustc` to emit LLVM optimization remarks to a set of YAML files, which can then be digested by existing tools, like https://github.com/OfekShilon/optview2. When `-Cremark-dir` is passed, and remarks are enabled (`-Cremark=all`), the remarks will be now written to the specified directory, **instead** of being printed to standard error output. The files are named based on the CGU from which they are being generated. Currently, the remarks are written using the LLVM streaming machinery, directly in the diagnostics handler. It seemed easier than going back to Rust and then form there back to C++ to use the streamer from the diagnostics handler. But there are many ways to implement this, of course, so I'm open to suggestions :) I included some comments with questions into the code. Also, I'm not sure how to test this. r? `@tmiasko`
2023-07-02Add `rustc` option to output LLVM optimization remarks to YAML filesJakub Beránek-0/+24
2023-07-02Auto merge of #112718 - oli-obk:SIMD-destructure_mir_const, r=cjgillotbors-24/+34
Make simd_shuffle_indices use valtrees This removes the second-to-last user of the `destructure_mir_constant` query. So in a follow-up we can remove the query and just move the query provider function directly into pretty printing (which is the last user). cc `@rust-lang/clippy` there's a small functional change, but I think it is correct?
2023-07-02Auto merge of #112910 - lqd:mcp510, r=petrochenkovbors-52/+64
Implement most of MCP510 This implements most of what remains to be done for MCP510: - turns `-C link-self-contained` into a `+`/`-` list of components, like `-C link-self-contained=+linker,+crto,+libc,+unwind,+sanitizers,+mingw`. The scaffolding is present for all these expected components to be implemented and stabilized in the future on their own time. This PR only handles the `-Zgcc-ld=lld` subset of these link-self-contained components as `-Clink-self-contained=+linker` - handles `-C link-self-contained=y|n` as-is today, for compatibility with `rustc_codegen_ssa::back::link::self_contained`'s [explicit opt-in and opt-out](https://github.com/lqd/rust/blob/9eee230cd0a56bfba3ce65121798d9f9f4341cdd/compiler/rustc_codegen_ssa/src/back/link.rs#L1671-L1676). - therefore supports our plan to opt out of `rust-lld` (when it's enabled by default) even for current `-Clink-self-contained` users, with e.g. `-Clink-self-contained -Clink-self-contained=-linker` - turns `add_gcc_ld_path` into its expected final form, by using the `-C link-self-contained=+linker` CLI flag, and whether the `LinkerFlavor` has the expected `Cc::Yes` and `Lld::Yes` shape (this is not yet the case in practice for any CLI linker flavor) - makes the [new clean linker flavors](https://github.com/rust-lang/rust/pull/96827#issuecomment-1208441595) selectable in the CLI in addition to the legacy ones, in order to opt-in to using `cc` and `lld` to emulate `-Zgcc-ld=lld` - ensure the new `-C link-self-contained` components, and `-C linker-flavor`s are unstable, and require `-Z unstable-options` to be used The up-to-date set of flags for the future stable CLI version of `-Zgcc-ld=lld` is currently: `-Clink-self-contained=+linker -Clinker-flavor=gnu-lld-cc -Zunstable-options`. It's possible we'll also need to do something for distros that don't ship `rust-lld`, but maybe there are already no tool search paths to be added to `cc` in this situation anyways. r? `@petrochenkov`
2023-07-01Auto merge of #112550 - loongarch-rs:fix-eflags, r=cjgillotbors-2/+13
loongarch: Fix ELF header flags This patch changes the ELF header flags so that the ABI matches the floating-point features. It also updates the link to the new official documentation.
2023-06-30refactor `add_gcc_ld_path` into its final formRémy Rakic-51/+63
2023-06-30use `LinkSelfContained` for `-C link-self-contained`Rémy Rakic-1/+1
2023-06-30Auto merge of #106619 - agausmann:avr-object-file, r=nagisabors-1/+6
Fix unset e_flags in ELF files generated for AVR targets Closes #106576 ~~Sort-of blocked by gimli-rs/object#500~~ (merged) I'm not sure whether the list of AVR CPU names is okay here. Maybe it could be moved out-of-line to improve the readability of the function.
2023-06-29Rollup merge of #111322 - mirkootter:master, r=davidtwcoMatthias Krüger-6/+38
Support for native WASM exceptions ### Motivation Currently, rustc does not support native WASM exceptions. It does support JavaScript based exceptions for the wasm32-emscripten-target, but this requires back&forth with javascript for many calls, which is very slow. Native wasm support for exceptions is quite common: Clang+LLVM implemented them years ago, and all major browsers support them by now. They enable zero-cost exceptions, at least with regard to runtime-performance-cost. They may increase startup-time and code size, though. ### Important: This PR does not change default behaviour Exceptions usually add a lot of code in form of unwinding blocks, increasing the binary size. Most users probably do not want that, especially which regard to web development. Therefore, wasm exceptions play a similar role as WASM-threads: rustc should support them, like clang does, but users who want to use it have to use some command-line magic like rustflags to opt in. ### What does this PR do? As stated above, the default behaviour is not changed. It is already possible to opt-in into wasm exceptions using the command line. Unfortunately, the LLVM IR is invalid and the LLVM backend crashes. ``` rustc <sourcefile> --target wasm32-unknown-unknown -C panic=unwind -C llvm-args=-wasm-enable-eh -C target-feature=+exception-handling ``` As it turns out, LLVM is quite picky when it comes to IR for exception handling. If the IR does not look exactly like it should, some LLVM-assertions fail and the code generation crashes. This PR adds the necessary modifications to the code generator to make it work. It also adds `exception-handling` as a wasm target feature. ### What this PR does not / what is missing This PR is not a full fledges solution. It is the first step. A few parts are still missing; however, it is already useable (see next section). Currently missing: * The std library has to be adapted. Currently, only [no_std] crates work * Usually, nested exceptions abort the program (i.e. a panic during the cleanup of another panic). This is currently not done yet. - Currently, code inside cleanup handlers does not unwind - To fix this requires a little more work: The code generator currently maintains a single terminate block per function for this. Unfortunately, WASM requires funclet based exception handling. Therefore, we need to create a terminate block per funclet. This is probably not a big problem, but I want to keep this PR simple. ### How to use the compiler given this PR? This PR does not add any command line flags or features. It uses those which are already there. To compile with exceptions enabled, you need * to set the panic strategy to unwind, i.e. `-C panic=unwind` * to enable the exception-handling target feature, i.e. `-C target-feature=+exception-handling` * to tell LLVM about the exception handling, i.e. `-C llvm-args=-wasm-enable-eh` Since the standard library has not been adapted, you can only use it in [no_std] crates as of now. The intrinsic `core::intrinsics::r#try` works. To throw exceptions, you need the ```@llvm.wasm.throw``` intrinsic. I created a sample application which works for me: https://github.com/mirkootter/rust-wasm-demos This example can be run at https://webassembly.sh
2023-06-29Rollup merge of #112946 - nnethercote:improve-cgu-naming-and-ordering, ↵Takayuki Maeda-21/+42
r=wesleywiser Improve cgu naming and ordering Some quality of life improvements when debugging and profiling CGU formation. r? `@wesleywiser`
2023-06-28Auto merge of #112307 - lcnr:operand-ref, r=compiler-errorsbors-29/+102
mir opt + codegen: handle subtyping fixes #107205 the same issue was caused in multiple places: - mir opts: both copy and destination propagation - codegen: assigning operands to locals (which also propagates values) I changed codegen to always update the type in the operands used for locals which should guard against any new occurrences of this bug going forward. I don't know how to make mir optimizations more resilient here. Hopefully the added tests will be enough to detect any trivially wrong optimizations going forward.
2023-06-27Rollup merge of #112207 - qwandor:virt_feature, r=davidtwcoMatthias Krüger-0/+2
Add trustzone and virtualization target features for aarch32. These are LLVM target features which allow the `smc` and `hvc` instructions respectively to be used in inline assembly.
2023-06-26Move mir const to valtree conversion to its own method.Oli Scherer-23/+25
2023-06-26Make simd_shuffle_indices use valtreesOli Scherer-13/+21
2023-06-26Tweak thread names for CGU processing.Nicholas Nethercote-21/+42
For non-incremental builds on Unix, currently all the thread names look like `opt regex.f10ba03eb5ec7975-cgu.0`. But they are truncated by `pthread_setname` to `opt regex.f10ba`, hiding the numeric suffix that distinguishes them. This is really annoying when using a profiler like Samply. This commit changes these thread names to a form like `opt cgu.0`, which is much better.
2023-06-22Remove unused fields from `CodegenContext`.Nicholas Nethercote-21/+3
2023-06-22Introduce `CodegenState`.Nicholas Nethercote-20/+29
The codegen main loop has two bools, `codegen_done` and `codegen_aborted`. There are only three valid combinations: `(false, false)`, `(true, false)`, `(true, true)`. This commit replaces them with a single tri-state enum, which makes things clearer.
2023-06-22Add comments to `Message` and `WorkItem`.Nicholas Nethercote-8/+22
This is particularly useful for `Message`.
2023-06-22Simplify `Message`.Nicholas Nethercote-64/+44
`Message` is an enum with multiple variants. Four of those variants map directly onto the four variants of `WorkItemResult`. This commit reduces those four `Message` variants to a single variant containing a `WorkItemResult`. This requires increasing `WorkItemResult`'s visibility to `pub(crate)` visibility, but `WorkItem` and `Message` can also have their visibility reduced to `pub(crate)`. This change avoids some boilerplate enum translation code, and makes `Message` easier to understand.
2023-06-22Move `Message::CodegenItem` to a separate type.Nicholas Nethercote-10/+11
`Message` is an enum with multiple variants, for messages sent to the coordinator thread. *Except* for `Message::CodegenItem`, which is entirely disjoint, being for messages sent from the coordinator thread to the main thread. This commit move `Message::CodegenItem` into a separate type, `CguMessage`, which makes the code much clearer.
2023-06-21Rollup merge of #112830 - nnethercote:more-codegen-cleanups, r=oli-obkNilstrieb-34/+22
More codegen cleanups Some additional cleanups I found while looking closely at this code, following up from #112827. r= `@oli-obk`
2023-06-21Inline and remove `WorkItem::start_profiling` and `execute_work_item`.Nicholas Nethercote-34/+22
They both match on a `WorkItem`. It's simpler to do it all in one place.
2023-06-20Rollup merge of #112794 - bjorn3:fix_lib_global_alloc, r=oli-obkGuillaume Gomez-2/+16
Fix linker failures when #[global_allocator] is used in a dependency Fixes https://github.com/rust-lang/rust/issues/112715
2023-06-19Rollup merge of #112232 - fee1-dead-contrib:match-eq-const-msg, r=b-naberMichael Goulet-1/+1
Better error for non const `PartialEq` call generated by `match` Resolves #90237
2023-06-19Fix linker failures when #[global_allocator] is used in a dependencybjorn3-2/+16
2023-06-19Remove unchecked_add/sub/mul/shl/shr from CTFE/cg_ssa/cg_clifScott McMurray-43/+6
2023-06-19Promote unchecked_add/sub/mul/shl/shr to mir::BinOpScott McMurray-4/+33
2023-06-19add FIXME's for a later refactoringlcnr-0/+1
2023-06-19codegen: fix `OperandRef` subtype handlinglcnr-29/+101
2023-06-18Better error for non const `PartialEq` call generated by `match`Deadbeef-1/+1
2023-06-16Rollup merge of #112474 - ldm0:ldm_enum_debuginfo_128_support, r=compiler-errorsMichael Goulet-0/+1
Support 128-bit enum variant in debuginfo codegen fixes #111600
2023-06-16Auto merge of #112597 - danakj:map-linker-paths, r=michaelwoeristerbors-3/+33
Use the relative sysroot path in the linker command line to specify sysroot rlibs This addresses https://github.com/rust-lang/rust/issues/112586
2023-06-15Rollup merge of #112669 - Nilstrieb:typo, r=jyn514Guillaume Gomez-1/+1
Fix comment for ptr alignment checks in codegen
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.