@@ -397,52 +397,50 @@ impl<B: WriteBackendMethods> CodegenContext<B> {
397397 }
398398}
399399
400- fn generate_lto_work < B : ExtraBackendMethods > (
400+ fn generate_fat_lto_work < B : ExtraBackendMethods > (
401401 cgcx : & CodegenContext < B > ,
402402 autodiff : Vec < AutoDiffItem > ,
403403 needs_fat_lto : Vec < FatLtoInput < B > > ,
404- needs_thin_lto : Vec < ( String , B :: ThinBuffer ) > ,
405404 import_only_modules : Vec < ( SerializedModule < B :: ModuleBuffer > , WorkProduct ) > ,
406- ) -> Vec < ( WorkItem < B > , u64 ) > {
405+ ) -> WorkItem < B > {
407406 let _prof_timer = cgcx. prof . generic_activity ( "codegen_generate_lto_work" ) ;
408407
409- if !needs_fat_lto. is_empty ( ) {
410- assert ! ( needs_thin_lto. is_empty( ) ) ;
411- let module =
412- B :: run_fat_lto ( cgcx, needs_fat_lto, import_only_modules) . unwrap_or_else ( |e| e. raise ( ) ) ;
413- if cgcx. lto == Lto :: Fat && !autodiff. is_empty ( ) {
414- let config = cgcx. config ( ModuleKind :: Regular ) ;
415- if let Err ( err) = B :: autodiff ( cgcx, & module, autodiff, config) {
416- err. raise ( ) ;
417- }
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 ( ) ;
418414 }
419- // We are adding a single work item, so the cost doesn't matter.
420- vec ! [ ( WorkItem :: FatLto ( module) , 0 ) ]
421- } else {
422- if !autodiff. is_empty ( ) {
423- let dcx = cgcx. create_dcx ( ) ;
424- dcx. handle ( ) . emit_fatal ( AutodiffWithoutLto { } ) ;
425- }
426- assert ! ( needs_fat_lto. is_empty( ) ) ;
427- let ( lto_modules, copy_jobs) = B :: run_thin_lto ( cgcx, needs_thin_lto, import_only_modules)
428- . unwrap_or_else ( |e| e. raise ( ) ) ;
429- lto_modules
430- . into_iter ( )
431- . map ( |module| {
432- let cost = module. cost ( ) ;
433- ( WorkItem :: ThinLto ( module) , cost)
434- } )
435- . chain ( copy_jobs. into_iter ( ) . map ( |wp| {
436- (
437- WorkItem :: CopyPostLtoArtifacts ( CachedModuleCodegen {
438- name : wp. cgu_name . clone ( ) ,
439- source : wp,
440- } ) ,
441- 0 , // copying is very cheap
442- )
443- } ) )
444- . collect ( )
445415 }
416+ WorkItem :: FatLto ( module)
417+ }
418+
419+ fn generate_thin_lto_work < B : ExtraBackendMethods > (
420+ cgcx : & CodegenContext < B > ,
421+ needs_thin_lto : Vec < ( String , B :: ThinBuffer ) > ,
422+ import_only_modules : Vec < ( SerializedModule < B :: ModuleBuffer > , WorkProduct ) > ,
423+ ) -> Vec < ( WorkItem < B > , u64 ) > {
424+ let _prof_timer = cgcx. prof . generic_activity ( "codegen_thin_generate_lto_work" ) ;
425+
426+ let ( lto_modules, copy_jobs) =
427+ B :: run_thin_lto ( cgcx, needs_thin_lto, import_only_modules) . unwrap_or_else ( |e| e. raise ( ) ) ;
428+ lto_modules
429+ . into_iter ( )
430+ . map ( |module| {
431+ let cost = module. cost ( ) ;
432+ ( WorkItem :: ThinLto ( module) , cost)
433+ } )
434+ . chain ( copy_jobs. into_iter ( ) . map ( |wp| {
435+ (
436+ WorkItem :: CopyPostLtoArtifacts ( CachedModuleCodegen {
437+ name : wp. cgu_name . clone ( ) ,
438+ source : wp,
439+ } ) ,
440+ 0 , // copying is very cheap
441+ )
442+ } ) )
443+ . collect ( )
446444}
447445
448446struct CompiledModules {
@@ -1489,20 +1487,36 @@ fn start_executing_work<B: ExtraBackendMethods>(
14891487 let needs_thin_lto = mem:: take ( & mut needs_thin_lto) ;
14901488 let import_only_modules = mem:: take ( & mut lto_import_only_modules) ;
14911489
1492- for ( work, cost) in generate_lto_work (
1493- & cgcx,
1494- autodiff_items. clone ( ) ,
1495- needs_fat_lto,
1496- needs_thin_lto,
1497- import_only_modules,
1498- ) {
1499- let insertion_index = work_items
1500- . binary_search_by_key ( & cost, |& ( _, cost) | cost)
1501- . unwrap_or_else ( |e| e) ;
1502- work_items. insert ( insertion_index, ( work, cost) ) ;
1490+ if !needs_fat_lto. is_empty ( ) {
1491+ assert ! ( needs_thin_lto. is_empty( ) ) ;
1492+
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 ) ) ;
15031500 if cgcx. parallel {
15041501 helper. request_token ( ) ;
15051502 }
1503+ } else {
1504+ if !autodiff_items. is_empty ( ) {
1505+ let dcx = cgcx. create_dcx ( ) ;
1506+ dcx. handle ( ) . emit_fatal ( AutodiffWithoutLto { } ) ;
1507+ }
1508+
1509+ for ( work, cost) in
1510+ generate_thin_lto_work ( & cgcx, needs_thin_lto, import_only_modules)
1511+ {
1512+ let insertion_index = work_items
1513+ . binary_search_by_key ( & cost, |& ( _, cost) | cost)
1514+ . unwrap_or_else ( |e| e) ;
1515+ work_items. insert ( insertion_index, ( work, cost) ) ;
1516+ if cgcx. parallel {
1517+ helper. request_token ( ) ;
1518+ }
1519+ }
15061520 }
15071521 }
15081522
0 commit comments