Commit Graph

255 Commits

Author SHA1 Message Date
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
Arthur Eubanks
f38839a874 format 2025-10-21 21:35:23 +00:00
Arthur Eubanks
fc7c4be59a 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-21 20:58:27 +00:00
Zalathar
98c95c966b Remove current code for embedding command-line args in PDB 2025-10-18 12:24:40 +11:00
Augie Fackler
eb20c6abd6 PassWrapper: use non-deprecated lookupTarget method
This avoids an extra trip through a triple string by directly passing
the Triple, and has been available since LLVM 21. The string overload
was deprecated today and throws an error on our CI for HEAD due to
-Werror paranoia, so we may as well clean this up now and also skip the
conversion on LLVM 21 since we can.

@rustbot label llvm-main
2025-10-07 11:02:13 -04:00
Augie Fackler
bd860bdf26 Fix typo in LLVM_VERSION_ macro use
Co-authored-by: Nikita Popov <github@npopov.com>
2025-09-26 15:38:30 -04:00
Augie Fackler
4c7292aba3 PassWrapper: drop unused variable for LLVM 22+ 2025-09-26 13:27:34 -04:00
Augie Fackler
7a9b6d94d4 PassWrapper: update for new PGOOptions args in LLVM 22
This changed in upstream change a5569b4bd7f8.

@rustbot label llvm-main
2025-09-25 18:24:16 -04:00
Zalathar
85018f09f6 Use LLVMDisposeTargetMachine 2025-09-25 18:10:55 +10:00
Zalathar
8b0a254860 Move target machine command-line quoting from C++ to Rust 2025-09-18 15:25:25 +10:00
Josh Stone
580b4891aa Update the minimum external LLVM to 20 2025-09-16 11:49:20 -07:00
klensy
acb35038ff remove unused getLongestEntryLength 2025-09-11 21:43:18 +03:00
klensy
0e5281cea8 remove unused macro 2025-09-11 21:40:25 +03:00
bjorn3
f2933b34a8 Remove want_summary argument from prepare_thin
It is always false nowadays. ThinLTO summary writing is instead done by
llvm_optimize.
2025-09-06 18:37:23 +00:00
bjorn3
23e72ab41e Move ___asan_globals_registered export
All other sanitizer symbols are handled in prepare_lto already.
2025-08-28 19:36:51 +00:00
bjorn3
fe2eeabe27 Use the object crate rather than LLVM for extracting bitcode sections 2025-07-25 11:21:28 +00:00