@@ -408,14 +408,16 @@ fn generate_lto_work<B: ExtraBackendMethods>(
408408
409409 if !needs_fat_lto. is_empty ( ) {
410410 assert ! ( needs_thin_lto. is_empty( ) ) ;
411- let mut module =
411+ let module =
412412 B :: run_fat_lto ( cgcx, needs_fat_lto, import_only_modules) . unwrap_or_else ( |e| e. raise ( ) ) ;
413413 if cgcx. lto == Lto :: Fat && !autodiff. is_empty ( ) {
414414 let config = cgcx. config ( ModuleKind :: Regular ) ;
415- module = module. autodiff ( cgcx, autodiff, config) . unwrap_or_else ( |e| e. raise ( ) ) ;
415+ if let Err ( err) = B :: autodiff ( cgcx, & module, autodiff, config) {
416+ err. raise ( ) ;
417+ }
416418 }
417419 // We are adding a single work item, so the cost doesn't matter.
418- vec ! [ ( WorkItem :: LTO ( module) , 0 ) ]
420+ vec ! [ ( WorkItem :: FatLto ( module) , 0 ) ]
419421 } else {
420422 if !autodiff. is_empty ( ) {
421423 let dcx = cgcx. create_dcx ( ) ;
@@ -428,7 +430,7 @@ fn generate_lto_work<B: ExtraBackendMethods>(
428430 . into_iter ( )
429431 . map ( |module| {
430432 let cost = module. cost ( ) ;
431- ( WorkItem :: LTO ( module) , cost)
433+ ( WorkItem :: ThinLto ( module) , cost)
432434 } )
433435 . chain ( copy_jobs. into_iter ( ) . map ( |wp| {
434436 (
@@ -736,15 +738,19 @@ pub(crate) enum WorkItem<B: WriteBackendMethods> {
736738 /// Copy the post-LTO artifacts from the incremental cache to the output
737739 /// directory.
738740 CopyPostLtoArtifacts ( CachedModuleCodegen ) ,
739- /// Performs (Thin)LTO on the given module.
740- LTO ( lto:: LtoModuleCodegen < B > ) ,
741+ /// Performs fat LTO on the given module.
742+ FatLto ( ModuleCodegen < B :: Module > ) ,
743+ /// Performs thin-LTO on the given module.
744+ ThinLto ( lto:: ThinModule < B > ) ,
741745}
742746
743747impl < B : WriteBackendMethods > WorkItem < B > {
744748 fn module_kind ( & self ) -> ModuleKind {
745749 match * self {
746750 WorkItem :: Optimize ( ref m) => m. kind ,
747- WorkItem :: CopyPostLtoArtifacts ( _) | WorkItem :: LTO ( _) => ModuleKind :: Regular ,
751+ WorkItem :: CopyPostLtoArtifacts ( _) | WorkItem :: FatLto ( _) | WorkItem :: ThinLto ( _) => {
752+ ModuleKind :: Regular
753+ }
748754 }
749755 }
750756
@@ -792,7 +798,8 @@ impl<B: WriteBackendMethods> WorkItem<B> {
792798 match self {
793799 WorkItem :: Optimize ( m) => desc ( "opt" , "optimize module" , & m. name ) ,
794800 WorkItem :: CopyPostLtoArtifacts ( m) => desc ( "cpy" , "copy LTO artifacts for" , & m. name ) ,
795- WorkItem :: LTO ( m) => desc ( "lto" , "LTO module" , m. name ( ) ) ,
801+ WorkItem :: FatLto ( _) => desc ( "lto" , "fat LTO module" , "everything" ) ,
802+ WorkItem :: ThinLto ( m) => desc ( "lto" , "thin-LTO module" , m. name ( ) ) ,
796803 }
797804 }
798805}
@@ -996,12 +1003,21 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>(
9961003 } )
9971004}
9981005
999- fn execute_lto_work_item < B : ExtraBackendMethods > (
1006+ fn execute_fat_lto_work_item < B : ExtraBackendMethods > (
1007+ cgcx : & CodegenContext < B > ,
1008+ mut module : ModuleCodegen < B :: Module > ,
1009+ module_config : & ModuleConfig ,
1010+ ) -> Result < WorkItemResult < B > , FatalError > {
1011+ B :: optimize_fat ( cgcx, & mut module) ?;
1012+ finish_intra_module_work ( cgcx, module, module_config)
1013+ }
1014+
1015+ fn execute_thin_lto_work_item < B : ExtraBackendMethods > (
10001016 cgcx : & CodegenContext < B > ,
1001- module : lto:: LtoModuleCodegen < B > ,
1017+ module : lto:: ThinModule < B > ,
10021018 module_config : & ModuleConfig ,
10031019) -> Result < WorkItemResult < B > , FatalError > {
1004- let module = module . optimize ( cgcx) ?;
1020+ let module = B :: optimize_thin ( cgcx, module ) ?;
10051021 finish_intra_module_work ( cgcx, module, module_config)
10061022}
10071023
@@ -1842,10 +1858,16 @@ fn spawn_work<'a, B: ExtraBackendMethods>(
18421858 ) ;
18431859 Ok ( execute_copy_from_cache_work_item ( & cgcx, m, module_config) )
18441860 }
1845- WorkItem :: LTO ( m) => {
1861+ WorkItem :: FatLto ( m) => {
1862+ let _timer = cgcx
1863+ . prof
1864+ . generic_activity_with_arg ( "codegen_module_perform_lto" , "everything" ) ;
1865+ execute_fat_lto_work_item ( & cgcx, m, module_config)
1866+ }
1867+ WorkItem :: ThinLto ( m) => {
18461868 let _timer =
18471869 cgcx. prof . generic_activity_with_arg ( "codegen_module_perform_lto" , m. name ( ) ) ;
1848- execute_lto_work_item ( & cgcx, m, module_config)
1870+ execute_thin_lto_work_item ( & cgcx, m, module_config)
18491871 }
18501872 } )
18511873 } ;
0 commit comments