Skip to content

Commit d21d31c

Browse files
committed
Move maybe_start_llvm_timer's body into spawn_work.
The two functions are alway called together. This commit factors out the repeated code.
1 parent 3517fe8 commit d21d31c

File tree

1 file changed

+18
-26
lines changed
  • compiler/rustc_codegen_ssa/src/back

1 file changed

+18
-26
lines changed

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,6 @@ fn start_executing_work<B: ExtraBackendMethods>(
13061306
// `running + if main_thread_state == Lending { 1 } else { 0 }`.
13071307
let mut running_with_own_token = 0;
13081308

1309-
let prof = &cgcx.prof;
13101309
let mut llvm_start_time: Option<VerboseTimingGuard<'_>> = None;
13111310

13121311
// Run the message loop while there's still anything that needs message
@@ -1352,13 +1351,13 @@ fn start_executing_work<B: ExtraBackendMethods>(
13521351
// LLVM work too.
13531352
let (item, _) =
13541353
work_items.pop().expect("queue empty - queue_full_enough() broken?");
1355-
maybe_start_llvm_timer(
1356-
prof,
1357-
cgcx.config(item.module_kind()),
1354+
main_thread_state = MainThreadState::Lending;
1355+
spawn_work(
1356+
&cgcx,
13581357
&mut llvm_start_time,
1358+
get_worker_id(&mut free_worker_ids),
1359+
item,
13591360
);
1360-
main_thread_state = MainThreadState::Lending;
1361-
spawn_work(&cgcx, get_worker_id(&mut free_worker_ids), item);
13621361
}
13631362
}
13641363
} else if codegen_state == Completed {
@@ -1397,13 +1396,13 @@ fn start_executing_work<B: ExtraBackendMethods>(
13971396
match main_thread_state {
13981397
MainThreadState::Idle => {
13991398
if let Some((item, _)) = work_items.pop() {
1400-
maybe_start_llvm_timer(
1401-
prof,
1402-
cgcx.config(item.module_kind()),
1399+
main_thread_state = MainThreadState::Lending;
1400+
spawn_work(
1401+
&cgcx,
14031402
&mut llvm_start_time,
1403+
get_worker_id(&mut free_worker_ids),
1404+
item,
14041405
);
1405-
main_thread_state = MainThreadState::Lending;
1406-
spawn_work(&cgcx, get_worker_id(&mut free_worker_ids), item);
14071406
} else {
14081407
// There is no unstarted work, so let the main thread
14091408
// take over for a running worker. Otherwise the
@@ -1437,9 +1436,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
14371436
&& running_with_own_token < tokens.len()
14381437
{
14391438
let (item, _) = work_items.pop().unwrap();
1440-
1441-
maybe_start_llvm_timer(prof, cgcx.config(item.module_kind()), &mut llvm_start_time);
1442-
spawn_work(&cgcx, get_worker_id(&mut free_worker_ids), item);
1439+
spawn_work(&cgcx, &mut llvm_start_time, get_worker_id(&mut free_worker_ids), item);
14431440
running_with_own_token += 1;
14441441
}
14451442

@@ -1669,27 +1666,22 @@ fn start_executing_work<B: ExtraBackendMethods>(
16691666
let quarter_of_workers = workers_running - 3 * workers_running / 4;
16701667
items_in_queue > 0 && items_in_queue >= quarter_of_workers
16711668
}
1672-
1673-
fn maybe_start_llvm_timer<'a>(
1674-
prof: &'a SelfProfilerRef,
1675-
config: &ModuleConfig,
1676-
llvm_start_time: &mut Option<VerboseTimingGuard<'a>>,
1677-
) {
1678-
if config.time_module && llvm_start_time.is_none() {
1679-
*llvm_start_time = Some(prof.verbose_generic_activity("LLVM_passes"));
1680-
}
1681-
}
16821669
}
16831670

16841671
/// `FatalError` is explicitly not `Send`.
16851672
#[must_use]
16861673
pub struct WorkerFatalError;
16871674

1688-
fn spawn_work<B: ExtraBackendMethods>(
1689-
cgcx: &CodegenContext<B>,
1675+
fn spawn_work<'a, B: ExtraBackendMethods>(
1676+
cgcx: &'a CodegenContext<B>,
1677+
llvm_start_time: &mut Option<VerboseTimingGuard<'a>>,
16901678
worker_id: usize,
16911679
work: WorkItem<B>,
16921680
) {
1681+
if cgcx.config(work.module_kind()).time_module && llvm_start_time.is_none() {
1682+
*llvm_start_time = Some(cgcx.prof.verbose_generic_activity("LLVM_passes"));
1683+
}
1684+
16931685
let cgcx = cgcx.clone();
16941686

16951687
B::spawn_named_thread(cgcx.time_trace, work.short_description(), move || {

0 commit comments

Comments
 (0)