Skip to content

Commit 977f354

Browse files
committed
fix PrintMod* flags
1 parent 43d7e5b commit 977f354

File tree

1 file changed

+14
-10
lines changed
  • compiler/rustc_codegen_llvm/src/back

1 file changed

+14
-10
lines changed

compiler/rustc_codegen_llvm/src/back/lto.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -617,22 +617,26 @@ pub(crate) fn run_pass_manager(
617617
let enable_ad = config.autodiff.contains(&config::AutoDiff::Enable);
618618
let stage =
619619
if enable_ad { write::AutodiffStage::DuringAD } else { write::AutodiffStage::PostAD };
620+
621+
// If Enzyme fails to differentiate the code, then this module will have everything that's
622+
// needed to reproduce the bug.
623+
if config.autodiff.contains(&config::AutoDiff::PrintModBefore) {
624+
unsafe { llvm::LLVMDumpModule(module.module_llvm.llmod()) };
625+
}
620626
unsafe {
621627
write::llvm_optimize(cgcx, dcx, module, config, opt_level, opt_stage, stage)?;
622628
}
623-
if cfg!(llvm_enzyme) && !thin && enable_ad {
629+
if cfg!(llvm_enzyme) && enable_ad {
630+
let opt_stage = llvm::OptStage::FatLTO;
631+
let stage = write::AutodiffStage::PostAD;
624632
unsafe {
625-
write::llvm_optimize(
626-
cgcx,
627-
dcx,
628-
module,
629-
config,
630-
opt_level,
631-
llvm::OptStage::FatLTO,
632-
write::AutodiffStage::PostAD,
633-
)?;
633+
write::llvm_optimize(cgcx, dcx, module, config, opt_level, opt_stage, stage)?;
634634
}
635635
}
636+
// This is the final IR, so people should be able to inspect the optimized autodiff output.
637+
if config.autodiff.contains(&config::AutoDiff::PrintModAfter) {
638+
unsafe { llvm::LLVMDumpModule(module.module_llvm.llmod()) };
639+
}
636640
debug!("lto done");
637641
Ok(())
638642
}

0 commit comments

Comments
 (0)