Skip to content

Commit 4d12cb0

Browse files
committed
refactor: initialize EnzymeWrapper in LlvmCodegenBackend::init
1 parent ddd5aad commit 4d12cb0

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
@@ -731,7 +731,7 @@ pub(crate) unsafe fn llvm_optimize(
731731
let llvm_plugins = config.llvm_plugins.join(",");
732732

733733
let enzyme_fn = if consider_ad {
734-
let wrapper = llvm::EnzymeWrapper::get_or_init(&cgcx.sysroot);
734+
let wrapper = llvm::EnzymeWrapper::get_instance();
735735
wrapper.registerEnzymeAndPassPipeline
736736
} else {
737737
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,
@@ -1319,7 +1317,6 @@ fn start_executing_work<B: ExtraBackendMethods>(
13191317
parallel: backend.supports_parallel() && !sess.opts.unstable_opts.no_parallel_backend,
13201318
pointer_size: tcx.data_layout.pointer_size(),
13211319
invocation_temp: sess.invocation_temp.clone(),
1322-
sysroot: sess.opts.sysroot.clone(),
13231320
};
13241321

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

0 commit comments

Comments
 (0)