File tree 2 files changed +15
-2
lines changed
compiler/rustc_codegen_ssa/src
2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -383,6 +383,12 @@ impl<B: WriteBackendMethods> CodegenContext<B> {
383
383
}
384
384
}
385
385
386
+ impl < B : CodegenBackend + WriteBackendMethods > CodegenContext < B > {
387
+ pub fn parallel ( & self ) -> bool {
388
+ self . backend . supports_parallel ( ) && !self . opts . unstable_opts . no_parallel_llvm
389
+ }
390
+ }
391
+
386
392
fn generate_lto_work < B : ExtraBackendMethods > (
387
393
cgcx : & CodegenContext < B > ,
388
394
needs_fat_lto : Vec < FatLtoInput < B > > ,
@@ -1400,7 +1406,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
1400
1406
. binary_search_by_key ( & cost, |& ( _, cost) | cost)
1401
1407
. unwrap_or_else ( |e| e) ;
1402
1408
work_items. insert ( insertion_index, ( work, cost) ) ;
1403
- if ! cgcx. opts . unstable_opts . no_parallel_llvm {
1409
+ if cgcx. parallel ( ) {
1404
1410
helper. request_token ( ) ;
1405
1411
}
1406
1412
}
@@ -1523,7 +1529,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
1523
1529
} ;
1524
1530
work_items. insert ( insertion_index, ( llvm_work_item, cost) ) ;
1525
1531
1526
- if ! cgcx. opts . unstable_opts . no_parallel_llvm {
1532
+ if cgcx. parallel ( ) {
1527
1533
helper. request_token ( ) ;
1528
1534
}
1529
1535
assert_eq ! ( main_thread_state, MainThreadState :: Codegenning ) ;
Original file line number Diff line number Diff line change @@ -115,6 +115,13 @@ pub trait CodegenBackend {
115
115
codegen_results : CodegenResults ,
116
116
outputs : & OutputFilenames ,
117
117
) -> Result < ( ) , ErrorGuaranteed > ;
118
+
119
+ /// Returns `true` if this backend can be safely called from multiple threads.
120
+ ///
121
+ /// Defaults to `true`.
122
+ fn supports_parallel ( & self ) -> bool {
123
+ true
124
+ }
118
125
}
119
126
120
127
pub trait ExtraBackendMethods :
You can’t perform that action at this time.
0 commit comments