Skip to main content

rustc_codegen_ssa/traits/
write.rs

1use std::path::PathBuf;
2
3use rustc_errors::DiagCtxtHandle;
4use rustc_middle::dep_graph::WorkProduct;
5
6use crate::back::lto::{SerializedModule, ThinModule};
7use crate::back::write::{CodegenContext, FatLtoInput, ModuleConfig, SharedEmitter};
8use crate::{CompiledModule, ModuleCodegen};
9
10pub trait WriteBackendMethods: Clone + 'static {
11    type Module: Send + Sync;
12    type TargetMachine;
13    type TargetMachineError;
14    type ModuleBuffer: ModuleBufferMethods;
15    type ThinData: Send + Sync;
16    type ThinBuffer: ThinBufferMethods;
17
18    /// Performs fat LTO by merging all modules into a single one, running autodiff
19    /// if necessary and running any further optimizations
20    fn run_and_optimize_fat_lto(
21        cgcx: &CodegenContext<Self>,
22        shared_emitter: &SharedEmitter,
23        exported_symbols_for_lto: &[String],
24        each_linked_rlib_for_lto: &[PathBuf],
25        modules: Vec<FatLtoInput<Self>>,
26    ) -> ModuleCodegen<Self::Module>;
27    /// Performs thin LTO by performing necessary global analysis and returning two
28    /// lists, one of the modules that need optimization and another for modules that
29    /// can simply be copied over from the incr. comp. cache.
30    fn run_thin_lto(
31        cgcx: &CodegenContext<Self>,
32        dcx: DiagCtxtHandle<'_>,
33        exported_symbols_for_lto: &[String],
34        each_linked_rlib_for_lto: &[PathBuf],
35        modules: Vec<(String, Self::ThinBuffer)>,
36        cached_modules: Vec<(SerializedModule<Self::ModuleBuffer>, WorkProduct)>,
37    ) -> (Vec<ThinModule<Self>>, Vec<WorkProduct>);
38    fn print_pass_timings(&self);
39    fn print_statistics(&self);
40    fn optimize(
41        cgcx: &CodegenContext<Self>,
42        shared_emitter: &SharedEmitter,
43        module: &mut ModuleCodegen<Self::Module>,
44        config: &ModuleConfig,
45    );
46    fn optimize_thin(
47        cgcx: &CodegenContext<Self>,
48        shared_emitter: &SharedEmitter,
49        thin: ThinModule<Self>,
50    ) -> ModuleCodegen<Self::Module>;
51    fn codegen(
52        cgcx: &CodegenContext<Self>,
53        shared_emitter: &SharedEmitter,
54        module: ModuleCodegen<Self::Module>,
55        config: &ModuleConfig,
56    ) -> CompiledModule;
57    fn prepare_thin(module: ModuleCodegen<Self::Module>) -> (String, Self::ThinBuffer);
58    fn serialize_module(module: ModuleCodegen<Self::Module>) -> (String, Self::ModuleBuffer);
59}
60
61pub trait ThinBufferMethods: Send + Sync {
62    fn data(&self) -> &[u8];
63}
64
65pub trait ModuleBufferMethods: Send + Sync {
66    fn data(&self) -> &[u8];
67}