Commit Graph

1024 Commits

Author SHA1 Message Date
James Barford-Evans
af2f1f375c use ConstExt for methods that do not yet exist in rustc_type_ir 2026-09-22 13:04:44 +01:00
bors
c64de18c55 Auto merge of #162499 - GuillaumeGomez:subtree-update_cg_gcc_2026-09-08, r=antoyo
`rustc_codegen_gcc` subtree update



r? antoyo
2026-09-22 08:08:25 +00:00
James Barford-Evans
c56a9917d8 Wire up f16b in backends 2026-09-21 08:57:52 +01:00
Guillaume Gomez
cf4bee6837 Remove forgotten file 2026-09-18 22:52:45 +02:00
Guillaume Gomez
c10c4cf936 Fix source code divergence 2026-09-18 20:56:48 +02:00
Guillaume Gomez
f5965de6c2 Merge commit '39f626bc72757517b75d8e2dde50fa832b8d6c03' 2026-09-18 20:51:24 +02:00
Nicholas Nethercote
8515e12560 Remove global_backend_features query
It's now possible to get the backend features (a `Vec<String>`) when the
codegen backend is started, pass it back through `CodegenBackendInit`,
and just store it in the `Session`. This removes the need for the query.

Also:

- `WriteBackendMethods::target_machine_factory` no longer needs the
  `target_features` parameter, because it's now available through the
  `sess` parameter.

- `CodegenContext` no longer needs the `backend_features` field because
  we can use `sess.global_backend_features` instead.

- `CodegenBackend::provide` is now a no-op for all the in-tree backends.
  I haven't removed it because out-of-tree backends still rely on it.
2026-09-16 15:29:44 +10:00
Nicholas Nethercote
81210c9d79 Change CodegenBackend::init to take &mut self
It currently takes `&self`, which is a bit strange for an `init` method.
As a result, the Cranelift and GCC backends have to use types with
interior mutability.

This commit changes it to `&mut self`. Benefits:

- The Cranelift backend can use `Option` instead of `OnceCell` to
  indicate uninit vs. init.

- The GCC backend can avoid `Mutex`, and use `bool` instead of
  `AtomicBool`, which makes things much simpler. The commit also
  restructures `GccCodegenBackend` to mirror `CraneliftCodegenBackend`:
  just contain an `Option<BackendConfig>`, which makes the uninit vs.
  init distinction foolproof. (E.g. no need to set `lto_supported` to
  false and then later overwrite it with the real value.) As part of
  this the `LockedTargetInfo` type is renamed `SharedTargetInfo` because
  that better matches its new internals. (All this compiles both with
  and without the "master" feature set.)
2026-09-16 15:29:44 +10:00
Nicholas Nethercote
51673f89e1 Split build_session
Session creation is currently awkward: we build a mostly-initialized
session, then use it to initialize a codegen backend, and then use the
codegen backend to finish initializing the session.

And it's not just awkward: within the Cranelift backend's `init` method
`sess.lto()` is called, which consults `sess.thin_lto_supported`,
*before* that field has been properly set! In practice it had no effect
but it's worth fixing.

This commit cleans up this mess. It introduces `EarlySession`, which
contains just four `Session` fields, the ones that are needed for
codegen backend initialization. It is now a field within `Session`, and
`Session` derefs to `EarlySession` to avoid changing a zillion
`sess.target`/`sess.opts`/etc. occurrences. `EarlySession` is passed to
`init`, which returns a `CodegenBackendInit` that contains the
backend-specific information needed to build a `Session`. (It replaces
the `replaced_intrinsics`, `fallback_intrinsics`, and
`thin_lto_supported` methods.) The `Session` can then be built in a
single step. No more `Session`/`CodegenBackend` initialization
intermingling.

A few functions that previously took a `Session` now take something
else, e.g. a `Target`. Some `Session` methods are now `EarlySession`
methods. And a new `early_lto` method is used for Cranelift's LTO check.
2026-09-16 15:29:42 +10:00
mejrs
6aaabbb863 compiler: fix bug and span_bug imports 2026-09-15 16:20:18 +02:00
Jonathan Brouwer
7cd747decf Rollup merge of #160023 - antoyo:ssa-indirect-return, r=workingjubilee
Refactor the way cg_ssa handles indirect returns (returns via `sret`) — Take 2

