@@ -681,33 +681,6 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
681681
682682 let ongoing_codegen = start_async_codegen ( backend. clone ( ) , tcx, target_cpu, autodiff_items) ;
683683
684- // Codegen an allocator shim, if necessary.
685- if let Some ( kind) = allocator_kind_for_codegen ( tcx) {
686- let llmod_id =
687- cgu_name_builder. build_cgu_name ( LOCAL_CRATE , & [ "crate" ] , Some ( "allocator" ) ) . to_string ( ) ;
688- let module_llvm = tcx. sess . time ( "write_allocator_module" , || {
689- backend. codegen_allocator (
690- tcx,
691- & llmod_id,
692- kind,
693- // If allocator_kind is Some then alloc_error_handler_kind must
694- // also be Some.
695- tcx. alloc_error_handler_kind ( ( ) ) . unwrap ( ) ,
696- )
697- } ) ;
698-
699- ongoing_codegen. wait_for_signal_to_codegen_item ( ) ;
700- ongoing_codegen. check_for_errors ( tcx. sess ) ;
701-
702- // These modules are generally cheap and won't throw off scheduling.
703- let cost = 0 ;
704- submit_codegened_module_to_llvm (
705- & ongoing_codegen. coordinator ,
706- ModuleCodegen :: new_allocator ( llmod_id, module_llvm) ,
707- cost,
708- ) ;
709- }
710-
711684 // For better throughput during parallel processing by LLVM, we used to sort
712685 // CGUs largest to smallest. This would lead to better thread utilization
713686 // by, for example, preventing a large CGU from being processed last and
@@ -823,6 +796,35 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
823796 }
824797 }
825798
799+ // Codegen an allocator shim, if necessary.
800+ // Do this last to ensure the LLVM_passes timer doesn't start while no CGUs have been codegened
801+ // yet for the backend to optimize.
802+ if let Some ( kind) = allocator_kind_for_codegen ( tcx) {
803+ let llmod_id =
804+ cgu_name_builder. build_cgu_name ( LOCAL_CRATE , & [ "crate" ] , Some ( "allocator" ) ) . to_string ( ) ;
805+ let module_llvm = tcx. sess . time ( "write_allocator_module" , || {
806+ backend. codegen_allocator (
807+ tcx,
808+ & llmod_id,
809+ kind,
810+ // If allocator_kind is Some then alloc_error_handler_kind must
811+ // also be Some.
812+ tcx. alloc_error_handler_kind ( ( ) ) . unwrap ( ) ,
813+ )
814+ } ) ;
815+
816+ ongoing_codegen. wait_for_signal_to_codegen_item ( ) ;
817+ ongoing_codegen. check_for_errors ( tcx. sess ) ;
818+
819+ // These modules are generally cheap and won't throw off scheduling.
820+ let cost = 0 ;
821+ submit_codegened_module_to_llvm (
822+ & ongoing_codegen. coordinator ,
823+ ModuleCodegen :: new_allocator ( llmod_id, module_llvm) ,
824+ cost,
825+ ) ;
826+ }
827+
826828 ongoing_codegen. codegen_finished ( tcx) ;
827829
828830 // Since the main thread is sometimes blocked during codegen, we keep track
0 commit comments