@@ -397,25 +397,6 @@ impl<B: WriteBackendMethods> CodegenContext<B> {
397397 }
398398}
399399
400- fn generate_fat_lto_work < B : ExtraBackendMethods > (
401- cgcx : & CodegenContext < B > ,
402- autodiff : Vec < AutoDiffItem > ,
403- needs_fat_lto : Vec < FatLtoInput < B > > ,
404- import_only_modules : Vec < ( SerializedModule < B :: ModuleBuffer > , WorkProduct ) > ,
405- ) -> WorkItem < B > {
406- let _prof_timer = cgcx. prof . generic_activity ( "codegen_generate_lto_work" ) ;
407-
408- let module =
409- B :: run_fat_lto ( cgcx, needs_fat_lto, import_only_modules) . unwrap_or_else ( |e| e. raise ( ) ) ;
410- if cgcx. lto == Lto :: Fat && !autodiff. is_empty ( ) {
411- let config = cgcx. config ( ModuleKind :: Regular ) ;
412- if let Err ( err) = B :: autodiff ( cgcx, & module, autodiff, config) {
413- err. raise ( ) ;
414- }
415- }
416- WorkItem :: FatLto ( module)
417- }
418-
419400fn generate_thin_lto_work < B : ExtraBackendMethods > (
420401 cgcx : & CodegenContext < B > ,
421402 needs_thin_lto : Vec < ( String , B :: ThinBuffer ) > ,
@@ -739,7 +720,11 @@ pub(crate) enum WorkItem<B: WriteBackendMethods> {
739720 /// directory.
740721 CopyPostLtoArtifacts ( CachedModuleCodegen ) ,
741722 /// Performs fat LTO on the given module.
742- FatLto ( ModuleCodegen < B :: Module > ) ,
723+ FatLto {
724+ needs_fat_lto : Vec < FatLtoInput < B > > ,
725+ import_only_modules : Vec < ( SerializedModule < B :: ModuleBuffer > , WorkProduct ) > ,
726+ autodiff : Vec < AutoDiffItem > ,
727+ } ,
743728 /// Performs thin-LTO on the given module.
744729 ThinLto ( lto:: ThinModule < B > ) ,
745730}
@@ -748,7 +733,7 @@ impl<B: WriteBackendMethods> WorkItem<B> {
748733 fn module_kind ( & self ) -> ModuleKind {
749734 match * self {
750735 WorkItem :: Optimize ( ref m) => m. kind ,
751- WorkItem :: CopyPostLtoArtifacts ( _) | WorkItem :: FatLto ( _ ) | WorkItem :: ThinLto ( _) => {
736+ WorkItem :: CopyPostLtoArtifacts ( _) | WorkItem :: FatLto { .. } | WorkItem :: ThinLto ( _) => {
752737 ModuleKind :: Regular
753738 }
754739 }
@@ -798,7 +783,7 @@ impl<B: WriteBackendMethods> WorkItem<B> {
798783 match self {
799784 WorkItem :: Optimize ( m) => desc ( "opt" , "optimize module" , & m. name ) ,
800785 WorkItem :: CopyPostLtoArtifacts ( m) => desc ( "cpy" , "copy LTO artifacts for" , & m. name ) ,
801- WorkItem :: FatLto ( _ ) => desc ( "lto" , "fat LTO module" , "everything" ) ,
786+ WorkItem :: FatLto { .. } => desc ( "lto" , "fat LTO module" , "everything" ) ,
802787 WorkItem :: ThinLto ( m) => desc ( "lto" , "thin-LTO module" , m. name ( ) ) ,
803788 }
804789 }
@@ -1005,9 +990,21 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>(
1005990
1006991fn execute_fat_lto_work_item < B : ExtraBackendMethods > (
1007992 cgcx : & CodegenContext < B > ,
1008- mut module : ModuleCodegen < B :: Module > ,
993+ needs_fat_lto : Vec < FatLtoInput < B > > ,
994+ import_only_modules : Vec < ( SerializedModule < B :: ModuleBuffer > , WorkProduct ) > ,
995+ autodiff : Vec < AutoDiffItem > ,
1009996 module_config : & ModuleConfig ,
1010997) -> Result < WorkItemResult < B > , FatalError > {
998+ let mut module =
999+ B :: run_fat_lto ( cgcx, needs_fat_lto, import_only_modules) . unwrap_or_else ( |e| e. raise ( ) ) ;
1000+
1001+ if cgcx. lto == Lto :: Fat && !autodiff. is_empty ( ) {
1002+ let config = cgcx. config ( ModuleKind :: Regular ) ;
1003+ if let Err ( err) = B :: autodiff ( cgcx, & module, autodiff, config) {
1004+ err. raise ( ) ;
1005+ }
1006+ }
1007+
10111008 B :: optimize_fat ( cgcx, & mut module) ?;
10121009
10131010 let module = B :: codegen ( cgcx, module, module_config) ?;
@@ -1490,13 +1487,14 @@ fn start_executing_work<B: ExtraBackendMethods>(
14901487 if !needs_fat_lto. is_empty ( ) {
14911488 assert ! ( needs_thin_lto. is_empty( ) ) ;
14921489
1493- let work = generate_fat_lto_work (
1494- & cgcx,
1495- autodiff_items. clone ( ) ,
1496- needs_fat_lto,
1497- import_only_modules,
1498- ) ;
1499- work_items. push ( ( work, 0 ) ) ;
1490+ work_items. push ( (
1491+ WorkItem :: FatLto {
1492+ needs_fat_lto,
1493+ import_only_modules,
1494+ autodiff : autodiff_items. clone ( ) ,
1495+ } ,
1496+ 0 ,
1497+ ) ) ;
15001498 if cgcx. parallel {
15011499 helper. request_token ( ) ;
15021500 }
@@ -1867,11 +1865,17 @@ fn spawn_work<'a, B: ExtraBackendMethods>(
18671865 ) ;
18681866 Ok ( execute_copy_from_cache_work_item ( & cgcx, m, module_config) )
18691867 }
1870- WorkItem :: FatLto ( m ) => {
1868+ WorkItem :: FatLto { needs_fat_lto , import_only_modules , autodiff } => {
18711869 let _timer = cgcx
18721870 . prof
18731871 . generic_activity_with_arg ( "codegen_module_perform_lto" , "everything" ) ;
1874- execute_fat_lto_work_item ( & cgcx, m, module_config)
1872+ execute_fat_lto_work_item (
1873+ & cgcx,
1874+ needs_fat_lto,
1875+ import_only_modules,
1876+ autodiff,
1877+ module_config,
1878+ )
18751879 }
18761880 WorkItem :: ThinLto ( m) => {
18771881 let _timer =
0 commit comments