about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src
AgeCommit message (Collapse)AuthorLines
2025-06-02Auto merge of #141760 - bjorn3:intrinsic_rework_part2, r=fee1-deadbors-64/+47
Improve intrinsic handling in cg_ssa (part 2) * Avoid computing function type and signature for intrinsics where possible * Nicer handling of bool returning intrinsics Follow up to https://github.com/rust-lang/rust/pull/141404
2025-06-01Rollup merge of #141622 - folkertdev:powerpc-va_arg, r=workingjubileeGuillaume Gomez-3/+182
implement `va_arg` for `powerpc` tracking issue: https://github.com/rust-lang/rust/issues/44930 The llvm `va_arg` implementation is well-known to have serious limitations. Some planned changes to rust's `VaList` make it much more likely that LLVM miscompiles `va_arg`, so this PR adds support for the various powerpc targets. Now at least the targets that `core` has explicit support for will continue to work. For `powerpc` (the 32-bit variant) this implementation also fixes a bug where only up to 20 variadic arguments were supported. Locally (with qemu), these targets now pass the tests in https://github.com/rust-lang/rust/blob/master/tests/run-make/c-link-to-rust-va-list-fn/checkrust.rs. That test does not actually run for the powerpc targets in CI though. The implementation is based on clang: - handling of big endian architectures https://github.com/llvm/llvm-project/blob/3c8089d1ea53232d5a7cdc33f0cb43ef7d6f723b/clang/lib/CodeGen/ABIInfoImpl.cpp#L191-L193 - 64-bit https://github.com/llvm/llvm-project/blob/3c8089d1ea53232d5a7cdc33f0cb43ef7d6f723b/clang/lib/CodeGen/Targets/PPC.cpp#L969 - 32-bit https://github.com/llvm/llvm-project/blob/3c8089d1ea53232d5a7cdc33f0cb43ef7d6f723b/clang/lib/CodeGen/Targets/PPC.cpp#L430 cc `@daltenty` (target maintainer) r? `@workingjubilee` `@rustbot` label: +F-c_variadic
2025-06-01implement `va_arg` for `powerpc`Folkert de Vries-11/+145
This actually fixes a bug where before only 20 arguments could be passed. As far as I can tell, an arbitrary number of arguments is now supported
2025-05-30implement `va_arg` for `powerpc64` and `powerpc64le`Folkert de Vries-3/+48
2025-05-30Auto merge of #139385 - joboet:threadlocal_address, r=nikicbors-3/+10
rustc_codegen_llvm: use `threadlocal.address` intrinsic to access TLS Fixes #136044 r? `@nikic`
2025-05-30Directly use from_immediate for handling boolbjorn3-3/+2
2025-05-30Avoid computing function type for intrinsic instancesbjorn3-6/+2
2025-05-30Use layout field of OperandRef in generic_simd_intrinsicbjorn3-32/+26
2025-05-30Use layout field of OperandRef and PlaceRef in codegen_intrinsic_callbjorn3-23/+17
This avoids having to get the function signature.
2025-05-30Rollup merge of #141538 - folkertdev:systemv-x86_64-va_arg, r=workingjubileeMatthias Krüger-9/+319
implement `va_arg` for x86_64 systemv tracking issue: https://github.com/rust-lang/rust/issues/44930 Turns out LLVM's `va_arg` is also unreliable for this target. https://github.com/llvm/llvm-project/issues/141361 So, like clang, we implement our own. I used - the spec at https://gitlab.com/x86-psABIs/x86-64-ABI - the clang implementation at https://github.com/llvm/llvm-project/blob/9a440f84773c56d3803f330774acb2b4f471d5b4/clang/lib/CodeGen/Targets/X86.cpp#L3041 We can take a bunch of shortcuts because the return type of `va_list` must implement `VaArgSafe`. I also extended some of the tests, because up to 11 floats can be stored in the `reg_safe_area` for this calling convention. r? `@workingjubilee` `@rustbot` label +F-c_variadic try-job: x86_64-apple-1
2025-05-30Rollup merge of #141507 - RalfJung:atomic-intrinsics, r=bjorn3Matthias Krüger-10/+10
atomic_load intrinsic: use const generic parameter for ordering We have a gazillion intrinsics for the atomics because we encode the ordering into the intrinsic name rather than making it a parameter. This is particularly bad for those operations that take two orderings. Let's fix that! This PR only converts `load`, to see if there's any feedback that would fundamentally change the strategy we pursue for the const generic intrinsics. The first two commits are preparation and could be a separate PR if you prefer. `@BoxyUwU` -- I hope this is a use of const generics that is unlikely to explode? All we need is a const generic of enum type. We could funnel it through an integer if we had to but an enum is obviously nicer... `@bjorn3` it seems like the cranelift backend entirely ignores the ordering?
2025-05-29implement `va_arg` for x86_64 systemv and macOSFolkert de Vries-2/+314
Turns out LLVM's `va_arg` is also unreliable for this target, so we need our own implementation.
2025-05-29rustc_codegen_llvm: use `threadlocal.address` intrinsic to access TLSjoboet-3/+10
2025-05-29`emit_xtensa_va_arg`: use `inbounds_ptradd` instead of `inbounds_gep`Folkert de Vries-7/+5
2025-05-28get rid of rustc_codegen_ssa::common::AtomicOrderingRalf Jung-10/+10
2025-05-28Remove unused arg_memory_ty methodbjorn3-10/+0
2025-05-28Mark all optimize methods and the codegen method as safebjorn3-9/+9
There is no safety contract and I don't think any of them can actually cause UB in more ways than passing malicious source code to rustc can. While LtoModuleCodegen::optimize says that the returned ModuleCodegen points into the LTO module, the LTO module has already been dropped by the time this function returns, so if the returned ModuleCodegen indeed points into the LTO module, we would have seen crashes on every LTO compilation, which we don't. As such the comment is outdated.
2025-05-28Remove methods from StaticCodegenMethods that are not called in cg_ssa itselfbjorn3-17/+13
2025-05-28Make predefine methods take &mut selfbjorn3-3/+3
2025-05-28Remove a couple of uses of interior mutability around staticsbjorn3-22/+27
2025-05-28Remove codegen_unit from MiscCodegenMethodsbjorn3-7/+10
2025-05-28Rollup merge of #141404 - bjorn3:refactor_cg_ssa_call_codegen, r=davidtwcoTrevor Gross-48/+32
Improve intrinsic handling in cg_ssa * Move all intrinsic handling code to the start of `codegen_call_terminator`. * Push some intrinsic handling code into `codegen_intrinsic_call`. * Don't depend on FnAbi for intrinsics.
2025-05-27Rollup merge of #141650 - Zalathar:revert-unused-local-file, r=ZalatharMatthias Krüger-59/+39
coverage: Revert "unused local file IDs" due to empty function names The changes to coverage metadata generation in rust-lang/rust#140847 appear to be the most likely cause of the `function name is empty` errors reported in rust-lang/rust#141577. If that guess is correct, great. If not, no big deal. --- This reverts commit 3b22c21dd8c30f499051fe7a758ca0e5d81eb638, reversing changes made to 5f292eea6d63abbd26f1e6e00a0b8cf21d828d7d. r? ghost
2025-05-27coverage: Revert "unused local file IDs" due to empty function namesZalathar-59/+39
This reverts commit 3b22c21dd8c30f499051fe7a758ca0e5d81eb638, reversing changes made to 5f292eea6d63abbd26f1e6e00a0b8cf21d828d7d.
2025-05-27Rollup merge of #141623 - folkertdev:va-arg-explicit-types, r=workingjubileeMichael Goulet-22/+61
use custom types to clarify arguments to `emit_ptr_va_arg` tracking issue: https://github.com/rust-lang/rust/issues/44930 split out of https://github.com/rust-lang/rust/pull/141622 r? ``@workingjubilee`` ``@rustbot`` label: +F-c_variadic
2025-05-27use custom types to clarify arguments to `emit_ptr_va_arg`Folkert de Vries-22/+61
2025-05-26Remove usage of FnAbi in codegen_intrinsic_callbjorn3-20/+10
2025-05-26Pass PlaceRef rather than Bx::Value to codegen_intrinsic_callbjorn3-28/+22
2025-05-24Cleanup CodegenFnAttrFlagsNoratrieb-2/+2
- Rename `USED` to `USED_COMPILER` to better reflect its behavior. - Reorder some items to group the used and allocator flags together - Renumber them without gaps
2025-05-19Rollup merge of #140847 - Zalathar:unused-local-file, r=SparrowLiiStuart Cook-39/+59
coverage: Detect unused local file IDs to avoid an LLVM assertion Each function's coverage metadata contains a *local file table* that maps local file IDs (used by the function's mapping regions) to global file IDs (shared by all functions in the same CGU). LLVM requires all local file IDs to have at least one mapping region, and has an assertion that will fail if it detects a local file ID with no regions. To make sure that assertion doesn't fire, we need to detect and skip functions whose metadata would trigger it. (This can't actually happen yet, because currently all of a function's spans must belong to the same file and expansion. But this will be an important edge case when adding expansion region support.)
2025-05-19Rollup merge of #140874 - mejrs:rads, r=WaffleLapkinStuart Cook-2/+2
make `rustc_attr_parsing` less dominant in the rustc crate graph It has/had a glob re-export of `rustc_attr_data_structures`, which is a crate much lower in the graph, and a lot of crates were using it *just* (or *mostly*) for that re-export, while they can rely on `rustc_attr_data_structures` directly. Previous graph: ![graph_1](https://github.com/user-attachments/assets/f4a5f13c-4222-4903-b56d-28c83511fcbd) Graph with this PR: ![graph_2](https://github.com/user-attachments/assets/1e053d9c-75cc-402b-84df-86229c98277a) The first commit keeps the re-export, and just changes the dependency if possible. The second commit is the "breaking change" which removes the re-export, and "explicitly" adds the `rustc_attr_data_structures` dependency where needed. It also switches over some src/tools/*. The second commit is actually a lot more involved than I expected. Please let me know if it's a better idea to back it out and just keep the first commit.
2025-05-15Revert "Fix linking statics on Arm64EC #140176"Jieyou Xu-6/+1
Unfortunately, multiple people are reporting linker warnings related to `__rust_no_alloc_shim_is_unstable` after this change. The solution isn't quite clear yet, let's revert to green for now, and try a reland with a determined solution for `__rust_no_alloc_shim_is_unstable`. This reverts commit c8b7f32434c0306db5c1b974ee43443746098a92, reversing changes made to 667247db71ea18c4130dd018d060e7f09d589490.
2025-05-13Auto merge of #140887 - pietroalbini:pa-bootstrap-update, r=compiler-errorsbors-1/+0
Stage0 bootstrap update This PR [follows the release process](https://forge.rust-lang.org/release/process.html#master-bootstrap-update-tuesday) to update the stage0 compiler. The only thing of note is https://github.com/rust-lang/rust/commit/58651d1b316e268fac2100c3ae37bb502a36b8ba, which was flagged by clippy as a correctness fix. I think allowing that lint in our case makes sense, but it's worth to have a second pair of eyes on it. r? `@Mark-Simulacrum`
2025-05-12Auto merge of #140914 - Zalathar:asm-bindings, r=compiler-errorsbors-82/+89
cg_llvm: Clean up some inline assembly bindings This PR combines a few loosely-related cleanups to LLVM bindings related to inline assembly. These include: - Replacing `LLVMRustInlineAsm` with LLVM-C's `LLVMGetInlineAsm` - Adjusting FFI declarations to avoid the need for explicit `as_c_char_ptr` conversions - Flattening control flow in `inline_asm_call` There should be no functional changes.
2025-05-12update cfg(bootstrap)Pietro Albini-1/+0
2025-05-11Rename `OperandBundleOwned` to `OperandBundleBox`Zalathar-17/+18
As with `DIBuilderBox`, the "Box" suffix does a better job of communicating that this is an owning pointer to some borrowable resource. This also renames the `raw` method to `as_ref`, which is what it would have been named originally if the `Deref` problem had been known at the time.
2025-05-11Flatten control-flow in `inline_asm_call` after verificationZalathar-52/+53
2025-05-11Make `LLVMRustInlineAsmVerify` take `*const c_uchar`Zalathar-4/+3
This avoids the need for an explicit `as_c_char_ptr` conversion.
2025-05-11Add a safe wrapper for `LLVMAppendModuleInlineAsm`Zalathar-11/+17
This patch also changes the Rust-side declaration to take `*const c_uchar` instead of `*const c_char`, to avoid the need for `AsCCharPtr`.
2025-05-11Use `LLVMGetInlineAsm`Zalathar-16/+17
This LLVM-C binding replaces the existing `LLVMRustInlineAsm` function.
2025-05-11Add a searchable tag `PTR_LEN_STR` to explain `*const c_uchar` bindingsZalathar-2/+2
This module comment describes why it's OK for LLVM bindings to declare a parameter type of `*const c_uchar` for pointer/length strings, even though the corresponding parameter on the C/C++ side uses `const char *`. Adding a searchable term to each such parameter should make it easier for future maintainers to understand why `*const c_uchar` is being used instead of `*const c_char`.
2025-05-11Rollup merge of #140792 - Urgau:minimum-maximum-intrinsics, ↵León Orell Valerian Liehr-0/+28
r=scottmcm,traviscross,tgross35 Use intrinsics for `{f16,f32,f64,f128}::{minimum,maximum}` operations This PR creates intrinsics for `{f16,f32,f64,f64}::{minimum,maximum}` operations. This wasn't done when those operations were added as the LLVM support was too weak but now that LLVM has libcalls for unsupported platforms we can finally use them. Cranelift and GCC[^1] support are partial, Cranelift doesn't support `f16` and `f128`, while GCC doesn't support `f16`. r? `@tgross35` try-job: aarch64-gnu try-job: dist-various-1 try-job: dist-various-2 [^1]: https://www.gnu.org/software///gnulib/manual/html_node/Functions-in-_003cmath_002eh_003e.html
2025-05-10Use the fallback body for `{minimum,maximum}f128` on LLVM as well.Urgau-6/+14
2025-05-10Rollup merge of #140660 - RalfJung:more-order, r=WaffleLapkinMatthias Krüger-1/+1
remove 'unordered' atomic intrinsics As their doc comment already indicates, these operations do not currently have a place in our memory model. The intrinsics were introduced to support a hack in compiler-builtins, but that hack recently got removed (see https://github.com/rust-lang/compiler-builtins/issues/788).
2025-05-09don't depend on rustc_attr_parsing if rustc_data_structures will domejrs-2/+2
2025-05-09remove 'unordered' atomic intrinsicsRalf Jung-1/+1
2025-05-09Use intrinsics for `{f16,f32,f64,f128}::{minimum,maximum}` operationsUrgau-0/+20
2025-05-10coverage: Detect unused local file IDs to avoid an LLVM assertionZalathar-5/+45
This case can't actually happen yet (other than via a testing flag), because currently all of a function's spans must belong to the same file and expansion. But this will be an important edge case when adding expansion region support.
2025-05-10coverage: Hoist `counter_for_bcb` out of its loopZalathar-10/+10
Having this helper function in the loop was confusing, because it doesn't rely on anything that changes between loop iterations.
2025-05-10coverage: Enlarge empty spans during MIR instrumentation, not codegenZalathar-24/+4
This allows us to assume that coverage spans will only be discarded during codegen in very unusual situations.