Commit Graph

3556 Commits

Author SHA1 Message Date
Jonathan Brouwer
de70798fa7 Rollup merge of #147302 - esp-rs:xtensa-asm, r=Amanieu
asm! support for the Xtensa architecture

This implements the asm! support for Xtensa. We've been using this code for a few years in [our fork](https://github.com/esp-rs/rust) and it's been working well. I finally found some time to clean it up a bit and start the upstreaming process. This should be one of the final PRs for Xtensa support on the Rust side (minus bug fixes of course). After this, we're mostly just waiting on the LLVM upstreaming which is going well. This PR doesn't cover all possible asm options for Xtensa, but the base ISA plus a few extras that are used in Espressif chips.

r? Amanieu
2026-06-08 17:11:05 +02:00
Scott Mabin
768fc10e9d asm! support for the Xtensa architecture
Co-authored-by: Taiki Endo <te316e89@gmail.com>
Co-authored-by: Kerry Jones <kerry@iodrive.co.za>
2026-06-08 11:53:15 +01:00
bjorn3
9419baeee8 Use WorkProductMap instead of FxIndexMap
This is an UnordMap internally. Iteration order for the work product map
should not matter aside from the place it is serialized where sorting by
WorkProductId is sufficient.
2026-06-07 13:24:12 +00:00
Jacob Pratt
d66ac2434a Rollup merge of #157016 - folkertdev:add-tailcc-abi, r=WaffleLapkin
add `extern "tail"` calling convention

Maps to LLVM's `tailcc` and hence inherits all its problems.

This calling convention at least compiles on:

- `x86_64`
- `aarch64`

It also compiles on

- `s390x`
- `loongarch64`

But I've been told by target maintainers that this is kind of unintentional, and it's not tested in LLVM.

For most backends LLVM does not have support and fails loudly.
2026-06-07 00:37:48 -04:00
Folkert de Vries
4e59f4c54b add extern "tail" calling convention 2026-06-05 20:19:51 +02:00
Takayuki Maeda
e2cc7e674e avoid ICE when formatting TargetMachine config errors 2026-06-05 18:09:54 +09:00
Jonathan Brouwer
3ac83ceb48 Rollup merge of #156281 - nikic:nofree, r=RalfJung
Emit nofree attribute

Treat the semantics of pointee.size as "dereferenceable-at-point" and always specify the size. Instead, use a separate NoFree attribute to determine whether dereferenceability extends to the whole function.

Then in the LLVM backend, only actually emit dereferenceable if nofree is also set, as dereferenceable currently implies nofree.

In addition, explicitly emit the nofree attribute, which will help when LLVM switches dereferenceable to be at-point.

Relevant recent LLVM PR: https://github.com/llvm/llvm-project/pull/195658
2026-06-04 18:28:47 +02:00
Nikita Popov
cb09a42d7e Emit nofree attribute
Treat the semantics of pointee.size as "dereferenceable-at-point"
and always specify the size. Instead, use a separate NoFree attribute
to determine whether dereferenceability extends to the whole function.

Then in the LLVM backend, only actually emit dereferenceable if
nofree is also set, as dereferenceable currently implies nofree.

In addition, explicitly emit the nofree attribute, which will help
when LLVM switches dereferenceable to be at-point.
2026-06-04 15:19:24 +02:00
Jonathan Brouwer
cf688f2329 Rollup merge of #157294 - cjgillot:split-coroutine-layout, r=oli-obk
Split coroutine layout computation to its own file

`coroutine.rs` is getting too large, and mixes MIR analyses for trait solving and runtime transformations.
2026-06-03 14:27:12 +02:00
Jonathan Brouwer
266eb48e34 Rollup merge of #156928 - bjorn3:emscripten_always_wasm_eh, r=TaKO8Ki
Remove -Zemscripten-wasm-eh

This was necessary when transitioning from JS to wasm exception handling on Emscripten. Enough time has probably passed that we no longer need to support JS exception handling on Emscripten. This enables cleaning up a fair bit of code.

