Commit Graph

270 Commits

Author SHA1 Message Date
Augie Fackler
96b774bdd6 PassWrapper: adapt to LLVM reading exception model from module flag 2026-09-18 08:52:10 -04:00
Jonathan Brouwer
c79bc2c916 Rollup merge of #162817 - durin42:llvm-24-thread-model, r=nikic
rustc_{codegen_,}llvm: adapt to new ThreadModel API

LLVM 24 [has moved](e733cebdf7) from TargetOptions::ThreadModel to specifying thread-model as a module flag. This catches us up.

@rustbot label: +llvm-main
2026-09-17 21:00:13 +02:00
Augie Fackler
bc1f40f8df PassWrapper: adapt for removal of EABIVersion arg in LLVM 24
We never set this to anything but the default that I noticed, and now
it's derived from the target triple in LLVM 24.
2026-09-15 15:16:20 -04:00
Augie Fackler
5dd4631041 rustc_{codegen_,}llvm: adapt to new ThreadModel API
LLVM 24 has moved from TargetOptions::ThreadModel to specifying
thread-model as a module flag. This catches us up.
2026-09-15 12:21:54 -04:00
Jonathan Brouwer
09c7c12af1 Rollup merge of #161903 - nnethercote:fix-target_config-cycle, r=nikic
Fix initialization cycle in `target_config`

There is an initialization cycle in `target_config`. Details in the final commit. The previous commits are precursors that support the changes in the final commit.

r? @nikic
cc @cuviper @RalfJung @Zalathar @Patryk27
2026-09-14 15:15:56 +02:00
Hans Wennborg
0847dae703 call renumberMetadataForAssembly() in LLVMRustPrintModule() 2026-09-08 09:41:18 +02:00
Nicholas Nethercote
7f0581d42e Fix initialization cycle in target_config
`llvm::target_config` creates `target_machine` by calling
`create_informational_target_machine`, which calls
`target_machine_factory`, which uses `internal_target_features`. But
this is just before `internal_target_features` is initialized! So we
should move `internal_target_features` initialization before
`target_machine`, right?

But `internal_target_features` initialization involves a closure that
inspects `target_machine`. There is a cyclic dependency. There is enough
function nesting here that it's hard to spot.

In practice this cycle doesn't cause problems because the closure
doesn't inspect the parts of `target_machine` that depend on
`internal_target_features`. But it demonstrates how startup
initialization is all tangled up, and it's blocking some cleanups I am
doing in #161432 relating to the dangerous uses of `Session` before it's
fully initialized.

Therefore, this commit changes the first part: instead of creating
an `OwnedTargetMachine` we create an `OwnedMCSubtargetInfo`. This is a
smaller type that has the feature information we need but doesn't depend
on `internal_target_features`. Under the covers we are now using LLVM's
`Target::createMCSubtargetInfo` instead of
`TargetMachine::getMCSubtargetInfo` so that we avoid having to create a
`TargetMachine` at this early stage. This eliminates the cycle.
(`TargetMachine` can still be created later on, once we're past this
fraught initialization.) There are some slight differences between these
two approaches, and the preceding commits fixed up some issues there.

Some details about this commit:
- The new `OwnedMCSubtargetInfo` is similar to the existing
  `OwnedTargetMachine`.
- `create_informational_target_machine` no longer needs a `for_cfg`
  parameter, because the one site where `for_cfg` was true has been
  removed.
- `LLVMRustCreateMCSubtargetInfo` mostly replicates part of
  `LLVMRustCreateTargetMachine`
- `LLVMRustMCSubtargetInfoHasFeature` partly replicates
  `LLVMRustHasFeature`.
- `LLVMRustHasFeature` is no longer needed.
- The error message for `custom-target-invalid-llvm-target.rs` changed.
2026-08-31 15:09:43 +10:00
Nicholas Nethercote
27f7c65c12 Remove dead LLVMOpaquePass/LLVMPassRef decls 2026-08-31 10:26:14 +10:00
Guillaume Gomez
4de5370f23 Rollup merge of #161098 - durin42:llvm-24-llvm-any-change, r=cuviper
PassWrapper: handle LLVM 24 change in function types

