Skip to content

Commit 9866ca8

Browse files
committed
Move some methods to WriteBackendMethods
1 parent 4878456 commit 9866ca8

File tree

5 files changed

+48
-50
lines changed

5 files changed

+48
-50
lines changed

compiler/rustc_codegen_gcc/src/lib.rs

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

386376
#[derive(Clone, Copy, PartialEq)]
@@ -438,6 +428,16 @@ impl WriteBackendMethods for GccCodegenBackend {
438428
type ThinData = ();
439429
type ThinBuffer = ThinBuffer;
440430

431+
fn target_machine_factory(
432+
&self,
433+
_sess: &Session,
434+
_opt_level: OptLevel,
435+
_features: &[String],
436+
) -> TargetMachineFactoryFn<Self> {
437+
// TODO(antoyo): set opt level.
438+
Arc::new(|_, _| ())
439+
}
440+
441441
fn optimize_and_codegen_fat_lto(
442442
cgcx: &CodegenContext,
443443
prof: &SelfProfilerRef,

compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,18 +116,6 @@ impl ExtraBackendMethods for LlvmCodegenBackend {
116116
) -> (ModuleCodegen<ModuleLlvm>, u64) {
117117
base::compile_codegen_unit(tcx, cgu_name)
118118
}
119-
fn target_machine_factory(
120-
&self,
121-
sess: &Session,
122-
optlvl: OptLevel,
123-
target_features: &[String],
124-
) -> TargetMachineFactoryFn<Self> {
125-
back::write::target_machine_factory(sess, optlvl, target_features)
126-
}
127-
128-
fn thread_profiler() -> Box<dyn Any> {
129-
Box::new(TimeTraceProfiler::new())
130-
}
131119
}
132120

133121
impl WriteBackendMethods for LlvmCodegenBackend {
@@ -136,6 +124,17 @@ impl WriteBackendMethods for LlvmCodegenBackend {
136124
type TargetMachine = OwnedTargetMachine;
137125
type ThinData = back::lto::ThinData;
138126
type ThinBuffer = back::lto::ThinBuffer;
127+
fn thread_profiler() -> Box<dyn Any> {
128+
Box::new(TimeTraceProfiler::new())
129+
}
130+
fn target_machine_factory(
131+
&self,
132+
sess: &Session,
133+
optlvl: OptLevel,
134+
target_features: &[String],
135+
) -> TargetMachineFactoryFn<Self> {
136+
back::write::target_machine_factory(sess, optlvl, target_features)
137+
}
139138
fn optimize_and_codegen_fat_lto(
140139
cgcx: &CodegenContext,
141140
prof: &SelfProfilerRef,

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ pub struct CodegenContext {
360360
pub parallel: bool,
361361
}
362362

363-
fn generate_thin_lto_work<B: ExtraBackendMethods>(
363+
fn generate_thin_lto_work<B: WriteBackendMethods>(
364364
cgcx: &CodegenContext,
365365
prof: &SelfProfilerRef,
366366
dcx: DiagCtxtHandle<'_>,
@@ -840,7 +840,7 @@ pub(crate) fn compute_per_cgu_lto_type(
840840
}
841841
}
842842

843-
fn execute_optimize_work_item<B: ExtraBackendMethods>(
843+
fn execute_optimize_work_item<B: WriteBackendMethods>(
844844
cgcx: &CodegenContext,
845845
prof: &SelfProfilerRef,
846846
shared_emitter: SharedEmitter,
@@ -985,7 +985,7 @@ fn execute_copy_from_cache_work_item(
985985
}
986986
}
987987

988-
fn do_fat_lto<B: ExtraBackendMethods>(
988+
fn do_fat_lto<B: WriteBackendMethods>(
989989
cgcx: &CodegenContext,
990990
prof: &SelfProfilerRef,
991991
shared_emitter: SharedEmitter,
@@ -1017,7 +1017,7 @@ fn do_fat_lto<B: ExtraBackendMethods>(
10171017
)
10181018
}
10191019

1020-
fn do_thin_lto<B: ExtraBackendMethods>(
1020+
fn do_thin_lto<B: WriteBackendMethods>(
10211021
cgcx: &CodegenContext,
10221022
prof: &SelfProfilerRef,
10231023
shared_emitter: SharedEmitter,
@@ -1170,7 +1170,7 @@ fn do_thin_lto<B: ExtraBackendMethods>(
11701170
compiled_modules
11711171
}
11721172

1173-
fn execute_thin_lto_work_item<B: ExtraBackendMethods>(
1173+
fn execute_thin_lto_work_item<B: WriteBackendMethods>(
11741174
cgcx: &CodegenContext,
11751175
prof: &SelfProfilerRef,
11761176
shared_emitter: SharedEmitter,
@@ -1897,7 +1897,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
18971897
#[must_use]
18981898
pub(crate) struct WorkerFatalError;
18991899

1900-
fn spawn_work<'a, B: ExtraBackendMethods>(
1900+
fn spawn_work<'a, B: WriteBackendMethods>(
19011901
cgcx: &CodegenContext,
19021902
prof: &'a SelfProfilerRef,
19031903
shared_emitter: SharedEmitter,
@@ -1940,7 +1940,7 @@ fn spawn_work<'a, B: ExtraBackendMethods>(
19401940
std::thread::Builder::new().name(name).spawn(f).expect("failed to spawn work thread");
19411941
}
19421942

1943-
fn spawn_thin_lto_work<B: ExtraBackendMethods>(
1943+
fn spawn_thin_lto_work<B: WriteBackendMethods>(
19441944
cgcx: &CodegenContext,
19451945
prof: &SelfProfilerRef,
19461946
shared_emitter: SharedEmitter,
@@ -2131,20 +2131,20 @@ impl SharedEmitterMain {
21312131
}
21322132
}
21332133

2134-
pub struct Coordinator<B: ExtraBackendMethods> {
2134+
pub struct Coordinator<B: WriteBackendMethods> {
21352135
sender: Sender<Message<B>>,
21362136
future: Option<thread::JoinHandle<Result<MaybeLtoModules<B>, ()>>>,
21372137
// Only used for the Message type.
21382138
phantom: PhantomData<B>,
21392139
}
21402140

2141-
impl<B: ExtraBackendMethods> Coordinator<B> {
2141+
impl<B: WriteBackendMethods> Coordinator<B> {
21422142
fn join(mut self) -> std::thread::Result<Result<MaybeLtoModules<B>, ()>> {
21432143
self.future.take().unwrap().join()
21442144
}
21452145
}
21462146

2147-
impl<B: ExtraBackendMethods> Drop for Coordinator<B> {
2147+
impl<B: WriteBackendMethods> Drop for Coordinator<B> {
21482148
fn drop(&mut self) {
21492149
if let Some(future) = self.future.take() {
21502150
// If we haven't joined yet, signal to the coordinator that it should spawn no more
@@ -2155,7 +2155,7 @@ impl<B: ExtraBackendMethods> Drop for Coordinator<B> {
21552155
}
21562156
}
21572157

2158-
pub struct OngoingCodegen<B: ExtraBackendMethods> {
2158+
pub struct OngoingCodegen<B: WriteBackendMethods> {
21592159
pub backend: B,
21602160
pub crate_info: CrateInfo,
21612161
pub output_filenames: Arc<OutputFilenames>,
@@ -2167,7 +2167,7 @@ pub struct OngoingCodegen<B: ExtraBackendMethods> {
21672167
pub shared_emitter_main: SharedEmitterMain,
21682168
}
21692169

2170-
impl<B: ExtraBackendMethods> OngoingCodegen<B> {
2170+
impl<B: WriteBackendMethods> OngoingCodegen<B> {
21712171
pub fn join(self, sess: &Session) -> (CodegenResults, FxIndexMap<WorkProductId, WorkProduct>) {
21722172
self.shared_emitter_main.check(sess, true);
21732173

@@ -2298,7 +2298,7 @@ impl<B: ExtraBackendMethods> OngoingCodegen<B> {
22982298
}
22992299
}
23002300

2301-
pub(crate) fn submit_codegened_module_to_llvm<B: ExtraBackendMethods>(
2301+
pub(crate) fn submit_codegened_module_to_llvm<B: WriteBackendMethods>(
23022302
coordinator: &Coordinator<B>,
23032303
module: ModuleCodegen<B::Module>,
23042304
cost: u64,
@@ -2307,15 +2307,15 @@ pub(crate) fn submit_codegened_module_to_llvm<B: ExtraBackendMethods>(
23072307
drop(coordinator.sender.send(Message::CodegenDone::<B> { llvm_work_item, cost }));
23082308
}
23092309

2310-
pub(crate) fn submit_post_lto_module_to_llvm<B: ExtraBackendMethods>(
2310+
pub(crate) fn submit_post_lto_module_to_llvm<B: WriteBackendMethods>(
23112311
coordinator: &Coordinator<B>,
23122312
module: CachedModuleCodegen,
23132313
) {
23142314
let llvm_work_item = WorkItem::CopyPostLtoArtifacts(module);
23152315
drop(coordinator.sender.send(Message::CodegenDone::<B> { llvm_work_item, cost: 0 }));
23162316
}
23172317

2318-
pub(crate) fn submit_pre_lto_module_to_llvm<B: ExtraBackendMethods>(
2318+
pub(crate) fn submit_pre_lto_module_to_llvm<B: WriteBackendMethods>(
23192319
tcx: TyCtxt<'_>,
23202320
coordinator: &Coordinator<B>,
23212321
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::{
@@ -17,6 +19,15 @@ pub trait WriteBackendMethods: Clone + 'static {
1719
type ThinData: Send + Sync;
1820
type ThinBuffer: ThinBufferMethods;
1921

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

0 commit comments

Comments
 (0)