Skip to content

Commit e523be9

Browse files
committed
refactor: initialize EnzymeWrapper in LlvmCodegenBackend::init
1 parent 7d47316 commit e523be9

File tree

4 files changed

+7
-14
lines changed

4 files changed

+7
-14
lines changed

compiler/rustc_codegen_llvm/src/back/lto.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -529,11 +529,8 @@ fn thin_lto(
529529
}
530530

531531
#[cfg(feature = "llvm_enzyme")]
532-
pub(crate) fn enable_autodiff_settings(
533-
sysroot: &rustc_session::config::Sysroot,
534-
ad: &[config::AutoDiff],
535-
) {
536-
let mut enzyme = llvm::EnzymeWrapper::get_or_init(sysroot);
532+
pub(crate) fn enable_autodiff_settings(ad: &[config::AutoDiff]) {
533+
let mut enzyme = llvm::EnzymeWrapper::get_instance();
537534

538535
for val in ad {
539536
// We intentionally don't use a wildcard, to not forget handling anything new.

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ pub(crate) unsafe fn llvm_optimize(
727727
let llvm_plugins = config.llvm_plugins.join(",");
728728

729729
let enzyme_fn = if consider_ad {
730-
let wrapper = llvm::EnzymeWrapper::get_or_init(&cgcx.sysroot);
730+
let wrapper = llvm::EnzymeWrapper::get_instance();
731731
wrapper.registerEnzymeAndPassPipeline
732732
} else {
733733
std::ptr::null()

compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,11 @@ impl CodegenBackend for LlvmCodegenBackend {
244244
#[cfg(feature = "llvm_enzyme")]
245245
{
246246
use rustc_session::config::AutoDiff;
247-
if sess.opts.unstable_opts.autodiff.contains(&AutoDiff::Enable) {
248-
{
249-
use crate::back::lto::enable_autodiff_settings;
250247

251-
enable_autodiff_settings(&sess.opts.sysroot, &sess.opts.unstable_opts.autodiff);
252-
}
248+
use crate::back::lto::enable_autodiff_settings;
249+
if sess.opts.unstable_opts.autodiff.contains(&AutoDiff::Enable) {
250+
drop(llvm::EnzymeWrapper::get_or_init(&sess.opts.sysroot));
251+
enable_autodiff_settings(&sess.opts.unstable_opts.autodiff);
253252
}
254253
}
255254
}

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use rustc_middle::ty::TyCtxt;
2929
use rustc_session::Session;
3030
use rustc_session::config::{
3131
self, CrateType, Lto, OutFileName, OutputFilenames, OutputType, Passes, SwitchWithOptPath,
32-
Sysroot,
3332
};
3433
use rustc_span::source_map::SourceMap;
3534
use rustc_span::{FileName, InnerSpan, Span, SpanData, sym};
@@ -347,7 +346,6 @@ pub struct CodegenContext<B: WriteBackendMethods> {
347346
pub split_debuginfo: rustc_target::spec::SplitDebuginfo,
348347
pub split_dwarf_kind: rustc_session::config::SplitDwarfKind,
349348
pub pointer_size: Size,
350-
pub sysroot: Sysroot,
351349

352350
/// Emitter to use for diagnostics produced during codegen.
353351
pub diag_emitter: SharedEmitter,
@@ -1318,7 +1316,6 @@ fn start_executing_work<B: ExtraBackendMethods>(
13181316
parallel: backend.supports_parallel() && !sess.opts.unstable_opts.no_parallel_backend,
13191317
pointer_size: tcx.data_layout.pointer_size(),
13201318
invocation_temp: sess.invocation_temp.clone(),
1321-
sysroot: sess.opts.sysroot.clone(),
13221319
};
13231320

13241321
// This is the "main loop" of parallel work happening for parallel codegen.

0 commit comments

Comments
 (0)