rustc_codegen_ssa/traits/
write.rs

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