This continues the work that @FractalFir done in rust-lang/rust#144976.

**I managed to make this work, so this confirms the original approach works and is ready to merge.**

r? workingjubilee

(assigning the same reviewer as the original PR)

# The problem

The current way `cg_ssa` handles `PassMode::Indirect` is fundamentally incompatible with the requirements of the GCC backend. This is currently worked around in a very brittle way, that breaks on ARM.

In order to function correctly, `cg_gcc` requires the `sret`(indirect return) pointer to be treated in a special way.

# The solution

This PR separates the `sret` pointer from all the other arguments, allowing each backend to decide how it wants to handle that pointer. This will allow GCC to do it's own thing, while changing nothing on the LLVM side. Currently, the PR just makes both backends preappend the sret arg, mimicking the previous behaviour.

The PR is based on this [zulip suggestion](https://rust-lang.zulipchat.com/#narrow/channel/421156-gsoc/topic/Project.3A.20Bootstrap.20of.20rustc.20with.20rustc_codegen_gcc/near/526487725).

# Assumptions I made.

The PR makes certain assumptions about the ABI handling.

1. No LLVM intrinsic returns via sret. [According to my sources](https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/Can.20LLVM.20intrinsics.20return.20via.20PassMode.3A.3AIndirect.3F), this is always true.
2. Tail calls don't currently return via `sret`. From [asking about](https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/Can.20tail.20calls.20return.20indirectly.28via.20a.20pointer.29.3F/near/532984507), it seems like the tail call handling does not currently support indirect returns. So, I did not add support for that.
3. TLS shims don't perform indirect returns, and asserts and drops also don't perform indirect returns(since they return nothing) - those assumptions seemed reasonable.
4. Inline assembly calls don't use indirect returns. I *assumed* functions like `inline_asm_call` will not need the `sret` handling code. I am not 100% sure about this, tough.
2026-09-11 12:45:02 +02:00
bjorn3
052ee70292 Don't rely on codegen emitting fn_abi_of_* errors in abi checks
This avoids a delayed bug if compilation is aborted between checking
function ABIs and codegening all functions.
2026-09-10 09:40:28 +02:00
Antoni Boucher
a714a9e8df Improve the new indirect return API 2026-09-09 11:29:11 -04:00
Antoni Boucher
43965ead44 Add missing indirect return argument to new calls 2026-09-09 11:28:44 -04:00
Fractal Fir(Michał Kostrubiec)
74bba56ab9 Apply suggestions from code review
Co-authored-by: Jubilee <workingjubilee@gmail.com>
2026-09-09 11:14:31 -04:00
FractalFir
e6b7dc8152 Ported cg_gcc to the new cg_ssa version 2026-09-09 11:14:31 -04:00
Jonathan Brouwer
f04af2086f Rollup merge of #160197 - susitsm:restrict-inline-asm-cookies, r=petrochenkov
Restrict LLVM inline asm location cookie usage. Fixes #150451

The parallel frontend makes the cookies nondeterministic in their current form, resulting in nondeterministic outputs when bitcode is emitted or LTO is used.

Causes minor diagnostic regression for inline asm in release builds. See rust-lang/rust#150451 for details.

Fixes rust-lang/rust#150451

r? bjorn3
2026-09-07 17:08:07 +02:00
Matyas Susits
970cb98f0e Disable inline asm line info cookies when llvm bitcode is saved or LTO is enabled
The parallel frontend makes the cookies nondeterministic in their
current form, resulting in nondeterministic outputs when bitcode is
emitted or LTO is used.

Causes minor diagnostic regression for inline asm in release builds.
2026-09-05 11:52:40 +02:00
Amanieu d'Antras
51b3f52eab Merge zreg into vreg and keep ffr in a clobber-only class 2026-09-04 13:29:17 +00:00
Reuben Cruise
7b2bfecd72 Adds support for AArch64 SVE to inline assembly
Adds new `zreg` register type and `SveVec*` variants to `InlineAsmType`
2026-09-04 13:29:17 +00:00
Jonathan Brouwer
f9090000f4 Rollup merge of #160989 - N1ark:08-12-generic-float-intrinsincs, r=folkertdev
Make sin, cos, exp, exp2, log, log2, log10 generic

Rebased and smaller version of rust-lang/rust#153934

Following `fabs`, make the `sin`, `cos`, `exp`, `exp2`, `log`, `log2` and `log10` intrinsics generic over the float type, rather than having four variants per float type.

The first two commits are purely stylistic:
- reorganised Cranelift code to make following changes simpler
- moved a misplaced comment in `compiler/rustc_codegen_llvm/src/intrinsic.rs` that caused `x fmt` to give up

The last commit actually makes them generic! Most code is a bit simpler, ~~and this will also hopefully simplify adding support for these intrinsics for the future [`bf16` type](https://github.com/rust-lang/rust/pull/160859)~~ :)

Unfortunately both GCC and Cranelift backend changes are a bit churny. Their code is a bit, opaque, to put it kindly, and I didn't want to refactor those here.

r? @folkertdev
cc @RalfJung
2026-09-01 13:27:38 +02:00
Jonathan Brouwer
1aeb21ba42 Rollup merge of #137720 - folkertdev:naked-function-target-feature, r=Amanieu
support `#[target_feature(enable = ...)]` on `#[naked]` functions

fixes https://github.com/rust-lang/rust/issues/136280

Instructions that are part of a target feature require a special directive on some targets. This PR adds those for the most common targets.

This is very WIP, but I'm hoping to collect some feedback on what is (not) supported and how to report that to users.

r? @ghost

cc @taiki-e @Amanieu
2026-09-01 13:27:35 +02:00
N1ark
edcae4441d Make sin, cos, exp, exp2, log, log2, log10 generic 2026-08-31 18:57:54 +01:00
Folkert de Vries
178eb4b50f attach naked function target features to module assembly 2026-08-31 00:25:34 +02:00
Jonathan Brouwer
9dd88ffd5a Rollup merge of #160851 - beetrees:f16-inline-asm-mips, r=folkertdev
Add MSA and `f16` inline ASM support for MIPS

This PR adds vector register support for MIPS inline ASM when using the MSA extension ([MSA specification](https://s3-eu-west-1.amazonaws.com/downloads-mips/documents/MD00868-1D-MSA64-AFP-01.12.pdf)), as well as adding support for the `f16` type.

Ping target maintainers of MIPS targets: @Itus-Shield @Gelbpunkt @ayrtonm @LukasWoodtli @wzssyqa @chenx97 @709924470 @Cyanoxygen @Fearyncess

Tracking issues:
`f16` inline ASM: rust-lang/rust#125398 (part of rust-lang/rust#116909)
MIPS inline ASM: rust-lang/rust#93335
MIPS target features: rust-lang/rust#150253
2026-08-29 16:13:30 +02:00
Jonathan Brouwer
80f74433db Rollup merge of #161522 - folkertdev:gcc-fma16-correctly-rounded, r=tgross35
test `f16::mul_add` not double-rounding the result

test the precision of `f16::mul_add`. The semantics of `mul_add` are that there should only be one rounding of the final result back into the storage type, i.e. the intermediate result of the multiplication should not be rounded.

A naive implementation of `f16::mul_add` as `f32::mul_add(a as f32, b as f32, c as f32) as f16` has insufficient precision, see https://github.com/llvm/llvm-project/issues/98389.

Our `rustc_codegen_gcc` backend still used the `f32` approach, this PR changes it to instead (implicitly) use the fallback body from `core`, which uses `f64::mul_add` so that the result is correctly rounded.
2026-08-25 18:00:08 +02:00
Jonathan Brouwer
3cc643bd77 Rollup merge of #160132 - folkertdev:pad-i32-count, r=bjorn3
make `pad_i32` of `PassMode::cast` an integer

so that we can specify more than one i32 of padding. This PR only adds the functionality but does not yet use it: there should be no functional changes.

This is needed for the ABI of `Complex<{ float }>` on 32-bit powerpc. Other mechanisms, e.g. using `PassMode::prefixed` don't appear to work.

More discussion is in [#t-compiler/help > power complex abi](https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/power.20complex.20abi/with/613294420).
2026-08-24 15:06:55 +02:00
Jacob Pratt
0434213f6d Rollup merge of #160949 - beetrees:f128-inline-asm-sparc, r=folkertdev
Add floating point inline ASM support for SPARC

This PR adds support for floating point registers to SPARC inline ASM.

Ping target maintainers: @psumbera @kulikjak @jonathanpallant @mvolfik @he32 @0323pin @semarie

Tracking issues:
f16 inline ASM: rust-lang/rust#125398 (part of rust-lang/rust#116909)
SPARC inline ASM: rust-lang/rust#93335
2026-08-22 19:37:11 -04:00
Folkert de Vries
a5f012576c test f16::mul_add not double-rounding the result
A naive `f32::mul_add(a as f32, b as f32, c as f32) as f16` has insufficient precision
2026-08-22 14:53:14 +02:00
Folkert de Vries
d5d5ff7edf make pad_i32 of PassMode::cast an integer
so that we can specify more than one i32 of padding.
2026-08-21 21:25:26 +02:00
Josh Stone
d480723d0a reformat 2026-08-19 09:27:38 -07:00
beetrees
1946001268 Add floating point inline ASM support for SPARC 2026-08-18 18:11:55 +01:00
Jonathan Brouwer
765bc489c8 Rollup merge of #160058 - RalfJung:atomic-volatile, r=JohnTitor
atomic volatile: add intrinsics

Extend the atomic load/store intrinsics to also support volatile atomic load/store.
Tracking issue: https://github.com/rust-lang/rust/issues/158947.
Library APIs that use these intrinsics will be added inn a future PR.

The GCC and cranelift implementations ignore the volatile flag, not sure how that should be implemented for them.
2026-08-17 20:58:24 +02:00
Ralf Jung
78a3e30143 atomic volatile: add intrinsics 2026-08-16 22:38:03 +02:00
beetrees
5113ee9bbc Add MSA and f16 inline ASM support for MIPS 2026-08-13 18:45:53 +01:00
Josh Stone
7672b83df3 Upgrade and deduplicate dependencies
- Upgrade from `getrandom v0.4.2` to `v0.4.3` to drop its `wasip2` and
  `wasip3` dependencies and many transitives.
- Upgrade from `gimli v0.33` to `v0.34` as a direct dependency and
  through a `thorin-dwp` upgrade.
- Upgrade from `object v0.37` and `v0.38` to `v0.39` as a direct
  dependency and via `ar_archive_writer` and `thorin-dwp` upgrades.
- Upgrade `libloading` and `wasmparser` to match other dependencies.

This also consolidates from `hashbrown v0.15`, `v0.16`, and `v0.17` to
just `v0.17.1`, which is the same that `std` currently uses.
2026-08-10 08:53:07 -07:00
Jonathan Brouwer
6a3b9acf14 Rollup merge of #160530 - RalfJung:internal-target-features, r=nnethercote
refactor handling of target features in Session

`Session` currently contains two lists of target features: `target_features`, which is also exposed in `cfg`, and `unstable_target_features`, which is used internally to communicate between various parts of the compiler which target features are *actually* available, including some that we don't have plans to put in `cfg`, namely "forbidden" target features. The `unstable_target_features` list is *not* equivalent to what nightly code sees in `cfg(target_features)` as the latter excludes "forbidden" target features. Both lists are computed by `fn cfg_target_features` even though one of them is never used for `cfg`. It's all kind of messy.

This PR refactors that: `fn cfg_target_features` is replaced by `fn internal_target_features` which computes all enabled Rust target features (including "forbidden" ones -- which are really more like "internal-only" ones so the 2nd commit renames them). We then compute `cfg(target_features)` from that. The session only stores one list, `internal_target_features`, which corresponds to the previous `unstable_target_features`.

To simplify computing `internal_target_features` I also refactored `parse_rust_feature_list` to better distinguish actual Rust target features from unknown target features that we are just grandfathering in. I also made `implied_target_features` not rebuild the same hash map over and over again. And I got rid of a bunch of silly temporary vectors and iterations over all Rust target features.
2026-08-08 00:38:22 +02:00
Ralf Jung
8bb9f279a9 refactor handling of target features in Session 2026-08-06 14:45:53 +02:00
Jonathan Brouwer
900f0bcb32 Rollup merge of #159225 - bjorn3:split_incr_comp_session, r=oli-obk
Split IncrCompSession out of Session

This will allow introducing a separate incr comp session dir for the post LTO artifacts in the future. In addition it statically encodes the lifetime of the incr comp session rather than requiring an enum behind a mutex stored in the Session.

Based on https://github.com/rust-lang/rust/pull/159000
Part of https://github.com/rust-lang/compiler-team/issues/908
2026-08-05 13:36:11 +02:00
Guillaume Gomez
bf57193d05 Revert "Auto merge of #159844 - GuillaumeGomez:subtree-update_cg_gcc_2026-07-24, r=GuillaumeGomez"
This reverts commit 504869653f, reversing
changes made to 7c329d6c76.
2026-08-03 23:05:36 +02:00
Guillaume Gomez
614d08194e Merge commit 'b3791c6305afd6ecc3e7f6232487f2bb31aed3e7' 2026-08-02 00:06:25 +02:00
Jacob Pratt
31e12ee467 Rollup merge of #160124 - scottmcm:simd-count, r=oli-obk
Structurally prevent zero-count `BackendRepr::SimdVector`s

This is already *supposed* to be impossible in layout, but this emphasizes that better.  This PR makes no behaviour changes; just `BackendLaneCount` instead of `u64` in https://doc.rust-lang.org/nightly/nightly-rustc/rustc_abi/enum.BackendRepr.html

Ironically I was inspired to do this as part of [looking at making `Simd<T, 0>` *work*](https://rust-lang.zulipchat.com/#narrow/channel/257879-project-portable-simd/topic/Allow.20N.3D.3D0.3F/with/613345298), but importantly if that's going to happen I think it should be `BackendRepr::Memory` like other ZSTs, *not* a `BackendRepr::ScalarVector` that would need to carry around a useless LLVM value in `OperandValue::Immediate` (where it's not even clear what the LLVM type of that value would be).
2026-07-31 22:25:12 -04:00
Scott McMurray
6da3077db9 Structurally prevent zero-count BackendRepr::SimdVectors
This is already *supposed* to be impossible in layout, but this emphasizes that better.

Ironically I was inspired to do this as part of looking at making `Simd<T, 0>` *work*, but importantly if that's going to happen I think it should be `BackendRepr::Memory` like other ZSTs, *not* a `BackendRepr::ScalarVector` that would need to carry around a useless LLVM value in `OperandValue::Immediate` (where it's not even clear what the LLVM type of that value would be).
2026-07-30 19:48:24 -07:00
Jacob Pratt
504ee5c04b Rollup merge of #160148 - GuillaumeGomez:rename-errors, r=JonathanBrouwer
Rename `errors.rs` file to `diagnostics.rs` (15/N)

Follow-up of https://github.com/rust-lang/rust/pull/157485.

r? @JonathanBrouwer
2026-07-29 20:48:22 -04:00
Guillaume Gomez
31918e4edd Rename rustc_codegen_gcc/errors.rs into rustc_codegen_gcc/diagnostics.rs 2026-07-29 14:18:32 +02:00
Mike Hommey
7158341ec7 Revert "codegen: add OperandValue::Uninit to skip stores for entirely-uninit constants"
This reverts commit ed9de1e466.
2026-07-28 18:47:39 +09:00
Jacob Pratt
0e238fd6c3 Rollup merge of #138618 - nbdd0121:asm_const_ptr, r=bjorn3
Support using const pointers in asm `const` operand

Implements [RFC#3848](https://github.com/rust-lang/rfcs/pull/3848) with tracking issue rust-lang/rust#128464

This adds support of const pointers for asm `const` in addition to plain integers.

The inline `asm!` support is implemented using `i` constraint, and the `global_asm!` and `naked_asm!` support is implemented by inserting `symbol + offset` and make `symbol` compiler-used. For unnamed consts, it will create additional internal & hidden symbols so that they can be referenced by global_asm.

~~The feature is also implemented for GCC backend but it's untested.~~ Tested now.
2026-07-26 00:21:39 -04:00
bjorn3
f9679fa4df Split IncrCompSession out of Session
This will allow introducing a separate incr comp session dir for the
post LTO artifacts in the future. In addition it statically encodes the
lifetime of the incr comp session rather than requiring an enum behind a
mutex stored in the Session.
2026-07-23 12:14:56 +02:00
Gary Guo
c95d35e96f Generate unique symbol names if const pointers refer to promoted static 2026-07-22 14:34:42 +01:00
Gary Guo
338d560eaf Handle pointers with offset for asm const 2026-07-22 13:47:31 +01:00