Commit graph

869 commits

Author SHA1 Message Date
Jacob Pratt
4e244c7cd5 Rollup merge of #150768 - bjorn3:llvm_intrinsic_no_fn_abi, r=wesleywiser
Don't compute FnAbi for LLVM intrinsics in backends

~~This removes support for `extern "unadjusted"` for anything other than LLVM intrinsics. It only makes sense in the context of calling LLVM intrinsics anyway as it exposes the way the LLVM backend internally represents types. Perhaps it should be renamed to `extern "llvm-intrinsic"`?~~

Follow up to https://github.com/rust-lang/rust/pull/148533
2026-02-12 00:41:06 -05:00
bjorn3
e4e725aec6 Convert to inline diagnostics in all codegen backends 2026-02-04 13:12:49 +00:00
xtqqczze
b7728f072e Omit standard copyright notice
Remove copyright notices for files licensed under the standard terms (MIT OR Apache-2.0).
2026-01-26 17:31:34 +00:00
bors
d8306375a7 Auto merge of #151065 - nagisa:add-preserve-none-abi, r=petrochenkov
abi: add a rust-preserve-none calling convention

This is the conceptual opposite of the rust-cold calling convention and is particularly useful in combination with the new `explicit_tail_calls` feature.

For relatively tight loops implemented with tail calling (`become`) each of the function with the regular calling convention is still responsible for restoring the initial value of the preserved registers. So it is not unusual to end up with a situation where each step in the tail call loop is spilling and reloading registers, along the lines of:

    foo:
        push r12
        ; do things
        pop r12
        jmp next_step

This adds up quickly, especially when most of the clobberable registers are already used to pass arguments or other uses.

I was thinking of making the name of this ABI a little less LLVM-derived and more like a conceptual inverse of `rust-cold`, but could not come with a great name (`rust-cold` is itself not a great name: cold in what context? from which perspective? is it supposed to mean that the function is rarely called?)
2026-01-25 02:49:32 +00:00
Matthias Krüger
87c0c90ac0 Rollup merge of #151346 - folkertdev:simd-splat, r=workingjubilee
add `simd_splat` intrinsic

Add `simd_splat` which lowers to the LLVM canonical splat sequence.

```llvm
insertelement <N x elem> poison, elem %x, i32 0
shufflevector <N x elem> v0, <N x elem> poison, <N x i32> zeroinitializer
```

Right now we try to fake it using one of

```rust
fn splat(x: u32) -> u32x8 {
    u32x8::from_array([x; 8])
}
```

or (in `stdarch`)

```rust
fn splat(value: $elem_type) -> $name {
    #[derive(Copy, Clone)]
    #[repr(simd)]
    struct JustOne([$elem_type; 1]);
    let one = JustOne([value]);
    // SAFETY: 0 is always in-bounds because we're shuffling
    // a simd type with exactly one element.
    unsafe { simd_shuffle!(one, one, [0; $len]) }
}
```

Both of these can confuse the LLVM optimizer, producing sub-par code. Some examples:

- https://github.com/rust-lang/rust/issues/60637
- https://github.com/rust-lang/rust/issues/137407
- https://github.com/rust-lang/rust/issues/122623
- https://github.com/rust-lang/rust/issues/97804

---

As far as I can tell there is no way to provide a fallback implementation for this intrinsic, because there is no `const` way of evaluating the number of elements (there might be issues beyond that, too). So, I added implementations for all 4 backends.

Both GCC and const-eval appear to have some issues with simd vectors containing pointers. I have a workaround for GCC, but haven't yet been able to make const-eval work. See the comments below.

Currently this just adds the intrinsic, it does not actually use it anywhere yet.
2026-01-24 21:04:15 +01:00
Simonas Kazlauskas
0cb56dc92c abi: add a rust-preserve-none calling convention
This is the conceptual opposite of the rust-cold calling convention and
is particularly useful in combination with the new `explicit_tail_calls`
feature.

For relatively tight loops implemented with tail calling (`become`) each
of the function with the regular calling convention is still responsible
for restoring the initial value of the preserved registers. So it is not
unusual to end up with a situation where each step in the tail call loop
is spilling and reloading registers, along the lines of:

    foo:
        push r12
        ; do things
        pop r12
        jmp next_step

This adds up quickly, especially when most of the clobberable registers
are already used to pass arguments or other uses.

