rustc_codegen_ssa/traits/
write.rs

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