diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index ef10b5c21d5..d42d5fe0be2 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -1306,7 +1306,6 @@ fn start_executing_work( // `running + if main_thread_state == Lending { 1 } else { 0 }`. let mut running_with_own_token = 0; - let prof = &cgcx.prof; let mut llvm_start_time: Option> = None; // Run the message loop while there's still anything that needs message @@ -1352,13 +1351,13 @@ fn start_executing_work( // LLVM work too. let (item, _) = work_items.pop().expect("queue empty - queue_full_enough() broken?"); - maybe_start_llvm_timer( - prof, - cgcx.config(item.module_kind()), - &mut llvm_start_time, - ); main_thread_state = MainThreadState::Lending; - spawn_work(&cgcx, get_worker_id(&mut free_worker_ids), item); + spawn_work( + &cgcx, + &mut llvm_start_time, + get_worker_id(&mut free_worker_ids), + item, + ); } } } else if codegen_state == Completed { @@ -1397,13 +1396,13 @@ fn start_executing_work( match main_thread_state { MainThreadState::Idle => { if let Some((item, _)) = work_items.pop() { - maybe_start_llvm_timer( - prof, - cgcx.config(item.module_kind()), - &mut llvm_start_time, - ); main_thread_state = MainThreadState::Lending; - spawn_work(&cgcx, get_worker_id(&mut free_worker_ids), item); + spawn_work( + &cgcx, + &mut llvm_start_time, + get_worker_id(&mut free_worker_ids), + item, + ); } else { // There is no unstarted work, so let the main thread // take over for a running worker. Otherwise the @@ -1437,9 +1436,7 @@ fn start_executing_work( && running_with_own_token < tokens.len() { let (item, _) = work_items.pop().unwrap(); - - maybe_start_llvm_timer(prof, cgcx.config(item.module_kind()), &mut llvm_start_time); - spawn_work(&cgcx, get_worker_id(&mut free_worker_ids), item); + spawn_work(&cgcx, &mut llvm_start_time, get_worker_id(&mut free_worker_ids), item); running_with_own_token += 1; } @@ -1669,27 +1666,22 @@ fn start_executing_work( let quarter_of_workers = workers_running - 3 * workers_running / 4; items_in_queue > 0 && items_in_queue >= quarter_of_workers } - - fn maybe_start_llvm_timer<'a>( - prof: &'a SelfProfilerRef, - config: &ModuleConfig, - llvm_start_time: &mut Option>, - ) { - if config.time_module && llvm_start_time.is_none() { - *llvm_start_time = Some(prof.verbose_generic_activity("LLVM_passes")); - } - } } /// `FatalError` is explicitly not `Send`. #[must_use] pub struct WorkerFatalError; -fn spawn_work( - cgcx: &CodegenContext, +fn spawn_work<'a, B: ExtraBackendMethods>( + cgcx: &'a CodegenContext, + llvm_start_time: &mut Option>, worker_id: usize, work: WorkItem, ) { + if cgcx.config(work.module_kind()).time_module && llvm_start_time.is_none() { + *llvm_start_time = Some(cgcx.prof.verbose_generic_activity("LLVM_passes")); + } + let cgcx = cgcx.clone(); B::spawn_named_thread(cgcx.time_trace, work.short_description(), move || {