about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm
AgeCommit message (Collapse)AuthorLines
2021-07-10Add clobber-only register classes for asm!Amanieu d'Antras-1/+49
These are needed to properly express a function call ABI using a clobber list, even though we don't support passing actual values into/out of these registers.
2021-07-10Use existing declaration of rust_eh_personalityTomasz Miąsko-3/+8
If crate declares `rust_eh_personality`, re-use existing declaration as otherwise attempts to set function attributes that follow the declaration will fail (unless it happens to have exactly the same type signature as the one predefined in the compiler).
2021-07-10Set personality with LLVMSetPersonalityFnTomasz Miąsko-2/+6
2021-07-09Auto merge of #86419 - ricobbe:raw-dylib-stdcall, r=petrochenkovbors-5/+22
Add support for raw-dylib with stdcall, fastcall functions Next stage of work for #58713: allow `extern "stdcall"` and `extern "fastcall"` with `#[link(kind = "raw-dylib")]`. I've deliberately omitted support for vectorcall, as that doesn't currently work, and I wanted to get this out for review. (I haven't really investigated the vectorcall failure much yet, but at first (very cursory) glance it appears that the problem is elsewhere.)
2021-07-09Pass type when creating loadNikita Popov-39/+39
This makes load generation compatible with opaque pointers. The generation of nontemporal copies still accesses the pointer element type, as fixing this requires more movement.
2021-07-09Pass type when creating atomic loadNikita Popov-0/+3
Instead of determining it from the pointer type, explicitly pass the type to load.
2021-07-09Add support for raw-dylib with stdcall, fastcall functions on ↵Richard Cobbe-5/+22
i686-pc-windows-msvc.
2021-07-09Avoid unnecessary `String::clone`lrh2000-4/+4
2021-07-09Store names of captured variables in `optimized_mir`lrh2000-19/+33
- Closures in external crates may get compiled in because of monomorphization. We should store names of captured variables in `optimized_mir`, so that they are written into the metadata file and we can use them to generate debuginfo. - If there are breakpoints inside closures, the names of captured variables stored in `optimized_mir` can be used to print them. Now the name is more precise when disjoint fields are captured.
2021-07-09Name the captured upvars for closures/generators in debuginfolrh2000-1/+23
Previously, debuggers print closures as something like ``` y::main::closure-0 (0x7fffffffdd34) ``` The pointer actually references to an upvar. It is not very obvious, especially for beginners. It's because upvars don't have names before, as they are packed into a tuple. This commit names the upvars, so we can expect to see something like ``` y::main::closure-0 {_captured_ref__b: 0x[...]} ```
2021-07-08Adjust the threshold to look at the ABI, not just the sizeScott McMurray-12/+24
2021-07-08Stop generating `alloca`s+`memcmp` for simple array equalityScott McMurray-0/+31
2021-07-08Improve ICE message when data-layouts don't matchSimonas Kazlauskas-5/+6
LLVM target name does not necessarily match the Rust target name and it can be confusing when the ICE message is describing a target other than has been specified on the command line.
2021-07-06Auto merge of #86911 - bjorn3:crate_info_refactor, r=petrochenkovbors-6/+1
Refactor linker code This merges `LinkerInfo` into `CrateInfo` as there is no reason to keep them separate. `LinkerInfo::to_linker` is merged into `get_linker` as both have different logic for each linker type and `to_linker` is directly called after `get_linker`. Also contains a couple of small cleanups. See the individual commits for all changes.
2021-07-06Don't pass local_crate_name to link_binary separatelybjorn3-6/+1
It is already part of CodegenResults
2021-07-02Respond to review feedbackWesley Wiser-1/+1
2021-07-02Show the variant name for univariant enumsWesley Wiser-1/+1
Previously, only the fields would be displayed with no indication of the variant name. If you already knew the enum was univariant, this was ok but if the enum was univariant because of layout, for example, a `Result<T, !>` then it could be very confusing which variant was the active one.
2021-07-02Update directly tagged enums to visualize the same as niche-layout enumsWesley Wiser-89/+34
Previously, directly tagged enums had a `variant$` field which would show the name of the active variant. We now show the variant using a `[variant]` synthetic item just like we do for niche-layout enums.
2021-07-02Auto merge of #85269 - dpaoliello:dpaoliello/DebugSymbols, r=michaelwoeristerbors-47/+38
Improve debug symbol names to avoid ambiguity and work better with MSVC's debugger There are several cases where names of types and functions in the debug info are either ambiguous, or not helpful, such as including ambiguous placeholders (e.g., `{{impl}}`, `{{closure}}` or `dyn _'`) or dropping qualifications (e.g., for dynamic types). Instead, each debug symbol name should be unique and useful: * Include disambiguators for anonymous `DefPathDataName` (closures and generators), and unify their formatting when used as a path-qualifier vs item being qualified. * Qualify the principal trait for dynamic types. * If there is no principal trait for a dynamic type, emit all other traits instead. * Respect the `qualified` argument when emitting ref and pointer types. * For implementations, emit the disambiguator. * Print const generics when emitting generic parameters or arguments. Additionally, when targeting MSVC, its debugger treats many command arguments as C++ expressions, even when the argument is defined to be a symbol name. As such names in the debug info need to be more C++-like to be parsed correctly: * Avoid characters with special meaning (`#`, `[`, `"`, `+`). * Never start a name with `<` or `{` as this is treated as an operator. * `>>` is always treated as a right-shift, even when parsing generic arguments (so add a space to avoid this). * Emit function declarations using C/C++ style syntax (e.g., leading return type). * Emit arrays as a synthetic `array$<type, size>` type. * Include a `$` in all synthetic types as this is a legal character for C++, but not Rust (thus we avoid collisions with user types).
2021-07-01Rollup merge of #86652 - nagisa:nagisa/non-leaf-fp, r=petrochenkovGuillaume Gomez-13/+23
Add support for leaf function frame pointer elimination This PR adds ability for the target specifications to specify frame pointer emission type that's not just “always” or “whatever cg decides”. In particular there's a new mode that allows omission of the frame pointer for leaf functions (those that don't call any other functions). We then set this new mode for Aarch64-based Apple targets. Fixes #86196
2021-07-01Auto merge of #86617 - joshtriplett:prune-dependencies, r=Mark-Simulacrumbors-2/+0
Remove unused dependencies from compiler crates Various compiler crates have dependencies that they don't appear to use. I used some scripting to detect such dependencies, filtered them based on some manual review, and removed those that do indeed appear to be entirely unused.
2021-06-30Improve debug symbol names to avoid ambiguity and work better with MSVC's ↵Daniel Paoliello-47/+38
debugger There are several cases where names of types and functions in the debug info are either ambiguous, or not helpful, such as including ambiguous placeholders (e.g., `{{impl}}`, `{{closure}}` or `dyn _'`) or dropping qualifications (e.g., for dynamic types). Instead, each debug symbol name should be unique and useful: * Include disambiguators for anonymous `DefPathDataName` (closures and generators), and unify their formatting when used as a path-qualifier vs item being qualified. * Qualify the principal trait for dynamic types. * If there is no principal trait for a dynamic type, emit all other traits instead. * Respect the `qualified` argument when emitting ref and pointer types. * For implementations, emit the disambiguator. * Print const generics when emitting generic parameters or arguments. Additionally, when targeting MSVC, its debugger treats many command arguments as C++ expressions, even when the argument is defined to be a symbol name. As such names in the debug info need to be more C++-like to be parsed correctly: * Avoid characters with special meaning (`#`, `[`, `"`, `+`). * Never start a name with `<` or `{` as this is treated as an operator. * `>>` is always treated as a right-shift, even when parsing generic arguments (so add a space to avoid this). * Emit function declarations using C/C++ style syntax (e.g., leading return type). * Emit arrays as a synthetic `array$<type, size>` type. * Include a `$` in all synthetic types as this is a legal character for C++, but not Rust (thus we avoid collisions with user types).
2021-06-30Add support for leaf fn frame pointer eliminationSimonas Kazlauskas-13/+23
This PR adds ability for the target specifications to specify frame pointer emission type that's not just “always” or “whatever cg decides”. In particular there's a new mode that allows omission of the frame pointer for leaf functions (those that don't call any other functions). We then set this new mode for Aarch64-based Apple targets. Fixes #86196
2021-06-29Auto merge of #86603 - Mark-Simulacrum:stage-step, r=pietroalbinibors-1/+0
Update to new bootstrap compiler r? `@pietroalbini`
2021-06-28Update to new bootstrap compilerMark Rousskov-1/+0
2021-06-28Update other codegens to use tcx managed vtable allocations.Charles Lew-0/+4
2021-06-26Auto merge of #86267 - ZuseZ4:master, r=nagisabors-0/+14
Allow loading of llvm plugins on nightly Based on a discussion in #82734 / with `@wsmoses.` Mainly moves [this](https://github.com/wsmoses/rust/commit/0149bc4e7e596005c665b132877abebe5258a0f6) behind a -Z flag, so it can only be used on nightly, as requested by `@nagisa` in https://github.com/rust-lang/rust/issues/82734#issuecomment-835863940 This change allows loading of llvm plugins like Enzyme. Right now it also requires a shared library LLVM build of rustc for symbol resolution. ```rust // test.rs extern { fn __enzyme_autodiff(_: usize, ...) -> f64; } fn square(x : f64) -> f64 { return x * x; } fn main() { unsafe { println!("Hello, world {} {}!", square(3.0), __enzyme_autodiff(square as usize, 3.0)); } } ``` ``` ./rustc test.rs -Z llvm-plugins="./LLVMEnzyme-12.so" -C passes="enzyme" ./test Hello, world 9 6! ``` I will try to figure out how to simplify the usage and get this into stable in a later iteration, but having this on nightly will already help testing further steps.
2021-06-26Remove dropping of loaded plugins and better debug infoManuel Drehwald-1/+3
2021-06-25rustc_codegen_llvm: Remove unused dependency rustc_incrementalJosh Triplett-1/+0
Unused since commit f141acf0678139ac31375d02feebcc2be220715b ("Move finalize_session_directory call out of cg_llvm").
2021-06-25rustc_codegen_llvm: Remove unused dependency rustc_featureJosh Triplett-1/+0
Unused since commit 622c48e4f1a5bc3727f8ead89767c8a9e367a77e ("Allow making `RUSTC_BOOTSTRAP` conditional on the crate name").
2021-06-23Use HTTPS links where possibleSmitty-3/+3
2021-06-23Add missing useManuel Drehwald-1/+4
2021-06-21addressing feedbackManuel Drehwald-6/+5
2021-06-13allow loading of llvm plugins on nightlyManuel Drehwald-0/+10
2021-06-10Auto merge of #86020 - nagisa:nagisa/outliner, r=pnkfelixbors-1/+12
Disable the machine outliner by default This addresses a codegen-issue that needs to be fixed upstream in LLVM. While we wait for the fix, we can disable it. Verified manually that the outliner is no longer run when `-Copt-level=z` is specified, and also that you can override this with `-Cllvm-args=-enable-machine-outliner` if you need it anyway. A regression test is not really feasible in this instance, given that we do not have any minimal reproducers. Fixes #85351 cc `@pnkfelix`
2021-06-10Auto merge of #85910 - cjgillot:no-meta-version, r=Aaron1011bors-1/+2
Drop metadata_encoding_version. Part of #85153 r? `@Aaron1011`
2021-06-07Auto merge of #85810 - bjorn3:further_driver_cleanup, r=varkorbors-10/+3
Driver improvements This PR contains a couple of cleanups for the driver and a few small improvements for the custom codegen backend interface. It also implements `--version` and `-Cpasses=list` support for custom codegen backends.
2021-06-06Auto merge of #84171 - ricobbe:raw-dylib-via-llvm, r=petrochenkovbors-1/+116
Partial support for raw-dylib linkage First cut of functionality for issue #58713: add support for `#[link(kind = "raw-dylib")]` on `extern` blocks in lib crates compiled to .rlib files. Does not yet support `#[link_name]` attributes on functions, or the `#[link_ordinal]` attribute, or `#[link(kind = "raw-dylib")]` on `extern` blocks in bin crates; I intend to publish subsequent PRs to fill those gaps. It's also not yet clear whether this works for functions in `extern "stdcall"` blocks; I also intend to investigate that shortly and make any necessary changes as a follow-on PR. This implementation calls out to an LLVM function to construct the actual `.idata` sections as temporary `.lib` files on disk and then links those into the generated .rlib.
2021-06-06Auto merge of #79608 - alessandrod:bpf, r=nagisabors-0/+6
BPF target support This adds `bpfel-unknown-none` and `bpfeb-unknown-none`, two new no_std targets that generate little and big endian BPF. The approach taken is very similar to the cuda target, where `TargetOptions::obj_is_bitcode` is enabled and code generation is done by the linker. I added the targets to `dist-various-2`. There are [some tests](https://github.com/alessandrod/bpf-linker/tree/main/tests/assembly) in bpf-linker and I'm planning to add more. Those are currently not ran as part of rust CI.
2021-06-05Disable the machine outliner by defaultSimonas Kazlauskas-1/+12
This addresses a codegen-issue that needs to be fixed upstream in LLVM. While we wait for the fix, we can disable it. Verified manually that the outliner is no longer run when `-Copt-level=z` is specified, and also that you can override this with `-Cllvm-args=-enable-machine-outliner` if you need it anyway. A regression test is not really feasible in this instance, given that we do not have any minimal reproducers. Fixes #85351
2021-06-04Add first cut of functionality for #58713: support for #[link(kind = ↵Richard Cobbe-1/+116
"raw-dylib")]. This does not yet support #[link_name] attributes on functions, the #[link_ordinal] attribute, #[link(kind = "raw-dylib")] on extern blocks in bin crates, or stdcall functions on 32-bit x86.
2021-06-04Auto merge of #84449 - alexcrichton:metadata-in-object, r=nagisabors-84/+0
rustc: Store metadata-in-rlibs in object files This commit updates how rustc compiler metadata is stored in rlibs. Previously metadata was stored as a raw file that has the same format as `--emit metadata`. After this commit, however, the metadata is encoded into a small object file which has one section which is the contents of the metadata. The motivation for this commit is to fix a common case where #83730 arises. The problem is that when rustc crates a `dylib` crate type it needs to include entire rlib files into the dylib, so it passes `--whole-archive` (or the equivalent) to the linker. The problem with this, though, is that the linker will attempt to read all files in the archive. If the metadata file were left as-is (today) then the linker would generate an error saying it can't read the file. The previous solution was to alter the rlib just before linking, creating a new archive in a temporary directory which has the metadata file removed. This problem from before this commit is now removed if the metadata file is stored in an object file that the linker can read. The only caveat we have to take care of is to ensure that the linker never actually includes the contents of the object file into the final output. We apply similar tricks as the `.llvmbc` bytecode sections to do this. This involved changing the metadata loading code a bit, namely updating some of the LLVM C APIs used to use non-deprecated ones and fiddling with the lifetimes a bit to get everything to work out. Otherwise though this isn't intended to be a functional change really, only that metadata is stored differently in archives now. This should end up fixing #83730 because by default dylibs will no longer have their rlib dependencies "altered" meaning that split-debuginfo will continue to have valid paths pointing at the original rlibs. (note that we still "alter" rlibs if LTO is enabled to remove Rust object files and we also "alter" for the #[link(cfg)] feature, but that's rarely used). Closes #83730
2021-06-04rustc: Store metadata-in-rlibs in object filesAlex Crichton-84/+0
This commit updates how rustc compiler metadata is stored in rlibs. Previously metadata was stored as a raw file that has the same format as `--emit metadata`. After this commit, however, the metadata is encoded into a small object file which has one section which is the contents of the metadata. The motivation for this commit is to fix a common case where #83730 arises. The problem is that when rustc crates a `dylib` crate type it needs to include entire rlib files into the dylib, so it passes `--whole-archive` (or the equivalent) to the linker. The problem with this, though, is that the linker will attempt to read all files in the archive. If the metadata file were left as-is (today) then the linker would generate an error saying it can't read the file. The previous solution was to alter the rlib just before linking, creating a new archive in a temporary directory which has the metadata file removed. This problem from before this commit is now removed if the metadata file is stored in an object file that the linker can read. The only caveat we have to take care of is to ensure that the linker never actually includes the contents of the object file into the final output. We apply similar tricks as the `.llvmbc` bytecode sections to do this. This involved changing the metadata loading code a bit, namely updating some of the LLVM C APIs used to use non-deprecated ones and fiddling with the lifetimes a bit to get everything to work out. Otherwise though this isn't intended to be a functional change really, only that metadata is stored differently in archives now. This should end up fixing #83730 because by default dylibs will no longer have their rlib dependencies "altered" meaning that split-debuginfo will continue to have valid paths pointing at the original rlibs. (note that we still "alter" rlibs if LTO is enabled to remove Rust object files and we also "alter" for the #[link(cfg)] feature, but that's rarely used). Closes #83730
2021-06-04Move crate_name field from OngoingCodegen to CrateInfobjorn3-1/+1
2021-06-04Remove unused importsbjorn3-2/+2
2021-06-04Provide default MetadataLoaderbjorn3-4/+0
2021-06-04Provide a default provide* implementation for CodegenBackendbjorn3-3/+0
Both cg_llvm and cg_clif don't override it. cg_spirv does override it, so it needs to be preserved.
2021-06-02Respond to review feedbackWesley Wiser-62/+28
2021-06-02Change the type name from `_enum<..>` to `enum$<..>`Wesley Wiser-3/+3
This makes the type name inline with the proposed standard in #85269.
2021-06-02Respond to review feedbackWesley Wiser-3/+33