about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src/traits/builder.rs
AgeCommit message (Collapse)AuthorLines
2025-09-19added typetree support for memcpyKaran Janthe-1/+2
2025-09-16Update the FIXME comments in the generic three_way_compareJosh Stone-8/+11
2025-09-16Update the minimum external LLVM to 20Josh Stone-7/+31
2025-08-08Rollup merge of #144192 - RalfJung:atomicrmw-ptr, r=nikicTrevor Gross-0/+3
atomicrmw on pointers: move integer-pointer cast hacks into backend Conceptually, we want to have atomic operations on pointers of the form `fn atomic_add(ptr: *mut T, offset: usize, ...)`. However, LLVM does not directly support such operations (https://github.com/llvm/llvm-project/issues/120837), so we have to cast the `offset` to a pointer somewhere. This PR moves that hack into the LLVM backend, so that the standard library, intrinsic, and Miri all work with the conceptual operation we actually want. Hopefully, one day LLVM will gain a way to represent these operations without integer-pointer casts, and then the hack will disappear entirely. Cc ```@nikic``` -- this is the best we can do right now, right? Fixes https://github.com/rust-lang/rust/issues/134617
2025-07-26Implement support for explicit tail calls in the MIR block builders and the ↵Joel Wejdenstål-0/+12
LLVM codegen backend.
2025-07-23atomicrmw on pointers: move integer-pointer cast hacks into backendRalf Jung-0/+3
2025-07-12Auto merge of #143810 - matthiaskrgr:rollup-iw7a23z, r=matthiaskrgrbors-1/+22
Rollup of 9 pull requests Successful merges: - rust-lang/rust#143403 (Port several trait/coherence-related attributes the new attribute system) - rust-lang/rust#143633 (fix: correct assertion to check for 'noinline' attribute presence before removal) - rust-lang/rust#143647 (Clarify and expand documentation for std::sys_common dependency structure) - rust-lang/rust#143716 (compiler: doc/comment some codegen-for-functions interfaces) - rust-lang/rust#143747 (Add target maintainer information for aarch64-unknown-linux-musl) - rust-lang/rust#143759 (Fix typos in function names in the `target_feature` test) - rust-lang/rust#143767 (Bump `src/tools/x` to Edition 2024 and some cleanups) - rust-lang/rust#143769 (Remove support for SwitchInt edge effects in backward dataflow) - rust-lang/rust#143770 (build-helper: clippy fixes) r? `@ghost` `@rustbot` modify labels: rollup
2025-07-12Auto merge of #143766 - matthiaskrgr:rollup-0x7t69s, r=matthiaskrgrbors-0/+10
Rollup of 8 pull requests Successful merges: - rust-lang/rust#142391 (rust: library: Add `setsid` method to `CommandExt` trait) - rust-lang/rust#143302 (`tests/ui`: A New Order [27/N]) - rust-lang/rust#143303 (`tests/ui`: A New Order [28/28] FINAL PART) - rust-lang/rust#143568 (std: sys: net: uefi: tcp4: Add timeout support) - rust-lang/rust#143611 (Mention more APIs in `ParseIntError` docs) - rust-lang/rust#143661 (chore: Improve how the other suggestions message gets rendered) - rust-lang/rust#143708 (fix: Include frontmatter in -Zunpretty output ) - rust-lang/rust#143718 (Make UB transmutes really UB in LLVM) r? `@ghost` `@rustbot` modify labels: rollup try-job: i686-gnu-nopt-1 try-job: test-various
2025-07-11Rollup merge of #143716 - ↵Matthias Krüger-1/+22
workingjubilee:document-some-codegen-backend-stuff, r=bjorn3,fee1-dead compiler: doc/comment some codegen-for-functions interfaces An out-of-date comment gets updated and some underdocumented functions get documented.
2025-07-11compiler: comment on some call-related codegen fn in cg_ssaJubilee Young-1/+22
Partially documents the situation due to LLVM CFI.
2025-07-10Add `BuilderMethods::unreachable_nonterminator`Scott McMurray-0/+10
So places that need `unreachable` but in the middle of a basic block can call that instead of figuring out the best way to do it.
2025-07-07Remove support for dynamic allocasmejrs-1/+0
2025-07-03setup CI and tidy to use typos for spellchecking and fix few typosklensy-1/+1
2025-06-22Remove dead instructions in terminate blocksMark Rousskov-1/+1
2025-06-12Simplify implementation of Rust intrinsics by using type parameters in the cachesayantn-2/+2
2025-05-30Rollup merge of #141507 - RalfJung:atomic-intrinsics, r=bjorn3Matthias Krüger-4/+2
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-28get rid of rustc_codegen_ssa::common::AtomicOrderingRalf Jung-4/+2
2025-05-28The personality function is a Function, not a Valuebjorn3-3/+3
2025-03-24Auto merge of #133984 - DaniPopes:scmp-ucmp, r=scottmcmbors-0/+12
Lower BinOp::Cmp to llvm.{s,u}cmp.* intrinsics Lowers `mir::BinOp::Cmp` (`three_way_compare` intrinsic) to the corresponding LLVM `llvm.{s,u}cmp.i8.*` intrinsics. These are the intrinsics mentioned in https://github.com/rust-lang/rust/pull/118310, which are now available in LLVM 19. I couldn't find any follow-up PRs/discussions about this, please let me know if I missed something. r? `@scottmcm`
2025-03-06Lower BinOp::Cmp to llvm.{s,u}cmp.* intrinsicsDaniPopes-0/+12
Lowers `mir::BinOp::Cmp` (`three_way_compare` intrinsic) to the corresponding LLVM `llvm.{s,u}cmp.i8.*` intrinsics, added in LLVM 19.
2025-02-24Remove an unused lifetime paramOli Scherer-1/+1
2025-02-24Auto merge of #137271 - nikic:gep-nuw-2, r=scottmcmbors-0/+8
Emit getelementptr inbounds nuw for pointer::add() Lower pointer::add (via intrinsic::offset with unsigned offset) to getelementptr inbounds nuw on LLVM versions that support it. This lets LLVM make use of the pre-condition that the offset addition does not wrap in an unsigned sense. Together with inbounds, this also implies that the offset is non-negative. Fixes https://github.com/rust-lang/rust/issues/137217.
2025-02-19Rework `OperandRef::extract_field` to stop calling `to_immediate_scalar` on ↵Scott McMurray-8/+1
things which are already immediates That means it stops trying to truncate things that are already `i1`s.
2025-02-19Emit `trunc nuw` for unchecked shifts and `to_immediate_scalar`Scott McMurray-0/+11
- For shifts this shrinks the IR by no longer needing an `assume` while still providing the UB information - Having this on the `i8`→`i1` truncations will hopefully help with some places that have to load `i8`s or pass those in LLVM structs without range information
2025-02-19Emit getelementptr inbounds nuw for pointer::add()Nikita Popov-0/+8
2025-02-18Auto merge of #133852 - x17jiri:cold_path, r=saethlinbors-0/+14
improve cold_path() #120370 added a new instrinsic `cold_path()` and used it to fix `likely` and `unlikely` However, in order to limit scope, the information about cold code paths is only used in 2-target switch instructions. This is sufficient for `likely` and `unlikely`, but limits usefulness of `cold_path` for idiomatic rust. For example, code like this: ``` if let Some(x) = y { ... } ``` may generate 3-target switch: ``` switch y.discriminator: 0 => true branch 1 = > false branch _ => unreachable ``` and therefore marking a branch as cold will have no effect. This PR improves `cold_path()` to work with arbitrary switch instructions. Note that for 2-target switches, we can use `llvm.expect`, but for multiple targets we need to manually emit branch weights. I checked Clang and it also emits weights in this situation. The Clang's weight calculation is more complex that this PR, which I believe is mainly because `switch` in `C/C++` can have multiple cases going to the same target.
2025-02-17improve cold_path()Jiri Bobek-0/+14
2025-02-14Auto merge of #136575 - scottmcm:nsuw-math, r=nikicbors-6/+29
Set both `nuw` and `nsw` in slice size calculation There's an old note in the code to do this, and now that [LLVM-C has an API for it](https://github.com/llvm/llvm-project/blob/f0b8ff12519270adcfef93410abff76ab073476a/llvm/include/llvm-c/Core.h#L4403-L4408), we might as well. And it's been there since what looks like LLVM 17 https://github.com/llvm/llvm-project/commit/de9b6aa341d8951625d62ae3dac8670ebb3eb006 so doesn't even need to be conditional. (There's other places, like `RawVecInner` or `Layout`, that might want to do things like this too, but I'll leave those for a future PR.)
2025-02-13Set both `nuw` and `nsw` in slice size calculationScott McMurray-6/+29
There's an old note in the code to do this, and now that LLVM-C has an API for it, we might as well.
2025-02-12`transmute` should also assume non-null pointersScott McMurray-0/+13
Previously it only did integer-ABI things, but this way it does data pointers too. That gives more information in general to the backend, and allows slightly simplifying one of the helpers in slice iterators.
2025-01-31Override `disjoint_or` in the LLVM backendScott McMurray-0/+5
2025-01-17Update our range `assume`s to the format that LLVM prefersScott McMurray-0/+21
2024-12-25rename typed_swap → typed_swap_nonoverlappingRalf Jung-1/+1
2024-11-17Likely unlikely fixJiri Bobek-0/+20
2024-11-03compiler: Directly use rustc_abi in codegenJubilee Young-1/+1
2024-10-29compiler: `rustc_abi::Abi` => `BackendRepr`Jubilee Young-2/+2
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-25coverage: SSA doesn't need to know about `instrprof_increment`Zalathar-8/+0
2024-09-24Auto merge of #130389 - Luv-Ray:LLVMMDNodeInContext2, r=nikicbors-0/+1
llvm: replace some deprecated functions `LLVMMDStringInContext` and `LLVMMDNodeInContext` are deprecated, replace them with `LLVMMDStringInContext2` and `LLVMMDNodeInContext2`. Also replace `Value` with `Metadata` in some function signatures for better consistency.
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-1/+1
2024-09-19replace some deprecated functionsLuv-Ray-0/+1
2024-09-17Rename supertraits of `CodegenMethods`.Nicholas Nethercote-3/+3
Supertraits of `BuilderMethods` are all called `XyzBuilderMethods`. Supertraits of `CodegenMethods` are all called `XyzMethods`. This commit changes the latter to `XyzCodegenMethods`, for consistency.
2024-09-17Tweak and explain the `BuilderMethods`/`CodegenMethods` connection.Nicholas Nethercote-3/+6
2024-09-17Remove unneeded bounds from `CodegenMethods` and `BuilderMethods`.Nicholas Nethercote-4/+1
Some of these are pulled in indirectly, e.g. `MiscMethods` via `TypeMethods`.
2024-09-17Rename `{ArgAbi,IntrinsicCall}Methods`.Nicholas Nethercote-4/+4
They both are part of `BuilderMethods`, and so should have `Builder` in their name like all the other traits in `BuilderMethods`.
2024-09-17Remove `Backend`.Nicholas Nethercote-3/+5
It's a trait that aggregates five other traits. But consider the places that use it. - `BuilderMethods`: requires three of the five traits. - `CodegenMethods`: requires zero(!) of the five traits. - `BaseTypeMethods`: requires two of the five traits. - `LayoutTypeMethods`: requires three of the five traits. - `TypeMembershipMethods`: requires one of the five traits. This commit just removes it, which makes everything simpler.
2024-09-17Merge `HasCodegen` into `BuilderMethods`.Nicholas Nethercote-2/+16
It has `Backend` and `Deref` boudns, plus an associated type `CodegenCx`, and it has a single use. This commit "inlines" it into `BuilderMethods`, which makes the complicated backend trait situation a little simpler.
2024-08-11Use assert_matches around the compilerMichael Goulet-2/+4
2024-08-04Add `Debug` impls to API types in `rustc_codegen_ssa`Mahmoud Mazouz-1/+1
2024-07-29Reformat `use` declarations.Nicholas Nethercote-10/+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-20compiler: Never debug_assert in codegenJubilee Young-6/+6
The gains in performance are not worth the costs in correctness. This is partly because the gains are zero and the costs are unknown.