Skip to content

Commit 2bfa330

Browse files
committed
Move some methods to WriteBackendMethods
1 parent bf865e1 commit 2bfa330

File tree

5 files changed

+47
-49
lines changed

5 files changed

+47
-49
lines changed

compiler/rustc_codegen_gcc/src/lib.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -369,16 +369,6 @@ impl ExtraBackendMethods for GccCodegenBackend {
369369
self.lto_supported.load(Ordering::SeqCst),
370370
)
371371
}
372-
373-
fn target_machine_factory(
374-
&self,
375-
_sess: &Session,
376-
_opt_level: OptLevel,
377-
_features: &[String],
378-
) -> TargetMachineFactoryFn<Self> {
379-
// TODO(antoyo): set opt level.
380-
Arc::new(|_, _| ())
381-
}
382372
}
383373

384374
#[derive(Clone, Copy, PartialEq)]
@@ -427,6 +417,16 @@ impl WriteBackendMethods for GccCodegenBackend {
427417
type ModuleBuffer = ModuleBuffer;
428418
type ThinData = ();
429419

420+
fn target_machine_factory(
421+
&self,
422+
_sess: &Session,
423+
_opt_level: OptLevel,
424+
_features: &[String],
425+
) -> TargetMachineFactoryFn<Self> {
426+
// TODO(antoyo): set opt level.
427+
Arc::new(|_, _| ())
428+
}
429+
430430
fn optimize_and_codegen_fat_lto(
431431
cgcx: &CodegenContext,
432432
prof: &SelfProfilerRef,

compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,16 @@ impl ExtraBackendMethods for LlvmCodegenBackend {
116116
) -> (ModuleCodegen<ModuleLlvm>, u64) {
117117
base::compile_codegen_unit(tcx, cgu_name)
118118
}
119+
}
120+
121+
impl WriteBackendMethods for LlvmCodegenBackend {
122+
type Module = ModuleLlvm;
123+
type ModuleBuffer = back::lto::ModuleBuffer;
124+
type TargetMachine = OwnedTargetMachine;
125+
type ThinData = back::lto::ThinData;
126+
fn thread_profiler() -> Box<dyn Any> {
127+
Box::new(TimeTraceProfiler::new())
128+
}
119129
fn target_machine_factory(
120130
&self,
121131
sess: &Session,
@@ -124,17 +134,6 @@ impl ExtraBackendMethods for LlvmCodegenBackend {
124134
) -> TargetMachineFactoryFn<Self> {
125135
back::write::target_machine_factory(sess, optlvl, target_features)
126136
}
127-
128-
fn thread_profiler() -> Box<dyn Any> {
129-
Box::new(TimeTraceProfiler::new())
130-
}
131-
}
132-
133-
impl WriteBackendMethods for LlvmCodegenBackend {
134-
type Module = ModuleLlvm;
135-
type ModuleBuffer = back::lto::ModuleBuffer;
136-
type TargetMachine = OwnedTargetMachine;
137-
type ThinData = back::lto::ThinData;
138137
fn optimize_and_codegen_fat_lto(
139138
cgcx: &CodegenContext,
140139
prof: &SelfProfilerRef,

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ pub struct CodegenContext {
354354
pub parallel: bool,
355355
}
356356

357-
fn generate_thin_lto_work<B: ExtraBackendMethods>(
357+
fn generate_thin_lto_work<B: WriteBackendMethods>(
358358
cgcx: &CodegenContext,
359359
prof: &SelfProfilerRef,
360360
dcx: DiagCtxtHandle<'_>,
@@ -833,7 +833,7 @@ pub(crate) fn compute_per_cgu_lto_type(
833833
}
834834
}
835835

836-
fn execute_optimize_work_item<B: ExtraBackendMethods>(
836+
fn execute_optimize_work_item<B: WriteBackendMethods>(
837837
cgcx: &CodegenContext,
838838
prof: &SelfProfilerRef,
839839
shared_emitter: SharedEmitter,
@@ -978,7 +978,7 @@ fn execute_copy_from_cache_work_item(
978978
}
979979
}
980980

981-
fn do_fat_lto<B: ExtraBackendMethods>(
981+
fn do_fat_lto<B: WriteBackendMethods>(
982982
cgcx: &CodegenContext,
983983
prof: &SelfProfilerRef,
984984
shared_emitter: SharedEmitter,
@@ -1010,7 +1010,7 @@ fn do_fat_lto<B: ExtraBackendMethods>(
10101010
)
10111011
}
10121012

1013-
fn do_thin_lto<B: ExtraBackendMethods>(
1013+
fn do_thin_lto<B: WriteBackendMethods>(
10141014
cgcx: &CodegenContext,
10151015
prof: &SelfProfilerRef,
10161016
shared_emitter: SharedEmitter,
@@ -1163,7 +1163,7 @@ fn do_thin_lto<B: ExtraBackendMethods>(
11631163
compiled_modules
11641164
}
11651165

1166-
fn execute_thin_lto_work_item<B: ExtraBackendMethods>(
1166+
fn execute_thin_lto_work_item<B: WriteBackendMethods>(
11671167
cgcx: &CodegenContext,
11681168
prof: &SelfProfilerRef,
11691169
shared_emitter: SharedEmitter,
@@ -1890,7 +1890,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
18901890
#[must_use]
18911891
pub(crate) struct WorkerFatalError;
18921892

1893-
fn spawn_work<'a, B: ExtraBackendMethods>(
1893+
fn spawn_work<'a, B: WriteBackendMethods>(
18941894
cgcx: &CodegenContext,
18951895
prof: &'a SelfProfilerRef,
18961896
shared_emitter: SharedEmitter,
@@ -1933,7 +1933,7 @@ fn spawn_work<'a, B: ExtraBackendMethods>(
19331933
std::thread::Builder::new().name(name).spawn(f).expect("failed to spawn work thread");
19341934
}
19351935

1936-
fn spawn_thin_lto_work<B: ExtraBackendMethods>(
1936+
fn spawn_thin_lto_work<B: WriteBackendMethods>(
19371937
cgcx: &CodegenContext,
19381938
prof: &SelfProfilerRef,
19391939
shared_emitter: SharedEmitter,
@@ -2120,20 +2120,20 @@ impl SharedEmitterMain {
21202120
}
21212121
}
21222122

2123-
pub struct Coordinator<B: ExtraBackendMethods> {
2123+
pub struct Coordinator<B: WriteBackendMethods> {
21242124
sender: Sender<Message<B>>,
21252125
future: Option<thread::JoinHandle<Result<MaybeLtoModules<B>, ()>>>,
21262126
// Only used for the Message type.
21272127
phantom: PhantomData<B>,
21282128
}
21292129

2130-
impl<B: ExtraBackendMethods> Coordinator<B> {
2130+
impl<B: WriteBackendMethods> Coordinator<B> {
21312131
fn join(mut self) -> std::thread::Result<Result<MaybeLtoModules<B>, ()>> {
21322132
self.future.take().unwrap().join()
21332133
}
21342134
}
21352135

2136-
impl<B: ExtraBackendMethods> Drop for Coordinator<B> {
2136+
impl<B: WriteBackendMethods> Drop for Coordinator<B> {
21372137
fn drop(&mut self) {
21382138
if let Some(future) = self.future.take() {
21392139
// If we haven't joined yet, signal to the coordinator that it should spawn no more
@@ -2144,7 +2144,7 @@ impl<B: ExtraBackendMethods> Drop for Coordinator<B> {
21442144
}
21452145
}
21462146

2147-
pub struct OngoingCodegen<B: ExtraBackendMethods> {
2147+
pub struct OngoingCodegen<B: WriteBackendMethods> {
21482148
pub backend: B,
21492149
pub crate_info: CrateInfo,
21502150
pub output_filenames: Arc<OutputFilenames>,
@@ -2156,7 +2156,7 @@ pub struct OngoingCodegen<B: ExtraBackendMethods> {
21562156
pub shared_emitter_main: SharedEmitterMain,
21572157
}
21582158

2159-
impl<B: ExtraBackendMethods> OngoingCodegen<B> {
2159+
impl<B: WriteBackendMethods> OngoingCodegen<B> {
21602160
pub fn join(self, sess: &Session) -> (CodegenResults, FxIndexMap<WorkProductId, WorkProduct>) {
21612161
self.shared_emitter_main.check(sess, true);
21622162

@@ -2287,7 +2287,7 @@ impl<B: ExtraBackendMethods> OngoingCodegen<B> {
22872287
}
22882288
}
22892289

2290-
pub(crate) fn submit_codegened_module_to_llvm<B: ExtraBackendMethods>(
2290+
pub(crate) fn submit_codegened_module_to_llvm<B: WriteBackendMethods>(
22912291
coordinator: &Coordinator<B>,
22922292
module: ModuleCodegen<B::Module>,
22932293
cost: u64,
@@ -2296,15 +2296,15 @@ pub(crate) fn submit_codegened_module_to_llvm<B: ExtraBackendMethods>(
22962296
drop(coordinator.sender.send(Message::CodegenDone::<B> { llvm_work_item, cost }));
22972297
}
22982298

2299-
pub(crate) fn submit_post_lto_module_to_llvm<B: ExtraBackendMethods>(
2299+
pub(crate) fn submit_post_lto_module_to_llvm<B: WriteBackendMethods>(
23002300
coordinator: &Coordinator<B>,
23012301
module: CachedModuleCodegen,
23022302
) {
23032303
let llvm_work_item = WorkItem::CopyPostLtoArtifacts(module);
23042304
drop(coordinator.sender.send(Message::CodegenDone::<B> { llvm_work_item, cost: 0 }));
23052305
}
23062306

2307-
pub(crate) fn submit_pre_lto_module_to_llvm<B: ExtraBackendMethods>(
2307+
pub(crate) fn submit_pre_lto_module_to_llvm<B: WriteBackendMethods>(
23082308
tcx: TyCtxt<'_>,
23092309
coordinator: &Coordinator<B>,
23102310
module: CachedModuleCodegen,

compiler/rustc_codegen_ssa/src/traits/backend.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@ use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
1010
use rustc_middle::ty::TyCtxt;
1111
use rustc_middle::util::Providers;
1212
use rustc_session::Session;
13-
use rustc_session::config::{self, CrateType, OutputFilenames, PrintRequest};
13+
use rustc_session::config::{CrateType, OutputFilenames, PrintRequest};
1414
use rustc_span::Symbol;
1515

1616
use super::CodegenObject;
1717
use super::write::WriteBackendMethods;
1818
use crate::back::archive::ArArchiveBuilderBuilder;
1919
use crate::back::link::link_binary;
20-
use crate::back::write::TargetMachineFactoryFn;
2120
use crate::{CodegenResults, ModuleCodegen, TargetConfig};
2221

2322
pub trait BackendTypes {
@@ -158,17 +157,6 @@ pub trait ExtraBackendMethods:
158157
cgu_name: Symbol,
159158
) -> (ModuleCodegen<Self::Module>, u64);
160159

161-
fn target_machine_factory(
162-
&self,
163-
sess: &Session,
164-
opt_level: config::OptLevel,
165-
target_features: &[String],
166-
) -> TargetMachineFactoryFn<Self>;
167-
168-
fn thread_profiler() -> Box<dyn Any> {
169-
Box::new(())
170-
}
171-
172160
/// Returns `true` if this backend can be safely called from multiple threads.
173161
///
174162
/// Defaults to `true`.

compiler/rustc_codegen_ssa/src/traits/write.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
use std::any::Any;
12
use std::path::PathBuf;
23

34
use rustc_data_structures::profiling::SelfProfilerRef;
45
use rustc_errors::DiagCtxtHandle;
56
use rustc_middle::dep_graph::WorkProduct;
7+
use rustc_session::{Session, config};
68

79
use crate::back::lto::{SerializedModule, ThinModule};
810
use crate::back::write::{
@@ -16,6 +18,15 @@ pub trait WriteBackendMethods: Clone + 'static {
1618
type ModuleBuffer: ModuleBufferMethods;
1719
type ThinData: Send + Sync;
1820

21+
fn thread_profiler() -> Box<dyn Any> {
22+
Box::new(())
23+
}
24+
fn target_machine_factory(
25+
&self,
26+
sess: &Session,
27+
opt_level: config::OptLevel,
28+
target_features: &[String],
29+
) -> TargetMachineFactoryFn<Self>;
1930
/// Performs fat LTO by merging all modules into a single one, running autodiff
2031
/// if necessary and running any further optimizations
2132
fn optimize_and_codegen_fat_lto(

0 commit comments

Comments
 (0)