@@ -666,7 +666,12 @@ pub(crate) unsafe fn optimize(
666666 } ?;
667667 if let Some ( thin_lto_buffer) = thin_lto_buffer {
668668 let thin_lto_buffer = unsafe { ThinBuffer :: from_raw_ptr ( thin_lto_buffer) } ;
669- let thin_bc_out = cgcx. output_filenames . temp_path ( OutputType :: ThinBitcode , module_name) ;
669+ let thin_bc_out =
670+ if let Some ( incr_comp_session_dir) = cgcx. incr_comp_session_dir . as_ref ( ) {
671+ incr_comp_session_dir. join ( pre_lto_embed_bitcode_filename ( module_name. unwrap ( ) ) )
672+ } else {
673+ cgcx. output_filenames . temp_path ( OutputType :: ThinBitcode , module_name)
674+ } ;
670675 if let Err ( err) = fs:: write ( & thin_bc_out, thin_lto_buffer. data ( ) ) {
671676 dcx. emit_err ( WriteBytecode { path : & thin_bc_out, err } ) ;
672677 }
@@ -803,12 +808,23 @@ pub(crate) unsafe fn codegen(
803808 let _timer = cgcx
804809 . prof
805810 . generic_activity_with_arg ( "LLVM_module_codegen_embed_bitcode" , & * module. name ) ;
806- let thin_bc_out =
807- cgcx. output_filenames . temp_path ( OutputType :: ThinBitcode , module_name) ;
808- assert ! ( thin_bc_out. exists( ) , "cannot find {:?} as embedded bitcode" , thin_bc_out) ;
811+ let thin_bc_out = if let Some ( incr_comp_session_dir) =
812+ cgcx. incr_comp_session_dir . as_ref ( )
813+ {
814+ incr_comp_session_dir. join ( pre_lto_embed_bitcode_filename ( module_name. unwrap ( ) ) )
815+ } else {
816+ cgcx. output_filenames . temp_path ( OutputType :: ThinBitcode , module_name)
817+ } ;
818+ assert ! (
819+ thin_bc_out. exists( ) ,
820+ "cannot find {} as embedded bitcode" ,
821+ thin_bc_out. display( )
822+ ) ;
809823 let data = fs:: read ( & thin_bc_out) . unwrap ( ) ;
810- debug ! ( "removing embed bitcode file {:?}" , thin_bc_out) ;
811- ensure_removed ( dcx, & thin_bc_out) ;
824+ if cgcx. incr_comp_session_dir . is_none ( ) {
825+ debug ! ( "removing embed bitcode file {:?}" , thin_bc_out) ;
826+ ensure_removed ( dcx, & thin_bc_out) ;
827+ }
812828 unsafe {
813829 embed_bitcode ( cgcx, llcx, llmod, & config. bc_cmdline , & data) ;
814830 }
@@ -1174,3 +1190,7 @@ fn record_llvm_cgu_instructions_stats(prof: &SelfProfilerRef, llmod: &llvm::Modu
11741190 serde_json:: from_str ( & raw_stats) . expect ( "cannot parse llvm cgu instructions stats" ) ;
11751191 prof. artifact_size ( "cgu_instructions" , module, total) ;
11761192}
1193+
1194+ fn pre_lto_embed_bitcode_filename ( module_name : & str ) -> String {
1195+ format ! ( "{module_name}.{}" , OutputType :: ThinBitcode . extension( ) )
1196+ }
0 commit comments