diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2023-07-21 09:22:32 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2023-07-31 16:21:02 +1000 |
| commit | d21d31cce7675f9b454022827a304919ceb5e9f0 (patch) | |
| tree | 01504650a1d5ab2c7b0b36c05fbc145b51157696 /compiler/rustc_codegen_ssa/src | |
| parent | 3517fe899e200a2904cd0a931a7afa4b9f6fd35b (diff) | |
| download | rust-d21d31cce7675f9b454022827a304919ceb5e9f0.tar.gz rust-d21d31cce7675f9b454022827a304919ceb5e9f0.zip | |
Move `maybe_start_llvm_timer`'s body into `spawn_work`.
The two functions are alway called together. This commit factors out the repeated code.
Diffstat (limited to 'compiler/rustc_codegen_ssa/src')
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/back/write.rs | 44 |
1 files changed, 18 insertions, 26 deletions
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<B: ExtraBackendMethods>( // `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<VerboseTimingGuard<'_>> = None; // Run the message loop while there's still anything that needs message @@ -1352,13 +1351,13 @@ fn start_executing_work<B: ExtraBackendMethods>( // 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()), + main_thread_state = MainThreadState::Lending; + spawn_work( + &cgcx, &mut llvm_start_time, + get_worker_id(&mut free_worker_ids), + item, ); - main_thread_state = MainThreadState::Lending; - spawn_work(&cgcx, get_worker_id(&mut free_worker_ids), item); } } } else if codegen_state == Completed { @@ -1397,13 +1396,13 @@ fn start_executing_work<B: ExtraBackendMethods>( match main_thread_state { MainThreadState::Idle => { if let Some((item, _)) = work_items.pop() { - maybe_start_llvm_timer( - prof, - cgcx.config(item.module_kind()), + main_thread_state = MainThreadState::Lending; + spawn_work( + &cgcx, &mut llvm_start_time, + get_worker_id(&mut free_worker_ids), + item, ); - main_thread_state = MainThreadState::Lending; - spawn_work(&cgcx, 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<B: ExtraBackendMethods>( && 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<B: ExtraBackendMethods>( 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<VerboseTimingGuard<'a>>, - ) { - 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<B: ExtraBackendMethods>( - cgcx: &CodegenContext<B>, +fn spawn_work<'a, B: ExtraBackendMethods>( + cgcx: &'a CodegenContext<B>, + llvm_start_time: &mut Option<VerboseTimingGuard<'a>>, worker_id: usize, work: WorkItem<B>, ) { + 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 || { |