LLVM 24 stopped using llvm::Any here [to avoid heap allocations](fa23198d68) in PassInstrumentation.

@rustbot label: +llvm-main
2026-08-25 00:33:40 +02:00
Guillaume Gomez
0ce1db749b Rollup merge of #161670 - jakos-sec:large-data-threshold, r=nagisa
Pass LargeDataThreshold to LLVM module IR

Before, LargeDataThreshold was only set via `LLVMRustCreateTargetMachine`. When LTO is enabled, this information is required to be passed into the generated LLVM module IR files since the LTO linker spins up its own TargetMachine and otherwise has no knowledge of the LargeDataThreshold.

Currently, `-Z large-data-threshold` has no affect at all when compiling with LTO.
This commit makes sure that if `-Z large-data-threshold` is passed and not 0, it is preserved and stored into the generated LLVM IR.
2026-08-25 00:33:35 +02:00
Augie Fackler
1f7f241417 Fix whitespace. 2026-08-24 10:29:02 -04:00
Jakob Koschel
7eaf48cc1f Pass LargeDataThreshold to LLVM module IR
Before, LargeDataThreshold was only set via `LLVMRustCreateTargetMachine`.
When LTO is enabled, this information is required to be passed into the
generated LLVM module IR files since the LTO linker spins up its own
TargetMachine and otherwise has no knowledge of the LargeDataThreshold.

Currently, `-Z large-data-threshold` has no affect at all when compiling
with LTO.
This commit makes sure that if `-Z large-data-threshold` is passed and
not 0, it is preserved and stored into the generated LLVM IR.
2026-08-24 12:31:48 +00:00
Tim Neumann
4c28ae248a LLVM 24: configure float-abi via module flag 2026-08-19 18:31:26 +02:00
Augie Fackler
50b867f932 PassWrapper: clang-format 2026-08-14 11:23:43 -04:00
Augie Fackler
299213ffae PassWrapper: handle LLVM 24 change in function types
LLVM 24 stopped using llvm::Any here to avoid heap allocations in
PassInstrumentation.
2026-08-14 10:53:32 -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
Augie Fackler
b8d3a4ac9c Reapply "LLVM 23: Run AssignGUIDPass in some places"
This reverts commit 4919940fad.
2026-07-08 12:17:39 -04: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
sgasho
d7e4edd9a1 Add -Zautodiff_post_passes flag to limit which llvm passes to run after enzyme 2026-07-03 00:43:49 +09: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
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
Tim Neumann
cdb73bb677 LLVM 23: Run AssignGUIDPass in some places 2026-05-28 13:30:25 +02:00
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
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
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
Alice Ryhl
a197752e88 Add kernel-hwaddress sanitizer
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2026-03-17 20:23:59 +00:00
Josh Stone
52dfa94cdc Update the minimum external LLVM to 21 2026-03-12 16:45:42 -07:00
Stuart Cook
cc0a60fd74 Rollup merge of #153446 - bjorn3:llvm_pre_link_thinlto, r=cuviper
Always use the ThinLTO pipeline for pre-link optimizations

When using cargo this was already effectively done for all dependencies as cargo passes -Clinker-plugin-lto without -Clto=fat/thin. -Clinker-plugin-lto assumes that ThinLTO will be used. The ThinLTO pre-link pipeline is faster than the fat LTO one. And according to the benchmarks in [^1] there is barely any runtime performance difference between executables that used fat LTO with the fat vs ThinLTO pre-link pipeline.

