Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
cfb6a1f
simplify how inline asm handles `MaybeUninit`
WaffleLapkin Dec 13, 2025
ddcd55f
Don't allow codegen attributes on trait methods
JonathanBrouwer Nov 9, 2025
8fa10c0
Add regression test for codegen attributes on required trait methods
JonathanBrouwer Nov 9, 2025
7d57c6f
Rename dep_root field of CrateOrigin to dep_root_for_errors
bjorn3 Nov 27, 2025
a0f8dff
Use CrateDepKind::Explicit for the profiler runtime
bjorn3 Nov 27, 2025
c7a99e2
Rename variants of CrateDepKind to be more descriptive
bjorn3 Nov 27, 2025
aff1f2a
Handle CrateOrigin::Injected in CrateOrigin::private_dep
bjorn3 Nov 27, 2025
0e1e72a
Remove dependencies field of CrateMetadata
bjorn3 Nov 28, 2025
f550532
Port `#[rustc_legacy_const_generics]` to use attribute parser
Bryntet Dec 15, 2025
1fe0a85
Add rv64IM
kevaundray Nov 10, 2025
2846968
add riscv64im to ignore list for stage0
kevaundray Nov 10, 2025
9ba7852
refactor readme
kevaundray Nov 10, 2025
7cf3556
document that mpmc channels deliver an item to (at most) one receiver
david-d-h Dec 15, 2025
9c14e3f
std: sys: fs: uefi: Implement set_times and set_perm
Ayush1325 Nov 29, 2025
ddd5aad
feat: dlopen Enzyme
sgasho Nov 24, 2025
4d12cb0
refactor: initialize EnzymeWrapper in LlvmCodegenBackend::init
sgasho Dec 15, 2025
58aeab5
add trailing line at compiler/rustc_codegen_llvm/Cargo.toml
sgasho Dec 15, 2025
356bb7a
Rollup merge of #148756 - JonathanBrouwer:link_section_targets2, r=jd…
matthiaskrgr Dec 15, 2025
7b80dd3
Rollup merge of #148790 - kevaundray:kw/rv64im-unknown-elf, r=davidtw…
matthiaskrgr Dec 15, 2025
81b602d
Rollup merge of #149271 - sgasho:enzyme-dlopen, r=bjorn3
matthiaskrgr Dec 15, 2025
2b539e9
Rollup merge of #149459 - Ayush1325:uefi-fs-setinfo, r=joboet
matthiaskrgr Dec 15, 2025
a18e0ae
Rollup merge of #149950 - WaffleLapkin:inlines-ur-mu-into-asm, r=jdon…
matthiaskrgr Dec 15, 2025
6ac2bdb
Rollup merge of #150000 - Bryntet:brynte/parse_legacy_const_generic_a…
matthiaskrgr Dec 15, 2025
7910391
Rollup merge of #150014 - bjorn3:metadata_loader_cleanups, r=jieyouxu
matthiaskrgr Dec 15, 2025
d2c0c65
Rollup merge of #150021 - david-d-h:main, r=ChrisDenton
matthiaskrgr Dec 15, 2025
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: dlopen Enzyme
  • Loading branch information
sgasho committed Dec 15, 2025
commit ddd5aad8a309ae49b3526334d2083db6b13d816a
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3613,6 +3613,7 @@ dependencies = [
"gimli 0.31.1",
"itertools",
"libc",
"libloading 0.9.0",
"measureme",
"object 0.37.3",
"rustc-demangle",
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_llvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ bitflags = "2.4.1"
gimli = "0.31"
itertools = "0.12"
libc = "0.2"
libloading = { version = "0.9.0", optional = true }
measureme = "12.0.1"
object = { version = "0.37.0", default-features = false, features = ["std", "read"] }
rustc-demangle = "0.1.21"
Expand Down Expand Up @@ -46,7 +47,6 @@ tracing = "0.1"
[features]
# tidy-alphabetical-start
check_only = ["rustc_llvm/check_only"]
llvm_enzyme = []
llvm_enzyme = ["dep:libloading"]
llvm_offload = []
# tidy-alphabetical-end

32 changes: 17 additions & 15 deletions compiler/rustc_codegen_llvm/src/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,31 +528,37 @@ fn thin_lto(
}
}

