diff options
| author | Jubilee <46493976+workingjubilee@users.noreply.github.com> | 2024-03-11 09:29:31 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-11 09:29:31 -0700 |
| commit | 88d387b26380e48384610d530aa275a573790797 (patch) | |
| tree | 98e28ab8ee04001fd52f65766550daec31f824f1 /compiler/rustc_codegen_ssa/src | |
| parent | d255c6a57c393db6221b1ff700daea478436f1cd (diff) | |
| parent | f368922cfa58d2ebc98b6153e62bcb65e27fcf67 (diff) | |
Rollup merge of #116791 - WaffleLapkin:unparallel-backends, r=oli-obk
Allow codegen backends to opt-out of parallel codegen This makes it a bit easier to write cursed codegen backends.
Diffstat (limited to 'compiler/rustc_codegen_ssa/src')
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/back/write.rs | 9 | ||||
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/traits/backend.rs | 7 |
2 files changed, 14 insertions, 2 deletions
diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index bbb04652119..4eda4c2f08c 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -374,6 +374,10 @@ pub struct CodegenContext<B: WriteBackendMethods> { pub incr_comp_session_dir: Option<PathBuf>, /// Channel back to the main control thread to send messages to pub coordinator_send: Sender<Box<dyn Any + Send>>, + /// `true` if the codegen should be run in parallel. + /// + /// Depends on [`CodegenBackend::supports_parallel()`] and `-Zno_parallel_backend`. + pub parallel: bool, } impl<B: WriteBackendMethods> CodegenContext<B> { @@ -1152,6 +1156,7 @@ fn start_executing_work<B: ExtraBackendMethods>( target_arch: tcx.sess.target.arch.to_string(), split_debuginfo: tcx.sess.split_debuginfo(), split_dwarf_kind: tcx.sess.opts.unstable_opts.split_dwarf_kind, + parallel: backend.supports_parallel() && !sess.opts.unstable_opts.no_parallel_backend, }; // This is the "main loop" of parallel work happening for parallel codegen. @@ -1422,7 +1427,7 @@ fn start_executing_work<B: ExtraBackendMethods>( .binary_search_by_key(&cost, |&(_, cost)| cost) .unwrap_or_else(|e| e); work_items.insert(insertion_index, (work, cost)); - if !cgcx.opts.unstable_opts.no_parallel_llvm { + if cgcx.parallel { helper.request_token(); } } @@ -1545,7 +1550,7 @@ fn start_executing_work<B: ExtraBackendMethods>( }; work_items.insert(insertion_index, (llvm_work_item, cost)); - if !cgcx.opts.unstable_opts.no_parallel_llvm { + if cgcx.parallel { helper.request_token(); } assert_eq!(main_thread_state, MainThreadState::Codegenning); diff --git a/compiler/rustc_codegen_ssa/src/traits/backend.rs b/compiler/rustc_codegen_ssa/src/traits/backend.rs index cb1feff1336..e6d42c596d2 100644 --- a/compiler/rustc_codegen_ssa/src/traits/backend.rs +++ b/compiler/rustc_codegen_ssa/src/traits/backend.rs @@ -111,6 +111,13 @@ pub trait CodegenBackend { codegen_results: CodegenResults, outputs: &OutputFilenames, ) -> Result<(), ErrorGuaranteed>; + + /// Returns `true` if this backend can be safely called from multiple threads. + /// + /// Defaults to `true`. + fn supports_parallel(&self) -> bool { + true + } } pub trait ExtraBackendMethods: |
