diff --git a/compiler/rustc_codegen_gcc/src/lib.rs b/compiler/rustc_codegen_gcc/src/lib.rs index ed809eb33a53..592eb68ce275 100644 --- a/compiler/rustc_codegen_gcc/src/lib.rs +++ b/compiler/rustc_codegen_gcc/src/lib.rs @@ -371,16 +371,6 @@ fn compile_codegen_unit( self.lto_supported.load(Ordering::SeqCst), ) } - - fn target_machine_factory( - &self, - _sess: &Session, - _opt_level: OptLevel, - _features: &[String], - ) -> TargetMachineFactoryFn { - // TODO(antoyo): set opt level. - Arc::new(|_, _| ()) - } } #[derive(Clone, Copy, PartialEq)] @@ -429,6 +419,16 @@ impl WriteBackendMethods for GccCodegenBackend { type ModuleBuffer = ModuleBuffer; type ThinData = (); + fn target_machine_factory( + &self, + _sess: &Session, + _opt_level: OptLevel, + _features: &[String], + ) -> TargetMachineFactoryFn { + // TODO(antoyo): set opt level. + Arc::new(|_, _| ()) + } + fn optimize_and_codegen_fat_lto( cgcx: &CodegenContext, prof: &SelfProfilerRef, diff --git a/compiler/rustc_codegen_llvm/src/lib.rs b/compiler/rustc_codegen_llvm/src/lib.rs index cda1e470fce4..62bba6c9bfc2 100644 --- a/compiler/rustc_codegen_llvm/src/lib.rs +++ b/compiler/rustc_codegen_llvm/src/lib.rs @@ -116,6 +116,16 @@ fn compile_codegen_unit( ) -> (ModuleCodegen, u64) { base::compile_codegen_unit(tcx, cgu_name) } +} + +impl WriteBackendMethods for LlvmCodegenBackend { + type Module = ModuleLlvm; + type ModuleBuffer = back::lto::ModuleBuffer; + type TargetMachine = OwnedTargetMachine; + type ThinData = back::lto::ThinData; + fn thread_profiler() -> Box { + Box::new(TimeTraceProfiler::new()) + } fn target_machine_factory( &self, sess: &Session, @@ -124,17 +134,6 @@ fn target_machine_factory( ) -> TargetMachineFactoryFn { back::write::target_machine_factory(sess, optlvl, target_features) } - - fn thread_profiler() -> Box { - Box::new(TimeTraceProfiler::new()) - } -} - -impl WriteBackendMethods for LlvmCodegenBackend { - type Module = ModuleLlvm; - type ModuleBuffer = back::lto::ModuleBuffer; - type TargetMachine = OwnedTargetMachine; - type ThinData = back::lto::ThinData; fn optimize_and_codegen_fat_lto( cgcx: &CodegenContext, prof: &SelfProfilerRef, diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index 31a77952ea38..3734e273e0b5 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -354,7 +354,7 @@ pub struct CodegenContext { pub parallel: bool, } -fn generate_thin_lto_work( +fn generate_thin_lto_work( cgcx: &CodegenContext, prof: &SelfProfilerRef, dcx: DiagCtxtHandle<'_>, @@ -822,7 +822,7 @@ pub(crate) fn compute_per_cgu_lto_type( } } -fn execute_optimize_work_item( +fn execute_optimize_work_item( cgcx: &CodegenContext, prof: &SelfProfilerRef, shared_emitter: SharedEmitter, @@ -967,7 +967,7 @@ fn execute_copy_from_cache_work_item( } } -fn do_fat_lto( +fn do_fat_lto( cgcx: &CodegenContext, prof: &SelfProfilerRef, shared_emitter: SharedEmitter, @@ -999,7 +999,7 @@ fn do_fat_lto( ) } -fn do_thin_lto( +fn do_thin_lto( cgcx: &CodegenContext, prof: &SelfProfilerRef, shared_emitter: SharedEmitter, @@ -1152,7 +1152,7 @@ fn do_thin_lto( compiled_modules } -fn execute_thin_lto_work_item( +fn execute_thin_lto_work_item( cgcx: &CodegenContext, prof: &SelfProfilerRef, shared_emitter: SharedEmitter, @@ -1879,7 +1879,7 @@ fn queue_full_enough(items_in_queue: usize, workers_running: usize) -> bool { #[must_use] pub(crate) struct WorkerFatalError; -fn spawn_work<'a, B: ExtraBackendMethods>( +fn spawn_work<'a, B: WriteBackendMethods>( cgcx: &CodegenContext, prof: &'a SelfProfilerRef, shared_emitter: SharedEmitter, @@ -1922,7 +1922,7 @@ fn spawn_work<'a, B: ExtraBackendMethods>( std::thread::Builder::new().name(name).spawn(f).expect("failed to spawn work thread"); } -fn spawn_thin_lto_work( +fn spawn_thin_lto_work( cgcx: &CodegenContext, prof: &SelfProfilerRef, shared_emitter: SharedEmitter, @@ -2109,20 +2109,20 @@ fn check(&self, sess: &Session, blocking: bool) { } } -pub struct Coordinator { +pub struct Coordinator { sender: Sender>, future: Option, ()>>>, // Only used for the Message type. phantom: PhantomData, } -impl Coordinator { +impl Coordinator { fn join(mut self) -> std::thread::Result, ()>> { self.future.take().unwrap().join() } } -impl Drop for Coordinator { +impl Drop for Coordinator { fn drop(&mut self) { if let Some(future) = self.future.take() { // If we haven't joined yet, signal to the coordinator that it should spawn no more @@ -2133,7 +2133,7 @@ fn drop(&mut self) { } } -pub struct OngoingCodegen { +pub struct OngoingCodegen { pub backend: B, pub output_filenames: Arc, // Field order below is intended to terminate the coordinator thread before two fields below @@ -2144,7 +2144,7 @@ pub struct OngoingCodegen { pub shared_emitter_main: SharedEmitterMain, } -impl OngoingCodegen { +impl OngoingCodegen { pub fn join(self, sess: &Session) -> (CompiledModules, FxIndexMap) { self.shared_emitter_main.check(sess, true); @@ -2267,7 +2267,7 @@ pub(crate) fn wait_for_signal_to_codegen_item(&self) { } } -pub(crate) fn submit_codegened_module_to_llvm( +pub(crate) fn submit_codegened_module_to_llvm( coordinator: &Coordinator, module: ModuleCodegen, cost: u64, @@ -2276,7 +2276,7 @@ pub(crate) fn submit_codegened_module_to_llvm( drop(coordinator.sender.send(Message::CodegenDone:: { llvm_work_item, cost })); } -pub(crate) fn submit_post_lto_module_to_llvm( +pub(crate) fn submit_post_lto_module_to_llvm( coordinator: &Coordinator, module: CachedModuleCodegen, ) { @@ -2284,7 +2284,7 @@ pub(crate) fn submit_post_lto_module_to_llvm( drop(coordinator.sender.send(Message::CodegenDone:: { llvm_work_item, cost: 0 })); } -pub(crate) fn submit_pre_lto_module_to_llvm( +pub(crate) fn submit_pre_lto_module_to_llvm( tcx: TyCtxt<'_>, coordinator: &Coordinator, module: CachedModuleCodegen, diff --git a/compiler/rustc_codegen_ssa/src/traits/backend.rs b/compiler/rustc_codegen_ssa/src/traits/backend.rs index 5b0275b0d1df..7b95562ddda3 100644 --- a/compiler/rustc_codegen_ssa/src/traits/backend.rs +++ b/compiler/rustc_codegen_ssa/src/traits/backend.rs @@ -10,14 +10,13 @@ use rustc_middle::ty::TyCtxt; use rustc_middle::util::Providers; use rustc_session::Session; -use rustc_session::config::{self, CrateType, OutputFilenames, PrintRequest}; +use rustc_session::config::{CrateType, OutputFilenames, PrintRequest}; use rustc_span::Symbol; use super::CodegenObject; use super::write::WriteBackendMethods; use crate::back::archive::ArArchiveBuilderBuilder; use crate::back::link::link_binary; -use crate::back::write::TargetMachineFactoryFn; use crate::{CompiledModules, CrateInfo, ModuleCodegen, TargetConfig}; pub trait BackendTypes { @@ -162,17 +161,6 @@ fn compile_codegen_unit( cgu_name: Symbol, ) -> (ModuleCodegen, u64); - fn target_machine_factory( - &self, - sess: &Session, - opt_level: config::OptLevel, - target_features: &[String], - ) -> TargetMachineFactoryFn; - - fn thread_profiler() -> Box { - Box::new(()) - } - /// Returns `true` if this backend can be safely called from multiple threads. /// /// Defaults to `true`. diff --git a/compiler/rustc_codegen_ssa/src/traits/write.rs b/compiler/rustc_codegen_ssa/src/traits/write.rs index d218b0f31722..5d2313092fa8 100644 --- a/compiler/rustc_codegen_ssa/src/traits/write.rs +++ b/compiler/rustc_codegen_ssa/src/traits/write.rs @@ -1,8 +1,10 @@ +use std::any::Any; use std::path::PathBuf; use rustc_data_structures::profiling::SelfProfilerRef; use rustc_errors::DiagCtxtHandle; use rustc_middle::dep_graph::WorkProduct; +use rustc_session::{Session, config}; use crate::back::lto::{SerializedModule, ThinModule}; use crate::back::write::{ @@ -16,6 +18,15 @@ pub trait WriteBackendMethods: Clone + 'static { type ModuleBuffer: ModuleBufferMethods; type ThinData: Send + Sync; + fn thread_profiler() -> Box { + Box::new(()) + } + fn target_machine_factory( + &self, + sess: &Session, + opt_level: config::OptLevel, + target_features: &[String], + ) -> TargetMachineFactoryFn; /// Performs fat LTO by merging all modules into a single one, running autodiff /// if necessary and running any further optimizations fn optimize_and_codegen_fat_lto(