This also helps avoid having yet another code path if we want to support Unified LTO (that is a single bitcode file that supports being used for both fat LTO and ThinLTO when using linker plugin LTO, we already support it when rustc does LTO as ThinLTO bitcode is enough of a superset of fat LTO bitcode that it happens to work by accident if you don't explicitly have a check preventing mixing of them for the current set of LTO features that rustc exposes.) I'm currently still investigating if rustc would benefit from Unified LTO and how exactly to integrate it.

[^1]: https://discourse.llvm.org/t/rfc-a-unified-lto-bitcode-frontend/61774
2026-03-08 14:01:35 +11:00
bjorn3
71a31b30d9 Always use the ThinLTO pipeline for pre-link optimizations
When using cargo this was already effectively done for all dependencies
as cargo passes -Clinker-plugin-lto without -Clto=fat/thin.
-Clinker-plugin-lto assumes that ThinLTO will be used. The ThinLTO
pre-link pipeline is faster than the fat LTO one. And according to the
benchmarks in [1] there is barely any runtime performance difference
between executables that used fat LTO with the fat vs ThinLTO pre-link
pipeline.

[1]: https://discourse.llvm.org/t/rfc-a-unified-lto-bitcode-frontend/61774
2026-03-05 17:40:58 +00:00
Daniel Paoliello
614bac581b [win] Fix truncated unwinds for Arm64 Windows 2026-02-27 14:53:09 -08:00
bjorn3
474a7168ab Remove explicit EmitThinLTOSummary argument
In favor of passing a NULL ThinLTOSummaryBufferRef. And improve type
improve type safety on the Rust side.
2026-02-21 11:47:45 +00:00
bjorn3
a086b3617e Remove ModuleBuffer ThinBuffer duplication 2026-02-21 11:47:45 +00:00
bjorn3
a5372d1dba Replace LLVMRustThinLTOBuffer with separate LLVMRustBuffers for bitcode and summary 2026-02-21 11:47:45 +00:00
bjorn3
c51cd0e691 Deduplicate some code in LLVMRustOptimize 2026-02-20 12:19:41 +00:00
bjorn3
6366a698e3 Remove -Zemit-thin-lto flag
As far as I can tell it was introduced to allow fat LTO with
-Clinker-plugin-lto. Later a change was made to automatically disable
ThinLTO summary generation when -Clinker-plugin-lto -Clto=fat is used,
so we can safely remove it.
2026-02-20 12:19:41 +00:00
Manuel Drehwald
c89a89bb14 Fix multi-cgu+debug builds using autodiff by delaying autodiff till lto 2026-02-11 14:08:56 -05:00
Farid Zakaria
93f2e80f4a Add -Z large-data-threshold
This flag allows specifying the threshold size for placing static data
in large data sections when using the medium code model on x86-64.

When using -Ccode-model=medium, data smaller than this threshold uses
RIP-relative addressing (32-bit offsets), while larger data uses
absolute 64-bit addressing. This allows the compiler to generate more
efficient code for smaller data while still supporting data larger than
2GB.

This mirrors the -mlarge-data-threshold flag available in GCC and Clang.
The default threshold is 65536 bytes (64KB) if not specified, matching
LLVM's default behavior.
2026-01-07 11:57:48 -08:00
Devon Loehr
634251cba8 Accommodate upstream PassPlugin rename 2025-12-26 15:40:40 +00:00
sgasho
ddd5aad8a3 feat: dlopen Enzyme 2025-12-16 00:31:32 +09:00
Alina Sbirlea
ad73972e99 Fix for LLVM22 making lowering decisions dependent on RuntimeLibraryInfo.
LLVM reference commit:
04c81a9973.
2025-12-04 20:23:00 +00:00
Lucas Baumann
d198633b95 add realtime sanitizer 2025-11-06 13:20:12 +01:00
Zalathar
73b734bf63 Pass debuginfo_compression through FFI as an enum 2025-10-25 23:58:19 +11:00
Matthias Krüger
e132d2d8a5 Rollup merge of #147948 - aeubanks:summarylist, r=durin42
PassWrapper: Access GlobalValueSummaryInfo::SummaryList via getter for LLVM 22+

https://github.com/llvm/llvm-project/pull/164355 makes SummaryList private and provides a getter method.

`@rustbot` label llvm-main
2025-10-22 07:12:12 +02:00
Arthur Eubanks
1e8054669c format 2025-10-21 22:29:48 +00:00
Arthur Eubanks
875cc36b17 actually compile 2025-10-21 22:21:50 +00:00