about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm
AgeCommit message (Collapse)AuthorLines
2025-06-30Rollup merge of #143140 - RalfJung:ptr-into-parts, r=oli-obkMatthias Krüger-1/+1
give Pointer::into_parts a more scary name and offer a safer alternative `into_parts` is a bit too innocent of a name for a somewhat subtle operation. r? `@oli-obk`
2025-06-30Disable f16 on Aarch64 without neon for llvm < 20.1.1Trevor Gross-0/+8
This check was added unconditionally in c51b229140 ("Disable f16 on Aarch64 without `neon`") and reverted in 4a8d35709e ("Revert "Disable `f16` on Aarch64 without `neon`"") since it did not fail in Rust's build. However, it is still possible to hit this crash if using LLVM 19 built with assertions, so disable the type conditionally based on version here. Note that for these builds, a similar patch is needed in the build script for `compiler-builtins` since it does not yet use `cfg(target_has_reliable_f16)` (hopefully to be resolved in the near future). Report: https://www.github.com/rust-lang/rust/pull/139276#issuecomment-3014781652 Original LLVM issue: https://www.github.com/llvm/llvm-project/issues/129394
2025-06-29Rollup merge of #142078 - sayantn:more-intrinsics, r=workingjubileeGuillaume Gomez-1/+16
Add SIMD funnel shift and round-to-even intrinsics This PR adds 3 new SIMD intrinsics - `simd_funnel_shl` - funnel shift left - `simd_funnel_shr` - funnel shift right - `simd_round_ties_even` (vector version of `round_ties_even_fN`) TODO (future PR): implement `simd_fsh{l,r}` in miri, cg_gcc and cg_clif (it is surprisingly hard to implement without branches, the common tricks that rotate uses doesn't work because we have 2 elements now. e.g, the `-n&31` trick used by cg_gcc to implement rotate doesn't work with this because then `fshl(a, b, 0)` will be `a | b`) [#t-compiler > More SIMD intrinsics](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/More.20SIMD.20intrinsics/with/522130286) `@rustbot` label T-compiler T-libs A-intrinsics F-core_intrinsics r? `@workingjubilee`
2025-06-29give Pointer::into_parts a more scary name and offer a safer alternativeRalf Jung-1/+1
2025-06-25Auto merge of #143026 - jdonszelmann:rollup-z7mkuyt, r=jdonszelmannbors-1/+22
Rollup of 7 pull requests Successful merges: - rust-lang/rust#142146 (Withdraw the claim `extern "C-cmse-nonsecure-*"` always matches `extern "C"`) - rust-lang/rust#142200 (`tests/ui`: A New Order [8/N]) - rust-lang/rust#142724 (Add runtime check to avoid overwrite arg in `Diag`) - rust-lang/rust#142809 (Add PrintTAFn flag for targeted type analysis printing) - rust-lang/rust#142976 (Check CoerceUnsized impl validity before coercing) - rust-lang/rust#142992 (Convert some ABI tests to use `extern "rust-invalid"`) - rust-lang/rust#143000 (Make `Sub`, `Mul`, `Div` and `Rem` `const_traits`) r? `@ghost` `@rustbot` modify labels: rollup
2025-06-25Rollup merge of #142809 - KMJ-007:ad-type-analysis-flag, r=ZuseZ4Jana Dönszelmann-1/+22
Add PrintTAFn flag for targeted type analysis printing ## Summary This PR adds a new `PrintTAFn` flag to the `-Z autodiff` option that allows printing type analysis information for a specific function, rather than all functions. ## Changes ### New Flag - Added `PrintTAFn=<function_name>` option to `-Z autodiff` - Usage: `-Z autodiff=Enable,PrintTAFn=my_function_name` ### Implementation Details - **Rust side**: Added `PrintTAFn(String)` variant to `AutoDiff` enum - **Parser**: Updated `parse_autodiff` to handle `PrintTAFn=<function_name>` syntax with proper error handling - **FFI**: Added `set_print_type_fun` function to interface with Enzyme's `FunctionToAnalyze` command line option - **Documentation**: Updated help text and documentation for the new flag ### Files Modified - `compiler/rustc_session/src/config.rs`: Added `PrintTAFn(String)` variant - `compiler/rustc_session/src/options.rs`: Updated parser and help text (now shows `PrintTAFn` in the list) - `compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs`: Added FFI function and static variable - `compiler/rustc_codegen_llvm/src/back/lto.rs`: Added handling for new flag - `src/doc/rustc-dev-guide/src/autodiff/flags.md`: Updated documentation - `src/doc/unstable-book/src/compiler-flags/autodiff.md`: Updated documentation ## Testing The flag can be tested with: ```bash rustc +enzyme -Z autodiff=Enable,PrintTAFn=square test.rs ``` This will print type analysis information only for the function named "square" instead of all functions. ## Error Handling The parser includes proper error handling: - Missing argument: `PrintTAFn` without `=<function_name>` will show an error - Unknown options: Invalid autodiff options will be reported r? ```@ZuseZ4```
2025-06-25Auto merge of #142879 - Mark-Simulacrum:opt-cleanup, r=WaffleLapkinbors-2/+1
Remove dead instructions in terminate blocks Terminate blocks look pretty in the IR I've looked at, so no actual perf delta from this. But it seems reasonable to note produce unused IR.
2025-06-25added PrintTAFn flag for autodiffKaran Janthe-1/+22
Signed-off-by: Karan Janthe <karanjanthe@gmail.com>
2025-06-22Remove dead instructions in terminate blocksMark Rousskov-2/+1
2025-06-22centralize `-Zmin-function-alignment` logicFolkert de Vries-5/+1
2025-06-19various minor target feature cleanupsRalf Jung-11/+11
2025-06-19line-wrap and extend comments, typosRalf Jung-5/+5
2025-06-19cg_gcc: properly populate cfg(target_features) with -Ctarget-featuresRalf Jung-16/+16
2025-06-19move -Ctarget-feature handling into shared codeRalf Jung-155/+41
2025-06-19move cfg(target_feature) computation into shared placeRalf Jung-80/+7
2025-06-18Auto merge of #141061 - dpaoliello:shimasfn, r=bjorn3bors-32/+42
Change __rust_no_alloc_shim_is_unstable to be a function This fixes a long sequence of issues: 1. A customer reported that building for Arm64EC was broken: #138541 2. This was caused by a bug in my original implementation of Arm64EC support, namely that only functions on Arm64EC need to be decorated with `#` but Rust was decorating statics as well. 3. Once I corrected Rust to only decorate functions, I started linking failures where the linker couldn't find statics exported by dylib dependencies. This was caused by the compiler not marking exported statics in the generated DEF file with `DATA`, thus they were being exported as functions not data. 4. Once I corrected the way that the DEF files were being emitted, the linker started failing saying that it couldn't find `__rust_no_alloc_shim_is_unstable`. This is because the MSVC linker requires the declarations of statics imported from other dylibs to be marked with `dllimport` (whereas it will happily link to functions imported from other dylibs whether they are marked `dllimport` or not). 5. I then made a change to ensure that `__rust_no_alloc_shim_is_unstable` was marked as `dllimport`, but the MSVC linker started emitting warnings that `__rust_no_alloc_shim_is_unstable` was marked as `dllimport` but was declared in an obj file. This is a harmless warning which is a performance hint: anything that's marked `dllimport` must be indirected via an `__imp` symbol so I added a linker arg in the target to suppress the warning. 6. A customer then reported a similar warning when using `lld-link` (<https://github.com/rust-lang/rust/pull/140176#issuecomment-2872448443>). I don't think it was an implementation difference between the two linkers but rather that, depending on the obj that the declaration versus uses of `__rust_no_alloc_shim_is_unstable` landed in we would get different warnings, so I suppressed that warning as well: #140954. 7. Another customer reported that they weren't using the Rust compiler to invoke the linker, thus these warnings were breaking their build: <https://github.com/rust-lang/rust/pull/140176#issuecomment-2881867433>. At that point, my original change was reverted (#141024) leaving Arm64EC broken yet again. Taking a step back, a lot of these linker issues arise from the fact that `__rust_no_alloc_shim_is_unstable` is marked as `extern "Rust"` in the standard library and, therefore, assumed to be a foreign item from a different crate BUT the Rust compiler may choose to generate it either in the current crate, some other crate that will be statically linked in OR some other crate that will by dynamically imported. Worse yet, it is impossible while building a given crate to know if `__rust_no_alloc_shim_is_unstable` will statically linked or dynamically imported: it might be that one of its dependent crates is the one with an allocator kind set and thus that crate (which is compiled later) will decide depending if it has any dylib dependencies or not to import `__rust_no_alloc_shim_is_unstable` or generate it. Thus, there is no way to know if the declaration of `__rust_no_alloc_shim_is_unstable` should be marked with `dllimport` or not. There is a simple fix for all this: there is no reason `__rust_no_alloc_shim_is_unstable` must be a static. It needs to be some symbol that must be linked in; thus, it could easily be a function instead. As a function, there is no need to mark it as `dllimport` when dynamically imported which avoids the entire mess above. There may be a perf hit for changing the `volatile load` to be a `tail call`, so I'm happy to change that part back (although I question what the codegen of a `volatile load` would look like, and if the backend is going to try to use load-acquire semantics). Build with this change applied BEFORE #140176 was reverted to demonstrate that there are no linking issues with either MSVC or MinGW: <https://github.com/rust-lang/rust/actions/runs/15078657205> Incidentally, I fixed `tests/run-make/no-alloc-shim` to work with MSVC as I needed it to be able to test locally (FYI for #128602) r? `@bjorn3` cc `@jieyouxu`
2025-06-17Rollup merge of #142588 - ZuseZ4:generic-ctx-imprv, r=oli-obkJacob Pratt-9/+6
Generic ctx imprv Cleanup work for my gpu pr r? `@oli-obk`
2025-06-16add and use generic get_const_int functionManuel Drehwald-7/+4
2025-06-16Change __rust_no_alloc_shim_is_unstable to be a functionDaniel Paoliello-32/+42
2025-06-16make more CodegenCx function genericManuel Drehwald-2/+2
2025-06-16Fix RISC-V C function ABI when passing/returning structs containing floatsbeetrees-1/+1
2025-06-16Auto merge of #142521 - sayantn:simplify-intrinsics, r=nikic,workingjubileebors-242/+55
Use `LLVMIntrinsicGetDeclaration` to completely remove the hardcoded intrinsics list Follow-up to rust-lang/rust#142259 This also needs a rustc-perf run, because `Intrinsic::getType` can be expensive `@rustbot` label A-LLVM A-codegen T-compiler r? `@workingjubilee` cc `@nikic`
2025-06-15Rollup merge of #142481 - heiher:loong-asm-f16, r=AmanieuLeón Orell Valerian Liehr-0/+21
Add `f16` inline asm support for LoongArch r? `````@Amanieu`````
2025-06-15Rollup merge of #141769 - bjorn3:codegen_metadata_module_rework, ↵León Orell Valerian Liehr-10/+9
r=workingjubilee,saethlin Move metadata object generation for dylibs to the linker code This deduplicates some code between codegen backends and may in the future allow adding extra metadata that is only known at link time. Prerequisite of https://github.com/rust-lang/rust/issues/96708.
2025-06-15Correctly account for different address spaces in LLVM intrinsic invocationssayantn-19/+24
2025-06-15Use `LLVMIntrinsicGetDeclaration` to completely remove the hardcoded ↵sayantn-224/+32
intrinsics list
2025-06-15Add `simd_funnel_sh{l,r}` and `simd_round_ties_even`sayantn-1/+16
2025-06-14Auto merge of #142259 - sayantn:simplify-intrinsics, r=workingjubileebors-826/+476
Simplify implementation of Rust intrinsics by using type parameters in the cache The current implementation of intrinsics have a lot of duplication to handle different overloads of overloaded LLVM intrinsic. This PR uses the **base name and the type parameters** in the cache instead of the full, overloaded name. This has the benefit that `call_intrinsic` doesn't need to provide the full name, rather the type parameters (which is most of the time more available). This uses `LLVMIntrinsicCopyOverloadedName2` to get the overloaded name from the base name and the type parameters, and only uses it to declare the function. (originally was part of rust-lang/rust#140763, split off later) `@rustbot` label A-codegen A-LLVM r? codegen
2025-06-14Add `f16` inline asm support for LoongArchWANG Rui-0/+21
2025-06-13Rollup merge of #140770 - folkertdev:custom-abi, r=tgross35Matthias Krüger-0/+4
add `extern "custom"` functions tracking issue: rust-lang/rust#140829 previous discussion: https://github.com/rust-lang/rust/issues/140566 In short, an `extern "custom"` function is a function with a custom ABI, that rust does not know about. Therefore, such functions can only be defined with `#[unsafe(naked)]` and `naked_asm!`, or via an `extern "C" { /* ... */ }` block. These functions cannot be called using normal rust syntax: calling them can only be done from inline assembly. The motivation is low-level scenarios where a custom calling convention is used. Currently, we often pick `extern "C"`, but that is a lie because the function does not actually respect the C calling convention. At the moment `"custom"` seems to be the name with the most support. That name is not final, but we need to pick something to actually implement this. r? `@traviscross` cc `@tgross35` try-job: x86_64-apple-2
2025-06-13Rollup merge of #135927 - azhogin:azhogin/retpoline, r=davidtwcoMatthias Krüger-41/+10
retpoline and retpoline-external-thunk flags (target modifiers) to enable retpoline-related target features `-Zretpoline` and `-Zretpoline-external-thunk` flags are target modifiers (tracked to be equal in linked crates). * Enables target features for `-Zretpoline-external-thunk`: `+retpoline-external-thunk`, `+retpoline-indirect-branches`, `+retpoline-indirect-calls`. * Enables target features for `-Zretpoline`: `+retpoline-indirect-branches`, `+retpoline-indirect-calls`. It corresponds to clang -mretpoline & -mretpoline-external-thunk flags. Also this PR forbids to specify those target features manually (warning). Issue: rust-lang/rust#116852
2025-06-12add `extern "custom"` functionsFolkert de Vries-0/+4
2025-06-12Simplify implementation of Rust intrinsics by using type parameters in the cachesayantn-826/+476
2025-06-10use `#[naked]` for `__rust_probestack`Folkert de Vries-2/+3
2025-06-09-Zretpoline and -Zretpoline-external-thunk flags (target modifiers) to ↵Andrew Zhogin-41/+10
enable retpoline-related target features
2025-06-08Rollup merge of #142194 - bjorn3:less_unstable_features, r=jieyouxuJubilee-1/+0
Remove all unused feature gates from the compiler
2025-06-08Rollup merge of #142179 - folkertdev:min-global-align-parse, r=workingjubileeJubilee-39/+5
store `target.min_global_align` as an `Align` Parse the alignment properly when the target is defined/parsed, and error out on invalid alignment values. That means this work doesn't need to happen for every global in each backend.
2025-06-08Rollup merge of #142053 - heiher:loong32-none, r=wesleywiserJubilee-2/+2
Add new Tier-3 targets: `loongarch32-unknown-none*` MCP: https://github.com/rust-lang/compiler-team/issues/865 NOTE: LoongArch32 ELF object support is available starting with object v0.37.0.
2025-06-08Remove all unused feature gates from the compilerbjorn3-1/+0
2025-06-07store `target.min_global_align` as an `Align`Folkert de Vries-39/+5
2025-06-06Add new Tier-3 targets: `loongarch32-unknown-none*`WANG Rui-1/+1
MCP: https://github.com/rust-lang/compiler-team/issues/865
2025-06-05Auto merge of #140872 - bjorn3:elf_use_used_linker, r=nikicbors-6/+6
Make #[used(linker)] the default on ELF too `#[used]` currently is an alias for `#[used(linker)]` on all platforms except ELF based ones where it is an alias for `#[used(compiler)]`. The latter has surprising behavior and the LLVM LangRef explicitly states that it "should only be used in rare circumstances, and should not be exposed to source languages." [^2] The reason `#[used]` still was an alias to `#[used(compiler)]` on ELF is because the gold linker has issues with it. Luckily gold has been deprecated with GCC 15 [^1] and seems to be unable to bootstrap rustc anyway [^3]. As such we shouldn't really care about supporting gold. This would also allow re-enabling start-stop-gc with lld. cc https://github.com/rust-lang/rust/issues/93798 Likely fixes https://github.com/rust-lang/rust/issues/85045 [^1]: https://lists.gnu.org/archive/html/info-gnu/2025-02/msg00001.html [^2]: https://llvm.org/docs/LangRef.html#the-llvm-compiler-used-global-variable [^3]: https://github.com/rust-lang/rust/issues/139425
2025-06-05Make #[used(linker)] the default on ELF toobjorn3-6/+6
#[used] currently is an alias for #[used(linker)] on all platforms except ELF based ones where it is an alias for #[used(compiler)]. The latter has surprising behavior and the LLVM LangRef explicitly states that it "should only be used in rare circumstances, and should not be exposed to source languages." The reason #[used] still was an alias to #[used(compiler)] on ELF is because the gold linker has issues with it. Luckily gold has been deprecated with GCC 15 and seems to be unable to bootstrap rustc anyway. As such we shouldn't really care about supporting gold.
2025-06-05Bump objectWANG Rui-1/+1
2025-06-04Rollup merge of #142005 - scottmcm:fieldidx-in-variantsmultiple, ↵Matthias Krüger-8/+8
r=workingjubilee Change `tag_field` to `FieldIdx` in `Variants::Multiple` It was already available as a generic parameter anyway, and it's not like we'll ever put a tag in the 5-billionth field. This is a first part of pulling smaller pieces out of rust-lang/rust#138759, so r? workingjubilee
2025-06-03Change `tag_field` to `FieldIdx` in `Variants::Multiple`Scott McMurray-8/+8
It was already available as a generic parameter anyway, and it's not like we'll ever put a tag in the 5-billionth field.
2025-06-04Rollup merge of #141250 - folkertdev:s390x-z17-target-features, r=workingjubileeMatthias Krüger-0/+8
add s390x z17 target features tracking issue: https://github.com/rust-lang/rust/issues/130869 earlier target features were added in https://github.com/rust-lang/rust/pull/135630, and https://github.com/rust-lang/rust/issues/135413#issuecomment-2886439455 has some extra context on these new features. r? ``@ghost`` cc ``@uweigand``
2025-06-03Rollup merge of #141569 - workingjubilee:canonicalize-abi, r=bjorn3Matthias Krüger-29/+40
Replace ad-hoc ABI "adjustments" with an `AbiMap` to `CanonAbi` Our `conv_from_spec_abi`, `adjust_abi`, and `is_abi_supported` combine to give us a very confusing way of reasoning about what _actual_ calling convention we want to lower our code to and whether we want to compile the resulting code at all. Instead of leaving this code as a miniature adventure game in which someone tries to combine stateful mutations into a Rube Goldberg machine that will let them escape the maze and arrive at the promised land of codegen, we let `AbiMap` devour this complexity. Once you have an `AbiMap`, you can answer which `ExternAbi`s will lower to what `CanonAbi`s (and whether they will lower at all). Removed: - `conv_from_spec_abi` replaced by `AbiMap::canonize_abi` - `adjust_abi` replaced by same - `Conv::PreserveAll` as unused - `Conv::Cold` as unused - `enum Conv` replaced by `enum CanonAbi` target-spec.json changes: - If you have a target-spec.json then now your "entry-abi" key will be specified in terms of one of the `"{abi}"` strings Rust recognizes, e.g. ```json "entry-abi": "C", "entry-abi": "win64", "entry-abi": "aapcs", ```
2025-06-03cg_llvm: convert to CanonAbiJubilee Young-29/+40
2025-06-03Move metadata object generation for dylibs to the linker codebjorn3-6/+1
This deduplicates some code between codegen backends and may in the future allow adding extra metadata that is only known at link time.