rustc_codegen_ssa/traits/
write.rs1use std::any::Any;
2use std::path::PathBuf;
3
4use rustc_data_structures::profiling::SelfProfilerRef;
5use rustc_errors::DiagCtxtHandle;
6use rustc_middle::dep_graph::WorkProduct;
7use rustc_session::{Session, config};
8
9use crate::back::lto::{SerializedModule, ThinModule};
10use crate::back::write::{
11 CodegenContext, FatLtoInput, ModuleConfig, SharedEmitter, TargetMachineFactoryFn,
12};
13use crate::{CompiledModule, ModuleCodegen};
14
15pub trait WriteBackendMethods: Clone + 'static {
16 type Module: Send + Sync;
17 type TargetMachine;
18 type ModuleBuffer: ModuleBufferMethods;
19 type ThinData: Send + Sync;
20
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>;
30 fn optimize_and_codegen_fat_lto(
33 cgcx: &CodegenContext,
34 prof: &SelfProfilerRef,
35 shared_emitter: &SharedEmitter,
36 tm_factory: TargetMachineFactoryFn<Self>,
37 exported_symbols_for_lto: &[String],
38 each_linked_rlib_for_lto: &[PathBuf],
39 modules: Vec<FatLtoInput<Self>>,
40 ) -> CompiledModule;
41 fn run_thin_lto(
45 cgcx: &CodegenContext,
46 prof: &SelfProfilerRef,
47 dcx: DiagCtxtHandle<'_>,
48 exported_symbols_for_lto: &[String],
49 each_linked_rlib_for_lto: &[PathBuf],
50 modules: Vec<(String, Self::ModuleBuffer)>,
51 cached_modules: Vec<(SerializedModule<Self::ModuleBuffer>, WorkProduct)>,
52 ) -> (Vec<ThinModule<Self>>, Vec<WorkProduct>);
53 fn optimize(
54 cgcx: &CodegenContext,
55 prof: &SelfProfilerRef,
56 shared_emitter: &SharedEmitter,
57 module: &mut ModuleCodegen<Self::Module>,
58 config: &ModuleConfig,
59 );
60 fn optimize_and_codegen_thin(
61 cgcx: &CodegenContext,
62 prof: &SelfProfilerRef,
63 shared_emitter: &SharedEmitter,
64 tm_factory: TargetMachineFactoryFn<Self>,
65 thin: ThinModule<Self>,
66 ) -> CompiledModule;
67 fn codegen(
68 cgcx: &CodegenContext,
69 prof: &SelfProfilerRef,
70 shared_emitter: &SharedEmitter,
71 module: ModuleCodegen<Self::Module>,
72 config: &ModuleConfig,
73 ) -> CompiledModule;
74 fn serialize_module(module: Self::Module, is_thin: bool) -> Self::ModuleBuffer;
75}
76
77pub trait ModuleBufferMethods: Send + Sync {
78 fn data(&self) -> &[u8];
79}