Skip to content

Commit 71873c9

Browse files
committed
Use the incremental build directory to save the bitcode if possible
1 parent a456668 commit 71873c9

File tree

1 file changed

+26
-6
lines changed
  • compiler/rustc_codegen_llvm/src/back

1 file changed

+26
-6
lines changed

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,12 @@ pub(crate) unsafe fn optimize(
726726
}?;
727727
if let Some(thin_lto_buffer) = thin_lto_buffer {
728728
let thin_lto_buffer = unsafe { ThinBuffer::from_raw_ptr(thin_lto_buffer) };
729-
let thin_bc_out = cgcx.output_filenames.temp_path(OutputType::ThinBitcode, module_name);
729+
let thin_bc_out =
730+
if let Some(incr_comp_session_dir) = cgcx.incr_comp_session_dir.as_ref() {
731+
incr_comp_session_dir.join(pre_lto_embed_bitcode_filename(module_name.unwrap()))
732+
} else {
733+
cgcx.output_filenames.temp_path(OutputType::ThinBitcode, module_name)
734+
};
730735
if let Err(err) = fs::write(&thin_bc_out, thin_lto_buffer.data()) {
731736
dcx.emit_err(WriteBytecode { path: &thin_bc_out, err });
732737
}
@@ -863,12 +868,23 @@ pub(crate) unsafe fn codegen(
863868
let _timer = cgcx
864869
.prof
865870
.generic_activity_with_arg("LLVM_module_codegen_embed_bitcode", &*module.name);
866-
let thin_bc_out =
867-
cgcx.output_filenames.temp_path(OutputType::ThinBitcode, module_name);
868-
assert!(thin_bc_out.exists(), "cannot find {:?} as embedded bitcode", thin_bc_out);
871+
let thin_bc_out = if let Some(incr_comp_session_dir) =
872+
cgcx.incr_comp_session_dir.as_ref()
873+
{
874+
incr_comp_session_dir.join(pre_lto_embed_bitcode_filename(module_name.unwrap()))
875+
} else {
876+
cgcx.output_filenames.temp_path(OutputType::ThinBitcode, module_name)
877+
};
878+
assert!(
879+
thin_bc_out.exists(),
880+
"cannot find {} as embedded bitcode",
881+
thin_bc_out.display()
882+
);
869883
let data = fs::read(&thin_bc_out).unwrap();
870-
debug!("removing embed bitcode file {:?}", thin_bc_out);
871-
ensure_removed(dcx, &thin_bc_out);
884+
if cgcx.incr_comp_session_dir.is_none() {
885+
debug!("removing embed bitcode file {:?}", thin_bc_out);
886+
ensure_removed(dcx, &thin_bc_out);
887+
}
872888
unsafe {
873889
embed_bitcode(cgcx, llcx, llmod, &config.bc_cmdline, &data);
874890
}
@@ -1236,3 +1252,7 @@ fn record_llvm_cgu_instructions_stats(prof: &SelfProfilerRef, llmod: &llvm::Modu
12361252
serde_json::from_str(&raw_stats).expect("cannot parse llvm cgu instructions stats");
12371253
prof.artifact_size("cgu_instructions", module, total);
12381254
}
1255+
1256+
fn pre_lto_embed_bitcode_filename(module_name: &str) -> String {
1257+
format!("{module_name}.{}", OutputType::ThinBitcode.extension())
1258+
}

0 commit comments

Comments
 (0)