Commit graph

853 commits

Author SHA1 Message Date
Ralf Jung
5e65109f21 add write_box_via_move intrinsic and use it for vec!
This allows us to get rid of box_new entirely
2026-02-16 17:27:40 +01:00
bjorn3
fa753a46c1 Remove code for ThinLTO from cg_gcc
It was just a dummy implementation to workarround the fact that thin
local lto is the default in rustc. By adding a thin_lto_supported thin
local lto can be automatically disabled for cg_gcc, removing the need
for this dummy implementation. This makes improvements to the LTO
handling on the cg_ssa side a lot easier.
2026-02-15 10:05:48 +00:00
Guillaume Gomez
1f94802603 Fix libgccjit version 2026-02-14 17:12:51 +01:00
Guillaume Gomez
6ea369cfee Merge commit '70ae207ff5' into subtree-update_cg_gcc_2026-02-14 2026-02-14 16:45:12 +01:00
bors
a423f68a0d Auto merge of #152533 - flip1995:clippy-subtree-update, r=Manishearth
Clippy subtree update

r? @Manishearth 

1 week late, due to vacation and some technical issues.
2026-02-13 18:09:00 +00:00
Philipp Krones
eaad11cc2c
cg_gcc: remove Clippy expect attribute 2026-02-12 16:55:36 +01:00
bjorn3
506ed6dcb7 Remove SelfProfilerRef from CodegenContext
It can't be serialized to a file.
2026-02-12 12:44:14 +00:00
Jacob Pratt
c41f9343e9
Rollup merge of #152478 - bjorn3:lto_refactors10, r=wesleywiser
Remove tm_factory field from CodegenContext

This is necessary to support serializing the `CodegenContext` to a `.rlink` file in the future for moving LTO to the `-Zlink-only` step.

Follow up to https://github.com/rust-lang/rust/pull/149209
Part of https://github.com/rust-lang/compiler-team/issues/908
2026-02-12 00:41:08 -05:00
Jacob Pratt
0041f221ea
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
f49223c443 Remove tm_factory field from CodegenContext
This is necessary to support serializing the CodegenContext to a .rlink
file in the future for moving LTO to the -Zlink-only step.
2026-02-11 12:18:04 +00:00
bjorn3
2d07e81a5c Move target machine factory error reporting into codegen backend 2026-02-11 10:53:38 +00:00
bjorn3
d2a0557afb Convert to inline diagnostics in all codegen backends 2026-02-04 13:12:49 +00:00
xtqqczze
abcd22d5ed 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
75963ce795 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
3a69035338
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
6db94dbc25 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
2206d935f7
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
dd9241d150
c_variadic: use Clone instead of LLVM va_copy 2026-01-20 18:38:50 +01:00
Folkert de Vries
120388c063
simd_splat: custom error in gcc backend for invalid element type 2026-01-19 16:56:20 +01:00
Folkert de Vries
80c0b99de0
add simd_splat intrinsic 2026-01-19 16:48:28 +01:00
Nicholas Nethercote
3aa31788b5 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
8e3d60447c Finish transition from semitransparent to semiopaque for rustc_macro_transparency 2026-01-08 19:14:45 +01:00
bjorn3
f1ab003658 Don't compute FnAbi for LLVM intrinsics in backends 2026-01-08 10:47:29 +00:00
bjorn3
acc8c0bd65 Reduce usage of FnAbi in codegen_llvm_intrinsic_call 2026-01-08 10:45:43 +00:00
bjorn3
aeac6cb2d6 Fix compilation of cg_gcc with master feature disabled 2025-12-27 18:41:14 +00:00
bjorn3
9bcd6ed4c9 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
c506e23426 Pass Function to Builder::function_call in cg_gcc 2025-12-27 17:46:26 +00:00
bjorn3
b40eae863a Don't assume get_fn is only called from codegen_mir in cg_gcc 2025-12-27 17:46:26 +00:00
bjorn3
62e17e920c Move llvm intrinsic call to backend 2025-12-27 17:46:25 +00:00
Guillaume Gomez
d5b6bd87ec Merge commit '02f889aec5' 2025-12-21 00:13:38 +01:00
David Wood
a56b1b9283
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
a9511b9b49 When we cannot load libgccjit.so, show the paths that were tried 2025-12-15 08:35:17 -05:00
bors
8188f6c808 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
b32845c61a
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
397339e928
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
146711fc24 Use let...else instead of match foo { ... _ => return }; and if let ... else return 2025-12-12 17:52:39 +00:00
Urgau
b1eb21bb85 Adapt and fix cg_gcc to the overhauled filename remapping 2025-12-12 07:34:52 +01:00
Matthias Krüger
573ed40b89
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
6078dd3bdf
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
4501327be4 Fix clippy lint in cg_gcc 2025-12-09 16:26:10 +01:00
Antoni Boucher
42059a3041 Remove libgccjit_path function 2025-12-05 09:58:37 -05:00
Antoni Boucher
58f3f313b3 Fix lib path 2025-12-05 09:55:02 -05:00
Antoni Boucher
2a74c626d6 Move to rustlib directory 2025-12-05 09:52:02 -05:00
Antoni Boucher
76bee3a044 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
b33119ffdd 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
94f1bfe1fc Merge commit 'dab6863ce8' into subtree-update_cg_gcc_2025-12-04 2025-12-04 14:53:08 +01:00
Paul Murphy
b54b288518 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
d3653e9f59 Remove an unnecessary unwrap in rustc_codegen_gcc 2025-11-29 10:34:07 +01:00
bjorn3
8f55c15bfe 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
10776a4071 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