fn enable_autodiff_settings(ad: &[config::AutoDiff]) {
#[cfg(feature = "llvm_enzyme")]
pub(crate) fn enable_autodiff_settings(
sysroot: &rustc_session::config::Sysroot,
ad: &[config::AutoDiff],
) {
let mut enzyme = llvm::EnzymeWrapper::get_or_init(sysroot);

for val in ad {
// We intentionally don't use a wildcard, to not forget handling anything new.
match val {
config::AutoDiff::PrintPerf => {
llvm::set_print_perf(true);
enzyme.set_print_perf(true);
}
config::AutoDiff::PrintAA => {
llvm::set_print_activity(true);
enzyme.set_print_activity(true);
}
config::AutoDiff::PrintTA => {
llvm::set_print_type(true);
enzyme.set_print_type(true);
}
config::AutoDiff::PrintTAFn(fun) => {
llvm::set_print_type(true); // Enable general type printing
llvm::set_print_type_fun(&fun); // Set specific function to analyze
enzyme.set_print_type(true); // Enable general type printing
enzyme.set_print_type_fun(&fun); // Set specific function to analyze
}
config::AutoDiff::Inline => {
llvm::set_inline(true);
enzyme.set_inline(true);
}
config::AutoDiff::LooseTypes => {
llvm::set_loose_types(true);
enzyme.set_loose_types(true);
}
config::AutoDiff::PrintSteps => {
llvm::set_print(true);
enzyme.set_print(true);
}
// We handle this in the PassWrapper.cpp
config::AutoDiff::PrintPasses => {}
Expand All @@ -571,9 +577,9 @@ fn enable_autodiff_settings(ad: &[config::AutoDiff]) {
}
}
// This helps with handling enums for now.
llvm::set_strict_aliasing(false);
enzyme.set_strict_aliasing(false);
// FIXME(ZuseZ4): Test this, since it was added a long time ago.
llvm::set_rust_rules(true);
enzyme.set_rust_rules(true);
}

pub(crate) fn run_pass_manager(
Expand Down Expand Up @@ -607,10 +613,6 @@ pub(crate) fn run_pass_manager(
if enable_ad { write::AutodiffStage::DuringAD } else { write::AutodiffStage::PostAD }
};

if enable_ad {
enable_autodiff_settings(&config.autodiff);
}

unsafe {
write::llvm_optimize(cgcx, dcx, module, None, config, opt_level, opt_stage, stage);
}
Expand Down
9 changes: 8 additions & 1 deletion compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,13 @@ pub(crate) unsafe fn llvm_optimize(

let llvm_plugins = config.llvm_plugins.join(",");

let enzyme_fn = if consider_ad {
let wrapper = llvm::EnzymeWrapper::get_or_init(&cgcx.sysroot);
wrapper.registerEnzymeAndPassPipeline
} else {
std::ptr::null()
};

let result = unsafe {
llvm::LLVMRustOptimize(
module.module_llvm.llmod(),
Expand All @@ -749,7 +756,7 @@ pub(crate) unsafe fn llvm_optimize(
vectorize_loop,
config.no_builtins,
config.emit_lifetime_markers,
run_enzyme,
enzyme_fn,
print_before_enzyme,
print_after_enzyme,
print_passes,
Expand Down
12 changes: 12 additions & 0 deletions compiler/rustc_codegen_llvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,18 @@ impl CodegenBackend for LlvmCodegenBackend {

fn init(&self, sess: &Session) {
llvm_util::init(sess); // Make sure llvm is inited

#[cfg(feature = "llvm_enzyme")]
{
use rustc_session::config::AutoDiff;
if sess.opts.unstable_opts.autodiff.contains(&AutoDiff::Enable) {
{
use crate::back::lto::enable_autodiff_settings;

enable_autodiff_settings(&sess.opts.sysroot, &sess.opts.unstable_opts.autodiff);
}
}
}
}

fn provide(&self, providers: &mut Providers) {
Expand Down
Loading