I was thinking of making the name of this ABI a little less LLVM-derived
and more like a conceptual inverse of `rust-cold`, but could not come
with a great name (`rust-cold` is itself not a great name: cold in what
context? from which perspective? is it supposed to mean that the
function is rarely called?)
2026-01-24 19:23:17 +02:00
Jacob Pratt
56d32942a5 Rollup merge of #149209 - lto_refactors8, r=jackh726
Move LTO to OngoingCodegen::join

This will make it easier to in the future move all this code to link_binary.

Follow up to https://github.com/rust-lang/rust/pull/147810
Part of https://github.com/rust-lang/compiler-team/issues/908
2026-01-21 02:04:01 -05:00
Folkert de Vries
012c4603b7 c_variadic: use Clone instead of LLVM va_copy 2026-01-20 18:38:50 +01:00
Folkert de Vries
e0b87e4dd5 simd_splat: custom error in gcc backend for invalid element type 2026-01-19 16:56:20 +01:00
Folkert de Vries
f11abba641 add simd_splat intrinsic 2026-01-19 16:48:28 +01:00
Nicholas Nethercote
c9a063ced9 Remove Deref/DerefMut impl for Providers.
It's described as a "backwards compatibility hack to keep the diff
small". Removing it requires only a modest amount of churn, and the
resulting code is clearer without the invisible derefs.
2026-01-14 15:55:59 +11:00
Martin Nordholts
fe0facf0f6 Finish transition from semitransparent to semiopaque for rustc_macro_transparency 2026-01-08 19:14:45 +01:00
bjorn3
e90414f622 Don't compute FnAbi for LLVM intrinsics in backends 2026-01-08 10:47:29 +00:00
bjorn3
f004b3eb19 Reduce usage of FnAbi in codegen_llvm_intrinsic_call 2026-01-08 10:45:43 +00:00
bjorn3
ea8f037c76 Fix compilation of cg_gcc with master feature disabled 2025-12-27 18:41:14 +00:00
bjorn3
5bcd472b86 Partially inline get_fn_addr/get_fn in codegen_llvm_intrinsic_call
This moves all LLVM intrinsic handling out of the regular call path for
cg_gcc and makes it easier to hook into this code for future cg_llvm
changes.
2025-12-27 17:46:26 +00:00
bjorn3
56be08eb45 Pass Function to Builder::function_call in cg_gcc 2025-12-27 17:46:26 +00:00
bjorn3
0462ce9934 Don't assume get_fn is only called from codegen_mir in cg_gcc 2025-12-27 17:46:26 +00:00
bjorn3
9ba3ed5423 Move llvm intrinsic call to backend 2025-12-27 17:46:25 +00:00
Guillaume Gomez
bf5283cf6f Merge commit '02f889aec5' 2025-12-21 00:13:38 +01:00
David Wood
11bc2e0907 codegen: implement repr(scalable)
Introduces `BackendRepr::ScalableVector` corresponding to scalable
vector types annotated with `repr(scalable)` which lowers to a scalable
vector type in LLVM.

Co-authored-by: Jamie Cunliffe <Jamie.Cunliffe@arm.com>
2025-12-16 11:00:12 +00:00
Antoni Boucher
f0418b3461 When we cannot load libgccjit.so, show the paths that were tried 2025-12-15 08:35:17 -05:00
bors
09c34cbac3 Auto merge of #149709 - Urgau:overhaul-filenames, r=davidtwco
Overhaul filename handling for cross-compiler consistency

This PR overhauls the way we handle filenames in the compiler and `rmeta` in order to achieve achieve cross-compiler consistency (ie. having the same path no matter if the filename was created in the current compiler session or is coming from `rmeta`).

