Commit Graph

799 Commits

Author SHA1 Message Date
Jonathan Brouwer
626596908b Rollup merge of #160335 - sgasho:dlopen_offload, r=ZuseZ4
dlopen offload

dlopen offload to dist it in dist-x86_64-linux without enabling llvm.offload=true in CI (https://github.com/rust-lang/rust/pull/159064#issuecomment-5003148163)

I tested that this works by following steps at https://rustc-dev-guide.rust-lang.org/offload/usage.html for both LLVM22 and 23(by switch base branch to https://github.com/rust-lang/rust/pull/158734 temporarily), though It might be better to land this after LLVM 23.

r? @ZuseZ4
2026-08-08 00:38:28 +02:00
sgasho
162cba5202 dlopen Offload 2026-08-06 23:16:59 +00:00
Jonathan Brouwer
6a6901467a Rollup merge of #159029 - erickt:lto-module-summaries, r=cuviper
rustc_llvm: Emit module summaries when using -Clto=fat

Currently, module summaries are only emitted with thin lto. If we would link full/fat lto'd rust code against lto'd c++ code built with CFI (or WPD), those passes would fail during the link step because the participating rust modules are missing module summaries. Rust code does not know at compile-time if it would be participating in some special link which may require module summaries, so this PR ensures module summaries are unconditionally emitted for full/fat lto, just like with thin lto.

The WriteBitcodeToFile function just invokes the normal BitcodeWriterPass under the hood, but doesn't provide a way to set the argument for emitting module summaries. So this patch just adds the pass directly and sets that argument.

This is a rebase of @PiJoules's https://github.com/rust-lang/rust/pull/158099, which also should fix up the tests with the gcc tools.
2026-08-05 21:55:42 +02:00
Jakub Beránek
7a2c0b3f5d Do not use -Werror when building rustc_llvm with GCC 2026-08-04 10:22:36 -04:00
Leonard Chan
a4bc26a608 rustc_llvm: Emit module summaries when using -Clto=fat
Currently, module summaries are only emitted with thin lto. If we would
link full/fat lto'd rust code against lto'd c++ code built with CFI (or
WPD), those passes would fail during the link step because the
participating rust modules are missing module summaries. Rust code does
not know at compile-time if it would be participating in some special
link which may require module summaries, so this PR ensures module
summaries are unconditionally emitted for full/fat lto, just like with
thin lto.

The WriteBitcodeToFile function just invokes the normal
BitcodeWriterPass under the hood, but doesn't provide a way to set the
argument for emitting module summaries. So this patch just adds the pass
directly and sets that argument.

Finally, now that we're generating module summaries for `-Clto=fat`
without using ThinLTO, we need to update `rustc-metadata` to keep
around a temporary directory that contains the `.rmeta` for a little
longer before we deserialize it.
2026-07-27 18:31:29 +00:00
Jacob Pratt
5f9254e47d Rollup merge of #158808 - chitao1234:fix-rustc-llvm-cross-libstdcxx-abi, r=cuviper
Filter host libstdc++ ABI flag in rustc_llvm cross builds

`compiler/rustc_llvm/build.rs` invokes `llvm-config` for the build host machine in cross compilation scenarios. In particular, the normal LLVM configuration on Linux sets `_GLIBCXX_USE_CXX11_ABI=1` and those flags would then pollute C++ wrapper objects being compiled for the target.

This patch makes `rustc_llvm` avoid propagating that macro when cross-compiling. This follows the existing pattern in `rustc_llvm/build.rs`, which already treats parts of cross `llvm-config` output as host-specific by filtering `-m*` flags and rewriting include paths. Although I think the more appropriate approach is to use a separate target LLVM C++ flags setting.

This currently affects Haiku rustc cross-compilation from Linux hosts. The Haiku target currently uses the old libstdc++ string ABI by default and that creates an ABI mismatch. I currently work around this locally by setting environment variable `CXXFLAGS_x86_64_unknown_haiku=-D_GLIBCXX_USE_CXX11_ABI=0`.
2026-07-20 23:38:03 -04:00
Augie Fackler
b8d3a4ac9c Reapply "LLVM 23: Run AssignGUIDPass in some places"
This reverts commit 4919940fad.
2026-07-08 12:17:39 -04:00
Manuel Drehwald
de73ac0de3 Fix typetree generation for arguments, like slices and re-enable their generation for memcpy.
This moves a TA failure in the testcase from memcpy to a later location.
2026-07-06 23:10:51 +02:00
Jonathan Brouwer
2085491fdf Rollup merge of #156777 - sgasho:test-fix-codegen-llvm-autodiff-2, r=ZuseZ4
Add -Zautodiff_post_passes flag to limit which llvm passes to run after enzyme to make autodiff tests more robust

* Add -Zautodiff_post_passes flag to limit which llvm passes to run after enzyme to make autodiff tests more robust
* Change some llvm ir check in codegen_llvm/autodiff tests

r? @ZuseZ4
2026-07-05 14:12:03 +02:00
Xuntao Chi
b1a5d8592f Filter host libstdc++ ABI flag in rustc_llvm cross builds 2026-07-05 17:45:55 +08:00
sgasho
d7e4edd9a1 Add -Zautodiff_post_passes flag to limit which llvm passes to run after enzyme 2026-07-03 00:43:49 +09:00
Jonathan Brouwer
aa4c911c12 Rollup merge of #158568 - liza371:llvm-23-compat, r=nikic
llvm-wrapper: use accessors for private fields in LLVM 23+

In LLVM, FeatureKV/SubtargetKV pointers are now private:
https://github.com/llvm/llvm-project/pull/206237
This change fixes compiler errors when building rustc with ToT LLVM
by using the key() and desc() accessors.
2026-06-30 03:41:37 +02:00
Liza Burakova
a60be48dff llvm-wrapper: use accessors for private fields in LLVM 23+
In LLVM, FeatureKV/SubtargetKV pointers are now private:
https://github.com/llvm/llvm-project/pull/206237
This change fixes compiler errors when building rustc with ToT LLVM
by using the key() and desc() accessors.
2026-06-29 15:09:50 +00:00
Jakub Chlanda
dbc4eb8f42 Introduce aarch64-unknown-linux-pauthtest
Co-authored-by: Daniil Kovalev <dkovalev@accesssoftek.com>
2026-06-26 13:23:08 +00:00
David Wood
cfc4211b6e codegen_ssa: multiply scalable vec size by vscale
When emitting a `memcpy` for a scalable vector, the size computed by
rustc (`num_vectors * element_count * element_ty`), since
rust-lang/rust#157915, needs to be multiplied by `vscale`.
2026-06-22 15:06:35 +00:00
Jacob Pratt
2c65872066 Rollup merge of #157476 - zmodem:cfi_symbols_fix, r=durin42
Adopt to LLVM 23 CfiFunctionIndex change

https://github.com/llvm/llvm-project/pull/201635 removed symbols()
2026-06-08 16:27:01 -04:00
Hans Wennborg
ca00de5a8a Adopt to LLVM 23 CfiFunctionIndex change
https://github.com/llvm/llvm-project/pull/201635 removed symbols()
2026-06-05 11:35:57 +02:00
Hans Wennborg
4919940fad Revert "LLVM 23: Run AssignGUIDPass in some places"
This reverts commit cdb73bb677.
2026-06-05 09:26:08 +02: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
0f6fb22448 Rollup merge of #157055 - TimNN:guid, r=cuviper
LLVM 23: Run AssignGUIDPass in some places

https://github.com/llvm/llvm-project/pull/184065 introduced the new pass.

I'm not 100% confident that this is the correct patch, but it makes all the previously failing `run-make` "lto" tests pass on my machine.

I added the pass to the `if (NeedThinLTOBufferPasses)` section to match the `addRequiredLTOPreLinkPasses` changes from the LLVM PR, and to the `LLVMRustModuleSerialize` section based on the stack trace of an LLVM assertion.

The IR may now contain an additional `!guid` attribute, requiring some codegen test expectations to be updated. I mostly followed the pattern from the LLVM PR, and removed trailing `{`s. (For both, tests that were failing locally, as well as potentially problematic expectations identified via grep, in case the test wasn't being run locally).

@rustbot label llvm-main
2026-06-01 19:35:50 +02:00
sgasho
179aaecb48 Link LLVM dynamically on aarch64-apple-darwin 2026-05-31 21:52:30 +09: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
Tim Neumann
cdb73bb677 LLVM 23: Run AssignGUIDPass in some places 2026-05-28 13:30:25 +02:00
Zalathar
c8449aa958 Use LLVMDIBuilderCreateEnumeratorOfArbitraryPrecision 2026-05-28 12:38:26 +10:00
Manuel Drehwald
1ffcca723e Update confusing and outdated file name 2026-05-25 18:27:10 -04:00
Stephen
8477a690b1 add support for Zprint-codegen-stats-json 2026-05-11 16:28:51 -04:00
Jacob Pratt
64b446b190 Rollup merge of #156156 - DKLoehr:subtarget_info, r=cuviper
Adjust getMCSubtargetInfo signature for LLVM 23+

A recent [LLVM PR](https://github.com/llvm/llvm-project/pull/195032) changed the signature of `getMCSubtargetInfo` to return a reference instead of a pointer. This adjusts uses of the function in `compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp` to account for the different signature.
2026-05-05 22:50:25 -04:00
abhinav srivastav
fc6b9c8626 updating flag with flag_if_supported
Co-authored-by: Urgau <3616612+Urgau@users.noreply.github.com>
2026-05-05 22:13:25 +05:30
Devon Loehr
7f697083d6 Fix formatting 2026-05-05 14:34:16 +00:00
Devon Loehr
412090247c Narrow definitions 2026-05-05 14:18:59 +00:00
paradoxicalguy
6a1953465b fix: remap ci-llvm debug paths via -fdebug-prefix-map
ci-llvm include paths were leaking into debuginfo of `librustc_driver` via C/C++ compilation in rustc_llvm, causing non-determinism across
stage2 builds.

extend debug path remapping to the C/C++ build in rustc_llvm by converting RUSTC_DEBUGINFO_MAP into corresponding -fdebug-prefix-map flags and passing them through cc::Build.
2026-05-05 13:49:25 +00:00
Devon Loehr
596d9853bb Adjust getMCSubtargetInfo signature for LLVM 23+ 2026-05-04 18:30:23 +00:00
Jonathan Brouwer
c6912bf401 Rollup merge of #155692 - fneddy:fix_naked-dead-code-elimination, r=folkertdev
disable naked-dead-code-elimination test if no RET mnemonic is available

this test emit x86_64 specific ret asm instruction and should not be compiled on any other arch.
2026-04-28 20:24:33 +02:00
Eddy (Eduard) Stefes
2a8e588c90 Add --print=backend-has-mnemonic and needs-asm-mnemonic directive
Add infrastructure to query LLVM backend for specific assembly mnemonics
and use it in compiletest to conditionally run tests based on instruction
availability.

This fixes test failures with naked-dead-code-elimination which requires
the `RET` mnemonic.

Co-authored-by: Folkert de Vries <flokkievids@gmail.com>
2026-04-28 10:21:15 +02:00
Jonathan Brouwer
dde4886801 Rollup merge of #146181 - Flakebi:dynamic-shared-memory, r=ZuseZ4,Sa4dus,workingjubilee,RalfJung,nikic,kjetilkjeka,kulst
Add intrinsic for launch-sized workgroup memory on GPUs

Workgroup memory is a memory region that is shared between all
threads in a workgroup on GPUs. Workgroup memory can be allocated
statically or after compilation, when launching a gpu-kernel.
The intrinsic added here returns the pointer to the memory that is
allocated at launch-time.

# Interface

With this change, workgroup memory can be accessed in Rust by
calling the new `gpu_launch_sized_workgroup_mem<T>() -> *mut T`
intrinsic.

It returns the pointer to workgroup memory guaranteeing that it is
aligned to at least the alignment of `T`.
The pointer is dereferencable for the size specified when launching the
current gpu-kernel (which may be the size of `T` but can also be larger
or smaller or zero).

All calls to this intrinsic return a pointer to the same address.

See the intrinsic documentation for more details.

## Alternative Interfaces

It was also considered to expose dynamic workgroup memory as extern
static variables in Rust, like they are represented in LLVM IR.
However, due to the pointer not being guaranteed to be dereferencable
(that depends on the allocated size at runtime), such a global must be
zero-sized, which makes global variables a bad fit.

# Implementation Details

Workgroup memory in amdgpu and nvptx lives in address space 3.
Workgroup memory from a launch is implemented by creating an
external global variable in address space 3. The global is declared with
size 0, as the actual size is only known at runtime. It is defined
behavior in LLVM to access an external global outside the defined size.

There is no similar way to get the allocated size of launch-sized
workgroup memory on amdgpu an nvptx, so users have to pass this
out-of-band or rely on target specific ways for now.

Tracking issue: rust-lang/rust#135516
2026-04-25 23:07:48 +02:00
Flakebi
13ec3de673 Add intrinsic for launch-sized workgroup memory on GPUs
Workgroup memory is a memory region that is shared between all
threads in a workgroup on GPUs. Workgroup memory can be allocated
statically or after compilation, when launching a gpu-kernel.
The intrinsic added here returns the pointer to the memory that is
allocated at launch-time.

# Interface

With this change, workgroup memory can be accessed in Rust by
calling the new `gpu_launch_sized_workgroup_mem<T>() -> *mut T`
intrinsic.

It returns the pointer to workgroup memory guaranteeing that it is
aligned to at least the alignment of `T`.
The pointer is dereferencable for the size specified when launching the
current gpu-kernel (which may be the size of `T` but can also be larger
or smaller or zero).

All calls to this intrinsic return a pointer to the same address.

See the intrinsic documentation for more details.

## Alternative Interfaces

It was also considered to expose dynamic workgroup memory as extern
static variables in Rust, like they are represented in LLVM IR.
However, due to the pointer not being guaranteed to be dereferencable
(that depends on the allocated size at runtime), such a global must be
zero-sized, which makes global variables a bad fit.

# Implementation Details

Workgroup memory in amdgpu and nvptx lives in address space 3.
Workgroup memory from a launch is implemented by creating an
external global variable in address space 3. The global is declared with
size 0, as the actual size is only known at runtime. It is defined
behavior in LLVM to access an external global outside the defined size.

There is no similar way to get the allocated size of launch-sized
workgroup memory on amdgpu an nvptx, so users have to pass this
out-of-band or rely on target specific ways for now.
2026-04-24 10:03:45 +02:00
Augie Fackler
f6b8f0b6f1 rustc_llvm: update opt-level handling for LLVM 23
LLVM 23 removed Os and Oz optimization pipelines and the PR says to use
O2 with optsize or minsize instead as appropriate.
2026-04-22 13:25:35 -04:00
sayantn
a5372be2a1 Add target arch verification for LLVM intrinsics 2026-04-12 23:33:27 +05:30
sayantn
c21f4ee437 Check for AutoUpgraded intrinsics, and lint on uses of deprecated intrinsics 2026-04-12 23:33:15 +05:30
Jonathan Brouwer
66a00ba2ef Rollup merge of #153995 - Flakebi:gpu-use-convergent, r=nnethercote
Use convergent attribute to funcs for GPU targets

On targets with convergent operations, we need to add the convergent attribute to all functions that run convergent operations. Following clang, we can conservatively apply the attribute to all functions when compiling for such a target and rely on LLVM optimizing away the attribute in cases where it is not necessary.

This affects the amdgpu and nvptx targets.

cc @kjetilkjeka, @kulst for nvptx
cc @ZuseZ4

r? @nnethercote, as you already reviewed this in the other PR

Split out from rust-lang/rust#149637, the part here should be uncontroversial.
2026-04-08 14:21:57 +02:00
David Wood
a24ee0329e cg_llvm/debuginfo: scalable vectors
Generate debuginfo for scalable vectors, following the structure that
Clang generates for scalable vectors.
2026-04-03 10:37:42 +00:00
bors
fb27476aaf Auto merge of #154468 - Kobzol:revert-154200, r=dingxiangfei2009
Revert "Rollup merge of #154200 - resrever:enable-dwarf-call-sites, r=dingxiangfei2009"

This reverts commit 2f1603077b, reversing
changes made to 6e3c17424d.

Debugging perf. hit from https://github.com/rust-lang/rust/pull/154384.

The binary size hits from https://github.com/rust-lang/rust/pull/154468#issuecomment-4144557076 were due to this PR, not all of the copmile-time hits though.
2026-03-28 16:59:18 +00:00
Manuel Drehwald
a3261a2307 Revert "Link LLVM dynamically on aarch64-apple-darwin"
This reverts commit e7c268f883.
2026-03-28 05:11:48 +01:00
Jakub Beránek
8b44562bc8 Revert "Rollup merge of #154200 - resrever:enable-dwarf-call-sites, r=dingxiangfei2009"
This reverts commit 2f1603077b, reversing
changes made to 6e3c17424d.
2026-03-27 20:08:24 +01:00
Jonathan Brouwer
2f1603077b Rollup merge of #154200 - resrever:enable-dwarf-call-sites, r=dingxiangfei2009
debuginfo: emit DW_TAG_call_site entries

Set `FlagAllCallsDescribed` on function definition DIEs so LLVM emits DW_TAG_call_site entries, letting debuggers and analysis tools track tail calls.
2026-03-25 19:52:50 +01:00
Jonathan Brouwer
0cd8de3843 Rollup merge of #153049 - Darksonn:kasan-sw-tags, r=fmease
Add `-Zsanitize=kernel-hwaddress`

The Linux kernel has a config option called `CONFIG_KASAN_SW_TAGS`  that enables `-fsanitize=kernel-hwaddress`. This is not supported by Rust.

One slightly awkward detail is that `#[sanitize(address = "off")]` applies to both `-Zsanitize=address` and `-Zsanitize=kernel-address`. Probably it was done this way because both are the same LLVM pass. I replicated this logic here for hwaddress, but it might be undesirable.

Note that `#[sanitize(kernel_hwaddress = "off")]` could be supported as an annotation on statics, but since it's also missing for `#[sanitize(hwaddress = "off")]`, I did not add it.

MCP: https://github.com/rust-lang/compiler-team/issues/975
Tracking issue: https://github.com/rust-lang/rust/issues/154171

cc @rcvalle @maurer @ojeda
2026-03-25 19:52:49 +01:00
Scott Young
9677d7a587 debuginfo: emit DW_TAG_call_site entries 2026-03-22 08:42:21 -04:00
sgasho
e7c268f883 Link LLVM dynamically on aarch64-apple-darwin 2026-03-22 16:06:31 +09:00
Alice Ryhl
a197752e88 Add kernel-hwaddress sanitizer
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2026-03-17 20:23:59 +00:00