]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_codegen_ssa/src/traits/write.rs
Merge branch 'master' into patch-2
[rust.git] / compiler / rustc_codegen_ssa / src / traits / write.rs
1 use crate::back::lto::{LtoModuleCodegen, SerializedModule, ThinModule};
2 use crate::back::write::{CodegenContext, FatLTOInput, ModuleConfig};
3 use crate::{CompiledModule, ModuleCodegen};
4
5 use rustc_errors::{FatalError, Handler};
6 use rustc_middle::dep_graph::WorkProduct;
7
8 pub trait WriteBackendMethods: 'static + Sized + Clone {
9     type Module: Send + Sync;
10     type TargetMachine;
11     type ModuleBuffer: ModuleBufferMethods;
12     type ThinData: Send + Sync;
13     type ThinBuffer: ThinBufferMethods;
14
15     /// Merge all modules into main_module and returning it
16     fn run_link(
17         cgcx: &CodegenContext<Self>,
18         diag_handler: &Handler,
19         modules: Vec<ModuleCodegen<Self::Module>>,
20     ) -> Result<ModuleCodegen<Self::Module>, FatalError>;
21     /// Performs fat LTO by merging all modules into a single one and returning it
22     /// for further optimization.
23     fn run_fat_lto(
24         cgcx: &CodegenContext<Self>,
25         modules: Vec<FatLTOInput<Self>>,
26         cached_modules: Vec<(SerializedModule<Self::ModuleBuffer>, WorkProduct)>,
27     ) -> Result<LtoModuleCodegen<Self>, 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         modules: Vec<(String, Self::ThinBuffer)>,
34         cached_modules: Vec<(SerializedModule<Self::ModuleBuffer>, WorkProduct)>,
35     ) -> Result<(Vec<LtoModuleCodegen<Self>>, Vec<WorkProduct>), FatalError>;
36     fn print_pass_timings(&self);
37     unsafe fn optimize(
38         cgcx: &CodegenContext<Self>,
39         diag_handler: &Handler,
40         module: &ModuleCodegen<Self::Module>,
41         config: &ModuleConfig,
42     ) -> Result<(), FatalError>;
43     fn optimize_fat(
44         cgcx: &CodegenContext<Self>,
45         llmod: &mut ModuleCodegen<Self::Module>,
46     ) -> Result<(), FatalError>;
47     unsafe fn optimize_thin(
48         cgcx: &CodegenContext<Self>,
49         thin: ThinModule<Self>,
50     ) -> Result<ModuleCodegen<Self::Module>, FatalError>;
51     unsafe fn codegen(
52         cgcx: &CodegenContext<Self>,
53         diag_handler: &Handler,
54         module: ModuleCodegen<Self::Module>,
55         config: &ModuleConfig,
56     ) -> Result<CompiledModule, FatalError>;
57     fn prepare_thin(module: ModuleCodegen<Self::Module>) -> (String, Self::ThinBuffer);
58     fn serialize_module(module: ModuleCodegen<Self::Module>) -> (String, Self::ModuleBuffer);
59 }
60
61 pub trait ThinBufferMethods: Send + Sync {
62     fn data(&self) -> &[u8];
63 }
64
65 pub trait ModuleBufferMethods: Send + Sync {
66     fn data(&self) -> &[u8];
67 }