This is required as some parts of the compiler rely on consistent paths for the soundness of generated code (see rust-lang/rust#148328).

In order to achieved consistency multiple steps are being taken by this PR:
 - by making `RealFileName` immutable
 - by only having `SourceMap::to_real_filename` create `RealFileName`
   - currently `RealFileName` can be created from any `Path` and are remapped afterwards, which creates consistency issue
 - by also making `RealFileName` holds it's working directory, embeddable name and the remapped scopes
   - this removes the need for a `Session`, to know the current(!) scopes and cwd, which is invalid as they may not be equal to the scopes used when creating the filename

In order for `SourceMap::to_real_filename` to know which scopes to apply `FilePathMapping` now takes the current remapping scopes to apply, which makes `FileNameDisplayPreference` and company useless and are removed.

This PR is split-up in multiple commits (unfortunately not atomic), but should help review the changes.

Unblocks https://github.com/rust-lang/rust/pull/147611
Fixes https://github.com/rust-lang/rust/issues/148328
2025-12-13 14:32:09 +00:00
Jacob Pratt
2afb92fe61 Rollup merge of #148837 - estebank:let-else, r=Kivooeo
Use `let...else` instead of `match foo { ... _ => return };` and `if let ... else return`
2025-12-13 00:55:55 -05:00
Jacob Pratt
8ff1c63605 Rollup merge of #145278 - notJoon:doc/rotate-operation, r=antoyo
Update `rustc_codegen_gcc` rotate operation document

## Description

This PR resolves a TODO comment in the `rustc_codegen_gcc` backend by documenting that the rotate operations (`rotate_left` and `rotate_right`) already implement the optimized branchless algorithm from comment.

The existing implementation already uses the optimal branchless rotation pattern:
- For left rotation: `(x << n) | (x >> (-n & (width-1)))`
- For right rotation: `(x >> n) | (x << (-n & (width-1)))`

This pattern avoids branches and generates efficient machine code across different platforms, which was the goal mentioned in the original TODO.

## Changes

- Removed the TODO comment that suggested implementing the algorithm from https://blog.regehr.org/archives/1063
2025-12-13 00:55:54 -05:00
Esteban Küber
824f41ea6f Use let...else instead of match foo { ... _ => return }; and if let ... else return 2025-12-12 17:52:39 +00:00
Urgau
a95aaca249 Adapt and fix cg_gcc to the overhauled filename remapping 2025-12-12 07:34:52 +01:00
Matthias Krüger
bc06068785 Rollup merge of #149458 - GuillaumeGomez:clippy-cg_gcc, r=kobzol
Run clippy on cg_gcc in CI

This is to prevent [this issue](https://github.com/rust-lang/rust/pull/149449#discussion_r2573045524): in cg_gcc repository, we run clippy on our code but not in here, which can create issues.

cc ````@antoyo````
r? ````@Kobzol````
2025-12-10 07:54:19 +01:00
Matthias Krüger
c53b4c3fe2 Rollup merge of #147725 - bjorn3:remove_oom_panic, r=Amanieu
Remove -Zoom=panic

There are major questions remaining about the reentrancy that this allows. It doesn't have any users on github outside of a single project that uses it in a panic=abort project to show backtraces. It can still be emulated through `#[alloc_error_handler]` or `set_alloc_error_hook` depending on if you use the standard library or not. And finally it makes it harder to do various improvements to the allocator shim.

With this PR the sole remaining symbol in the allocator shim that is not effectively emulating weak symbols is the symbol that prevents skipping the allocator shim on stable even when it would otherwise be empty because libstd + `#[global_allocator]` is used.

Closes https://github.com/rust-lang/rust/issues/43596
Fixes https://github.com/rust-lang/rust/issues/126683
2025-12-10 07:54:17 +01:00
Guillaume Gomez
e6143962f9 Fix clippy lint in cg_gcc 2025-12-09 16:26:10 +01:00
Antoni Boucher
ff29461e1a Remove libgccjit_path function 2025-12-05 09:58:37 -05:00
Antoni Boucher
b00418c0f5 Fix lib path 2025-12-05 09:55:02 -05:00
Antoni Boucher
8e77eeb017 Move to rustlib directory 2025-12-05 09:52:02 -05:00
Antoni Boucher
c0d4f5fab1 Move the libgccjit.so file in a target directory
Since GCC is not multi-target, we need multiple libgccjit.so.
Our solution to have a directory per target so that we can have multiple
libgccjit.so.
2025-12-05 09:51:26 -05:00
bors
8d9b1d0292 Auto merge of #149642 - GuillaumeGomez:subtree-update_cg_gcc_2025-12-04, r=GuillaumeGomez
cg_gcc subtree update

cc `@antoyo`

r? ghost
2025-12-04 17:48:32 +00:00
Guillaume Gomez
701b9ba0fb Merge commit 'dab6863ce8' into subtree-update_cg_gcc_2025-12-04 2025-12-04 14:53:08 +01:00
Paul Murphy
5c467cb4d1 Allow PowerPC spe_acc as clobber-only register
This register is only supported on the *powerpc*spe targets. It is
only recognized by LLVM. gcc does not accept this as a clobber, nor
does it support these targets.

This is a volatile register, thus it is included with clobber_abi.
2025-12-03 12:37:22 -06:00
AudaciousAxiom
1c89fe9d6d Remove an unnecessary unwrap in rustc_codegen_gcc 2025-11-29 10:34:07 +01:00
bjorn3
4054d07d38 Remove -Zoom=panic
There are major questions remaining about the reentrancy that this
allows. It doesn't have any users on github outside of a single project
that uses it in a panic=abort project to show backtraces. It
can still be emulated through #[alloc_error_handler] or
set_alloc_error_hook depending on if you use the standard library or
not. And finally it makes it harder to do various improvements to the
allocator shim.
2025-11-28 19:30:39 +00:00
bors
d923fdd90b Auto merge of #149348 - GuillaumeGomez:subtree-update_cg_gcc_2025-11-26, r=GuillaumeGomez
cg_gcc subtree sync

cc `@antoyo`
2025-11-28 01:53:22 +00:00
Guillaume Gomez
8059907cef Update GCC submodule 2025-11-26 20:11:43 +01:00
Guillaume Gomez
a7ea98bf2c Update GCC commit 2025-11-26 19:43:53 +01:00
Guillaume Gomez
2af849a6e5 Merge commit '55171cfa8b' into subtree-update_cg_gcc_2025-11-26 2025-11-26 19:41:43 +01:00
bjorn3
cbc3860a72 Use rust rather than LLVM target features in the target spec
This works better with non-LLVM codegen backends.
2025-11-25 14:39:42 +00:00
bjorn3
385590e9dc Remove SharedEmitter from CodegenContext 2025-11-23 10:33:52 +00:00
bjorn3
67c61cefaf Remove opts field from CodegenContext 2025-11-23 10:33:52 +00:00
bors
3e1d5371ea Auto merge of #148481 - GuillaumeGomez:subtree-update_cg_gcc_2025-11-04, r=GuillaumeGomez
Sync rustc_codegen_gcc subtree

cc `@antoyo`

r? ghost
2025-11-13 18:00:02 +00:00
Jeremy Fitzhardinge
f7b6605209 Add -Zannotate-moves for profiler visibility of move/copy operations
This implements a new unstable compiler flag `-Zannotate-moves` that makes
move and copy operations visible in profilers by creating synthetic debug
information. This is achieved with zero runtime cost by manipulating debug
info scopes to make moves/copies appear as calls to `compiler_move<T, SIZE>`
and `compiler_copy<T, SIZE>` marker functions in profiling tools.

This allows developers to identify expensive move/copy operations in their
code using standard profiling tools, without requiring specialized tooling
or runtime instrumentation.

The implementation works at codegen time. When processing MIR operands
(`Operand::Move` and `Operand::Copy`), the codegen creates an `OperandRef`
with an optional `move_annotation` field containing an `Instance` of the
appropriate profiling marker function. When storing the operand,
`store_with_annotation()` wraps the store operation in a synthetic debug
scope that makes it appear inlined from the marker.

Two marker functions (`compiler_move` and `compiler_copy`) are defined
in `library/core/src/profiling.rs`. These are never actually called -
they exist solely as debug info anchors.

Operations are only annotated if the type:
   - Meets the size threshold (default: 65 bytes, configurable via
     `-Zannotate-moves=SIZE`)
   - Has a non-scalar backend representation (scalars use registers,
     not memcpy)

This has a very small size impact on object file size. With the default
limit it's well under 0.1%, and even with a very small limit of 8 bytes
it's still ~1.5%. This could be enabled by default.
2025-11-06 15:39:45 -08:00
bors
7d3a4569d3 Auto merge of #148544 - matthiaskrgr:rollup-n9dqgwc, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - rust-lang/rust#147994 (Deduplicate deprecation warning when using unit or tuple structs)
 - rust-lang/rust#148440 ([rustdoc search] Simplify itemTypes and filter "dependencies")
 - rust-lang/rust#148501 (triagebot: Create Zulip topics for libs backports)
 - rust-lang/rust#148517 (Remove no longer necessary lint allow)
 - rust-lang/rust#148518 (Unify the configuration of the compiler docs)
 - rust-lang/rust#148523 (miri subtree update)
 - rust-lang/rust#148525 (Fix ICE from lit_to_mir_constant caused by type error)
 - rust-lang/rust#148534 (Merge `Vec::push{,_mut}_within_capacity`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-11-05 21:07:24 +00:00
bors
2b0da9bf1f Auto merge of #148516 - bjorn3:target_feature_parsing_improvements, r=WaffleLapkin
Move warning reporting from flag_to_backend_features to cfg_target_feature

This way warnings are emitted even in a check build.
2025-11-05 17:56:16 +00:00