about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src/abi.rs
AgeCommit message (Collapse)AuthorLines
2025-08-26Use captures(address) instead of captures(none) for indirect argsNikita Popov-3/+5
While provenance cannot be captured through these arguments, the address / object identity can.
2025-08-20Tell LLVM about read-only capturesNikita Popov-1/+6
`&Freeze` parameters are not only `readonly` within the function, but any captures of the pointer can also only be used for reads. This can now be encoded using the `captures(address, read_provenance)` attribute.
2025-08-11Set dead_on_return attribute for indirect argumentsNikita Popov-1/+11
Set the dead_on_return attribute (added in LLVM 21) for arguments that are passed indirectly, but not byval. This indicates that the value of the argument on return does not matter, enabling additional dead store elimination.
2025-07-05use `is_multiple_of` instead of manual moduloFolkert de Vries-1/+1
2025-06-16Fix RISC-V C function ABI when passing/returning structs containing floatsbeetrees-1/+1
2025-06-12add `extern "custom"` functionsFolkert de Vries-0/+4
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-05-28Remove unused arg_memory_ty methodbjorn3-10/+0
2025-04-05Update the minimum external LLVM to 19Josh Stone-16/+1
2025-02-24Remove an unused lifetime paramOli Scherer-1/+1
2025-02-18compiler: Stop reexporting stuff in cg_llvm::abiJubilee Young-11/+8
The reexports confuse tooling like rustdoc into thinking cg_llvm is the source of key types that originate in rustc_target.
2025-02-12Rollup merge of #136807 - ↵Jacob Pratt-1/+0
workingjubilee:merge-gpus-to-get-the-arcradeongeforce, r=bjorn3 compiler: internally merge `PtxKernel` into `GpuKernel` r? ``@bjorn3`` for review
2025-02-11Rollup merge of #136721 - dpaoliello:cleanllvm2, r=ZalatharJacob Pratt-1/+1
cg_llvm: Reduce visibility of some items outside the `llvm` module Next piece of #135502 This reduces the visibility of items (other than those in the `llvm` module) so that dead code analysis will correctly identify unused items.
2025-02-10rustc_codegen_llvm: Mark items as pub(crate) outside of the llvm moduleDaniel Paoliello-1/+1
2025-02-09compiler: internally merge `Conv::PtxKernel` into `GpuKernel`Jubilee Young-1/+0
It is speculated that these two can be conceptually merged, and it can start by ripping out rustc's notion of the PtxKernel call convention. Leave the ExternAbi for now, but the nvptx target now should see it as just a different way to spell Conv::GpuKernel.
2025-02-09Auto merge of #136751 - bjorn3:update_rustfmt, r=Mark-Simulacrumbors-15/+23
Update bootstrap compiler and rustfmt The rustfmt version we previously used formats things differently from what the latest nightly rustfmt does. This causes issues for subtrees that get formatted both in-tree and in their own repo. Updating the rustfmt used in-tree solves those issues. Also bumped the bootstrap compiler as the stage0 update command always updates both at the same time.
2025-02-08Rustfmtbjorn3-15/+23
2025-02-07compiler: remove reexports from rustc_target::callconvJubilee Young-4/+3
2025-01-16Add gpu-kernel calling conventionFlakebi-6/+16
The amdgpu-kernel calling convention was reverted in commit f6b21e90d1ec01081bc2619efb68af6788a63d65 due to inactivity in the amdgpu target. Introduce a `gpu-kernel` calling convention that translates to `ptx_kernel` or `amdgpu_kernel`, depending on the target that rust compiles for.
2024-11-03compiler: Directly use rustc_abi in codegenJubilee Young-3/+3
2024-10-29compiler: `rustc_abi::Abi` => `BackendRepr`Jubilee Young-4/+6
The initial naming of "Abi" was an awful mistake, conveying wrong ideas about how psABIs worked and even more about what the enum meant. It was only meant to represent the way the value would be described to a codegen backend as it was lowered to that intermediate representation. It was never meant to mean anything about the actual psABI handling! The conflation is because LLVM typically will associate a certain form with a certain ABI, but even that does not hold when the special cases that actually exist arise, plus the IR annotations that modify the ABI. Reframe `rustc_abi::Abi` as the `BackendRepr` of the type, and rename `BackendRepr::Aggregate` as `BackendRepr::Memory`. Unfortunately, due to the persistent misunderstandings, this too is now incorrect: - Scattered ABI-relevant code is entangled with BackendRepr - We do not always pre-compute a correct BackendRepr that reflects how we "actually" want this value to be handled, so we leave the backend interface to also inject various special-cases here - In some cases `BackendRepr::Memory` is a "real" aggregate, but in others it is in fact using memory, and in some cases it is a scalar! Our rustc-to-backend lowering code handles this sort of thing right now. That will eventually be addressed by lifting duplicated lowering code to either rustc_codegen_ssa or rustc_target as appropriate.
2024-10-28compiler: Add `is_uninhabited` and use LayoutS accessorsJubilee Young-2/+2
This reduces the need of the compiler to peek on the fields of LayoutS.
2024-10-08compiler: Factor rustc_target::abi out of cg_llvmJubilee Young-1/+3
2024-10-04Use wide pointers consistenly across the compilerUrgau-1/+1
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-26/+18
2024-09-21add `C-cmse-nonsecure-entry` ABIFolkert de Vries-3/+8
2024-09-18Update the minimum external LLVM to 18Josh Stone-3/+1
2024-09-17Rename `{ArgAbi,IntrinsicCall}Methods`.Nicholas Nethercote-1/+1
They both are part of `BuilderMethods`, and so should have `Builder` in their name like all the other traits in `BuilderMethods`.
2024-08-16Add `warn(unreachable_pub)` to `rustc_codegen_llvm`.Nicholas Nethercote-7/+7
2024-08-12Auto merge of #128371 - andjo403:rangeAttribute, r=nikicbors-13/+48
Add range attribute to scalar function results and arguments as LLVM 19 adds the range attribute this starts to use it for better optimization. hade been interesting to see a perf run with the https://github.com/rust-lang/rust/pull/127513 closes https://github.com/rust-lang/rust/issues/50156 cc https://github.com/rust-lang/rust/issues/49572 shall be fixed but not possible to see as there is asserts that already trigger the optimization.
2024-08-11Add range attribute to scalar function results and argumentsAndreas Jonson-13/+48
2024-08-07codegen: better centralize function attribute computationRalf Jung-3/+23
2024-07-29Auto merge of #125016 - nicholasbishop:bishop-cb-112, r=tgross35bors-0/+2
Update compiler_builtins to 0.1.114 The `weak-intrinsics` feature was removed from compiler_builtins in https://github.com/rust-lang/compiler-builtins/pull/598, so dropped the `compiler-builtins-weak-intrinsics` feature from alloc/std/sysroot. In https://github.com/rust-lang/compiler-builtins/pull/593, some builtins for f16/f128 were added. These don't work for all compiler backends, so add a `compiler-builtins-no-f16-f128` feature and disable it for cranelift and gcc.
2024-07-29Reformat `use` declarations.Nicholas Nethercote-11/+9
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-02Use the aligned size for alloca at args when the pass mode is cast.DianQK-1/+2
The `load` and `store` instructions in LLVM access the aligned size.
2024-05-30Add f16/f128 handling in a couple placesNicholas Bishop-0/+2
2024-05-09Make builtin_deref just return a TyMichael Goulet-1/+1
2024-04-25Auto merge of #121298 - nikic:writable, r=cuviperbors-0/+13
Set writable and dead_on_unwind attributes for sret arguments Set the `writable` and `dead_on_unwind` attributes for `sret` arguments. This allows call slot optimization to remove more memcpy's. See https://llvm.org/docs/LangRef.html#parameter-attributes for the specification of these attributes. In short, the statement we're making here is that: * The return slot is writable. * The return slot will not be read if the function unwinds. Fixes https://github.com/rust-lang/rust/issues/90595.
2024-04-25Set writable and dead_on_unwind attributes for sret argumentsNikita Popov-0/+13
2024-04-24Auto merge of #122053 - erikdesjardins:alloca, r=nikicbors-1/+1
Stop using LLVM struct types for alloca The alloca type has no semantic meaning, only the size (and alignment, but we specify it explicitly) matter. Using `[N x i8]` is a more direct way to specify that we want `N` bytes, and avoids relying on LLVM's struct layout. It is likely that a future LLVM version will change to an untyped alloca representation. Split out from #121577. r? `@ghost`
2024-04-11use [N x i8] for alloca typesErik Desjardins-1/+1
2024-04-11Put `PlaceValue` into `OperandValue::Ref`, rather than 3 tuple fieldsScott McMurray-3/+8
2024-04-11Make `PlaceRef` hold a `PlaceValue` for the non-layout fields (like ↵Scott McMurray-1/+1
`OperandRef` does)
2024-04-08force_array -> is_consecutiveNikita Popov-1/+4
The actual ABI implication here is that in some cases the values are required to be "consecutive", i.e. must either all be passed in registers or all on stack (without padding). Adjust the code to either use Uniform::new() or Uniform::consecutive() depending on which behavior is needed. Then, when lowering this in LLVM, skip the [1 x i128] to i128 simplification if is_consecutive is set. i128 is the only case I'm aware of where this is problematic right now. If we find other cases, we can extend this (either based on target information or possibly just by not simplifying for is_consecutive entirely).
2024-04-08Fix argument ABI for overaligned structs on ppc64leNikita Popov-1/+1
When passing a 16 (or higher) aligned struct by value on ppc64le, it needs to be passed as an array of `i128` rather than an array of `i64`. This will force the use of an even starting register. For the case of a 16 byte struct with alignment 16 it is important that `[1 x i128]` is used instead of `i128` -- apparently, the latter will get treated similarly to `[2 x i64]`, not exhibiting the correct ABI. Add a `force_array` flag to `Uniform` to support this. The relevant clang code can be found here: https://github.com/llvm/llvm-project/blob/fe2119a7b08b6e468b2a67768904ea85b1bf0a45/clang/lib/CodeGen/Targets/PPC.cpp#L878-L884 https://github.com/llvm/llvm-project/blob/fe2119a7b08b6e468b2a67768904ea85b1bf0a45/clang/lib/CodeGen/Targets/PPC.cpp#L780-L784 I think the corresponding psABI wording is this: > Fixed size aggregates and unions passed by value are mapped to as > many doublewords of the parameter save area as the value uses in > memory. Aggregrates and unions are aligned according to their > alignment requirements. This may result in doublewords being > skipped for alignment. In particular the last sentence. Fixes https://github.com/rust-lang/rust/issues/122767.
2024-03-17make PassMode::Cast consistently copy between Rust/ABI representationErik Desjardins-41/+27
Previously, we did this slightly incorrectly for return values, and didn't do it at all for arguments.
2024-03-17make CastTarget::size and CastTarget::llvm_type consistent, removeErik Desjardins-28/+24
special case that's not present in Clang Making the methods consistent doesn't require much justification. It's required for us to generate correct code. The special case was present near the end of `CastTarget::llvm_type`, and resulted in the final integer component of the ABI type being shrunk to the smallest integer that fits. You can see this in action here (https://godbolt.org/z/Pe73cr91d), where, for a struct with 5 u16 elements, rustc generates `{ i64, i16 }`, while Clang generates `[2 x i64]`. This special case was added a long time ago, when the function was originally written [1]. That commit consolidated logic from many backends, and in some of the code it deleted, sparc64 [2] and powerpc64 [3] had similar special cases. However, looking at Clang today, it doesn't have this special case for sparc64 (https://godbolt.org/z/YaafvYWdf) or powerpc64 (https://godbolt.org/z/5c3YePTje), so this change just removes it. [1]: https://github.com/rust-lang/rust/commit/f0636b61c7f84962a609e831760db9d77f4f5e14#diff-183c4dadf10704bd1f521b71f71d89bf755c9603a93f894d66c03bb1effc6021R231 [2]: https://github.com/rust-lang/rust/commit/f0636b61c7f84962a609e831760db9d77f4f5e14#diff-2d8f87ea6db6d7f0a6fbeb1d5549adc07e93331278d951a1e051a40f92914436L163-L166 [3]: https://github.com/rust-lang/rust/commit/f0636b61c7f84962a609e831760db9d77f4f5e14#diff-88af4a9df9ead503a5c7774a0455d270dea3ba60e9b0ec1ce550b4c53d3bce3bL172-L175
2024-03-11copy byval argument to alloca if alignment is insufficientErik Desjardins-49/+55
2024-03-05use [N x i8] for byval/sret typesErik Desjardins-4/+16
This avoids depending on LLVM's struct types to determine the size of the byval/sret slot.