This is the final step of https://github.com/rust-lang/rust/issues/112195.
2026-06-03 14:27:09 +02:00
Jonathan Brouwer
cccb16ea98 Rollup merge of #157311 - jdonszelmann:weak-linkage-eii, r=bjorn3
Use weak linkage for EII defaults

hard to find a test for this, but weak seems more correct (after private discussion with @bjorn3)

Also changes a log statement to make it a lil easier to see what's going on.

r? @bjorn3
2026-06-03 14:27:08 +02:00
bjorn3
9b7623a162 Remove -Zemscripten-wasm-eh
This was necessary when transitioning from JS to wasm exception handling
on Emscripten. Enough time has probably passed that we no longer need to
support JS exception handling on Emscripten. This enables cleaning up a
fair bit of code.
2026-06-02 19:56:40 +02:00
Jana Dönszelmann
bef59cd138 Use weak linkage (otherwise we can't compile .so files with eiis in them) 2026-06-02 14:57:40 +02:00
Jonathan Brouwer
99bb120cf8 Rollup merge of #157130 - alexcrichton:refactor-cast-target-internals, r=nnethercote
Use a `ArrayVec` in `CastTarget`

This commit switches a fixed-size list of `[Option<Reg>; 8]` to instead
holding `ArrayVec<Reg, 8>` in the `CastTarget` type used when
calculating ABIs. This is inspired by [discussion on Zulip][link] where
I'm hoping to in the near future extend the usage of this to possibly
beyond 8 elements for a new WebAssembly ABI taking advantage of
multi-value. For now though this mostly just switches to
array/slice-like idioms of accessors rather than dealing with
`Option<Reg>` as the unit.

[link]: https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Using.20.60ArgAbi.3A.3Amake_direct_deprecated.60/with/598607139
2026-06-02 13:20:49 +02:00
Jonathan Brouwer
94fee53bdf Rollup merge of #156467 - RalfJung:weak-import-addr, r=bjorn3
mark the 'import linkage' statics as unnamed_addr
2026-06-02 13:20:45 +02:00
Camille Gillot
7092ebf862 Integrate field_names inside field_tys.
We already have a vector of `CoroutineSavedTy`, no need to have a separate
one just for debuginfo.
2026-06-02 08:28:59 +00:00
Alex Crichton
c668b83eed Use a ArrayVec in CastTarget
This commit switches a fixed-size list of `[Option<Reg>; 8]` to instead
holding `ArrayVec<Reg, 8>` in the `CastTarget` type used when
calculating ABIs. This is inspired by [discussion on Zulip][link] where
I'm hoping to in the near future extend the usage of this to possibly
beyond 8 elements for a new WebAssembly ABI taking advantage of
multi-value. For now though this mostly just switches to
array/slice-like idioms of accessors rather than dealing with
`Option<Reg>` as the unit.

[link]: https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Using.20.60ArgAbi.3A.3Amake_direct_deprecated.60/with/598607139
2026-06-01 07:34:12 -07:00
Jonathan Brouwer
cf39dc63f4 Rollup merge of #157139 - scottmcm:abi-range-inclusive, r=oli-obk
compiler: `ops::RangeInclusive` → `range::RangeInclusive`

The type's been stable for over 6 weeks now, so let's use it!  It's better for cases like this one where it's stored in a data structure.

Probably won't be materially faster, but does make the variant slightly smaller and lets some more things be `Copy`.  And deletes a whole bunch of parens from things being fields instead of methods 😄

r? compiler
2026-05-30 11:40:21 +02:00
Scott McMurray
f7cf361f3c compiler: ops::RangeInclusive → range::RangeInclusive
The type's been stable for over 6 weeks now, so let's use it!  It's better for cases like this one where it's stored in a data structure.

Probably won't be materially faster, but does make the variant slightly smaller and lets some more things be `Copy`.
2026-05-29 21:57:45 -07:00
Jonathan Brouwer
cbc3a2e0cf Rollup merge of #154835 - ZuseZ4:offload-sharedmem, r=oli-obk
std::offload sharedmem

@Sa4dUs @Kevinsala This simply allows requesting shared-memory for gpu kernels at launch time via std::offload. The actual work to access the shared memory inside the kernel has already landed independent of the offload work in rustc, so we're building on that.

cc @Flakebi (thanks for your work!)
2026-05-29 21:03:30 +02:00
Jonathan Brouwer
1e2fc47f29 Rollup merge of #156980 - Darksonn:frame-ptrs-module, r=nnethercote
Add frame pointer annotations to the module

While working on rust-lang/rust#156973 I found https://github.com/llvm/llvm-project/issues/188234 which points out that the frame pointer annotation is also missing.
2026-05-29 09:06:23 +02:00
Jonathan Brouwer
ff278757bd Rollup merge of #157050 - bjorn3:lto_refactors19, r=lqd
Couple of changes to help with moving LTO to the link phase

Part of https://github.com/rust-lang/compiler-team/issues/908
2026-05-29 09:06:20 +02:00
Jonathan Brouwer
0f27774436 Rollup merge of #156867 - scottmcm:WIP-no-alloca-for-catch-unwind, r=dianqk
Stop needing an alloca for `catch_unwind`

Turns out these were all making `OperandValue::Immediate`s already -- the intrinsic always returns a primitive scalar -- so pretty easy to handle.

cc https://github.com/rust-lang/rust/issues/153250 https://github.com/rust-lang/compiler-team/issues/970

While I was looking at it, I also "rustified" the intrinsic signature a bit: returning a `bool` and taking a generic pointee and `unsafe fn`s cleans up the call in `std` a bit without making the implementation in the backend any harder.

r? dianqk
2026-05-29 09:06:19 +02:00
Scott McMurray
6aa9c0325e Stop needing an alloca for catch_unwind
Turns out these were all making `OperandValue::Immediate`s already -- the intrinsic always returns a primitive scalar -- so pretty easy to handle.

While I was looking at it, I also "rustified" the intrinsic signature a bit: returning a `bool` and taking a generic pointee and `unsafe fn`s cleans up the call in `std` a bit without making the implementation in the backend any harder.
2026-05-28 19:53:59 -07:00
Manuel Drehwald
c01bfdc405 Enable requesting shared-memory at kernel launch-time via offload 2026-05-28 16:03:06 -07:00
Manuel Drehwald
fade967190 Give variables passed to Omp/Offload nice names on LLVM-IR level 2026-05-28 16:03:04 -07:00
Jonathan Brouwer
49bbe8aca7 Rollup merge of #156746 - Zalathar:llvm-debuginfo, r=jieyouxu
cg_llvm: Use `LLVMDIBuilderCreateEnumeratorOfArbitraryPrecision`

- Part of https://github.com/rust-lang/rust/issues/134001
- Follow-up to https://github.com/rust-lang/rust/pull/146763
---

This PR replaces our custom `LLVMRustDIBuilderCreateEnumerator` FFI binding with an equivalent LLVM-C binding to `LLVMDIBuilderCreateEnumeratorOfArbitraryPrecision`, which was introduced in LLVM 21.

I have also added comments to the remaining `LLVMRustDIBuilder` functions explaining why they currently can't use an LLVM-C binding, and noted some other functions that can use LLVM-C bindings in the future.
2026-05-28 14:59:42 +02:00
bjorn3
9f8820be29 Support implementing ExtraBackendMethods and WriteBackendMethods independently 2026-05-28 09:15:36 +00:00
Jonathan Brouwer
2456df10c4 Rollup merge of #156941 - ZuseZ4:update-offload-file-naming, r=oli-obk
Offload: Update confusing and outdated file name

We swapped the order in which we do host and device compilations. The file getting renamed is effectively the output of the clang-offload-packager, the first magic bytes (`00000000  10 ff 10 ad`) confirm it. I was just creating a figure to visualize and noticed that the name is off.

cc @Kevinsala @jdoerfert is there any naming convention?

r? oli-obk
2026-05-28 10:36:45 +02:00
Jonathan Brouwer
3c533ce81d Rollup merge of #156568 - SergioGasquez:fix/xtensa-vaarg-alg, r=folkertdev
Fix Xtensa vaarg stack transition algorithm

Fixes Xtensa va arg stack transition algorithm
2026-05-28 10:36:43 +02:00
Alice Ryhl
df84feacbd Add frame pointer annotations to the module 2026-05-28 05:57:11 +00:00
Zalathar
d59cae8cf1 Note some bindings that can be replaced after dropping LLVM 21 support 2026-05-28 12:47:38 +10:00
Zalathar
12ad5b7c52 Explain why the remaining debuginfo bindings don't use LLVM-C 2026-05-28 12:38:26 +10:00
Zalathar
c8449aa958 Use LLVMDIBuilderCreateEnumeratorOfArbitraryPrecision 2026-05-28 12:38:26 +10:00
Guillaume Gomez
0846622465 Rollup merge of #156973 - Darksonn:unwind-tables-module, r=nnethercote
Add uwtable annotation to modules when required

When unwind tables are enabled with `-Cforce-unwind-tables=y`, Rust will annotate all functions with the `uwtable` annotation. However, this annotation is missing on modules, which leads to incorrect unwind tables being generated by LLVM for constructors (such as `asan.module_ctor`).

This was discovered because it leads to a crash in Linux when KASAN and dynamic shadow call stack are both enabled. In this scenario, the kernel uses the unwind tables to locate the `paciasp` and `autiasp` instructions in each function and patches the machine code at boot to use the shadow call stack instructions instead. However, LLVM's AArch64PointerAuth pass emits DWARF info for `paciasp` whenever `-g` is passed, but only emits DWARF info for `autiasp` when the `uwtable` attribute is present. Since the `uwtable` annotation is missing for modules, the relevant directives are generated for only the `autiasp` instruction in `asan.module_ctor`, and not for the `paciasp` instruction. This causes the kernel's dynamic SCS logic to patch the prolouge of `asan.module_ctor`, but not the epilogue. This leads to a crash as the shadow call stack becomes unbalanced.

The fact that LLVM doesn't use the same condition for whether to emit DWARF information for both instructions may be a separate bug in LLVM.

Relevant issue: https://github.com/llvm/llvm-project/issues/188234

AI assistance was used to determine the root cause of this crash from the observed symptoms, and to write the tests. Also thanks to @samitolvanen and @maurer for debugging this issue.

Similar to this previous PR of mine: rust-lang/rust#130824
2026-05-27 20:45:14 +02:00
Ralf Jung
59428e76e8 MIR inlining: allow backends to opt-in to inlining intrinsics 2026-05-27 13:59:25 +02:00
Alice Ryhl
90fe8cc66f Adjust UWTableKind comment ref to llvm type 2026-05-27 09:27:35 +00:00
Alice Ryhl
f46fade899 Emit uwtable annotation for modules 2026-05-26 14:32:05 +00:00
Manuel Drehwald
1ffcca723e Update confusing and outdated file name 2026-05-25 18:27:10 -04:00
bors
1d59f669f9 Auto merge of #156849 - saethlin:test-call-site-inline-attributes, r=dianqk
Re-add call site inlining attributes

It is very odd that we are blindly setting the call site attributes to the same as the definition, because I think the point of the call site attributes is to differentiate between calls. Probably worth looking into later, but for now I think we should just be undoing the change we made by mistake.

This fixes the accidental regression from https://github.com/rust-lang/rust/pull/156242
2026-05-24 13:02:42 +00:00
Ben Kimock
adbf6f56dc Re-add call site inlining attributes 2026-05-23 16:49:04 -04:00
Scott McMurray
d3d3485dd4 Let intrinsics use the SSA operand path 2026-05-22 22:02:06 -07:00
Jonathan Brouwer
8162cf582b Rollup merge of #156242 - Jamesbarford:feat/remove-alwaysinline+target-feature, r=RalfJung,saethlin
Remove unsound `target_feature_inline_always` feature

## Summary
- Remove `target_feature_inline_always`
- Update stdarch generators to only use `#[inline]` & regenerate stdarch.

## Why?
Succinctly; the feature relies on LLVMs `AlwaysInlinerPass()` running before LLVMs heuristic based inliner pass. Which is not a basis for sound code.

This has been discussed in [the tracking issue](https://github.com/rust-lang/rust/issues/145574).

If the ordering of the passes were to change, of which they have in the past, it is very possible we could inline functions across callsites with mismatching target features leading to unsound code. Checks proposed in; https://github.com/rust-lang/rust/pull/155426 would only take into account caller -> callee which is not enough to guard against possibly of generating unsound code if the pass ordering were to change.

There doesn't seem to be a way, presently, this this mechanism to provide soundness guarantees nor does it seem like `AlwaysInlinerPass()` is a desired feature of LLVM, which this feature relies on.

r? @RalfJung
2026-05-21 12:21:45 +02:00
Jonathan Brouwer
ff42fc00d4 Rollup merge of #156208 - BorrowSanitizer:codegen-emit-retag-1, r=saethlin
Emit retags in codegen to support BorrowSanitizer (part 1)

Tracking issue: rust-lang/rust#154760
[Zulip Thread](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Staging.20for.20emitting.20retags.20in.20codegen/with/593004012)

This is the first of several PRs that will add experimental support for emitting retags as function calls in codegen. Each PR will be a minimal, improved slice of the changes in rust-lang/rust#155965.

This PR contains all of the changes that will affect codegen backends. It adds methods to `IntrinsicCallBuilderMethods` for emitting each kind of retag call.

cc: @RalfJung
2026-05-17 15:52:36 +02:00
Ian McCormack
e15861bdd2 Add trait methods for experimental retags to cg. 2026-05-15 12:34:03 -04:00
James Barford-Evans
405214dd92 PR feedback - revert fn inline_attr(...) to how it was prior to inlinealways + target feature changes, factoring in subsequent codebase changes 2026-05-15 10:30:16 +01:00
Sergio Gasquez
41e1dc4df7 fix: xtensa vaarg stack transition algorithm 2026-05-14 12:41:22 +02:00
Guy Bedford
45adab87a5 Pass user-provided llvm_args after target spec llvm_args.
This ensures that user arguments can override target arguments without being silently ignored.
2026-05-13 12:16:25 -07:00
Jonathan Brouwer
0705b602f0 Rollup merge of #155815 - djc:swift-cc, r=jieyouxu
Add Swift function call ABI

Adds an unstable `extern "Swift"` ABI behind the `abi_swift` feature gate, mapping to LLVM's `swiftcc` calling convention. This is only allowed (a) for `is_darwin_like` targets, since the [ABI is only stable for those platforms](https://www.swift.org/blog/abi-stability-and-more/) and (b) with the LLVM backend, since the other backends don't support it.

Current approaches to interoperability with Swift lower to Objective-C (or require a Swift stub exposing a C ABI), but that is an optional mapping on the Swift side that some newer Apple frameworks omit. It would be great to be able to more directly/natively be able to call into Swift code directly via its stable API (on Apple platforms at least).

Reimplements rust-lang/rust#64582 on top of current main. The main objection to the previous PR seemed to be that it needed an RFC, but there was pushback (which seems sensible to me) that an RFC could be deferred until stabilization.

I think this needs a tracking issue? Would be happy to write one up if/when there is a consensus that this will be merged.
2026-05-13 15:16:17 +02:00
Jonathan Brouwer
8edd846028 Rollup merge of #156472 - stephenduong1004:print-stats-json, r=nikomatsakis
Add support for Zprint-codegen-stats-json

Add a flag `-Zprint-codegen-stats-json=<file>` to collect and write LLVM statistics in JSON format. It makes use of the function `llvm::PrintStatisticsJSON` in LLVM.

The flag currently only obtains LLVM statistics for now, but could be used to collect more front-end statistics in the future.
2026-05-13 11:46:37 +02:00