]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_ssa/traits/backend.rs
Auto merge of #68623 - Zoxc:lld, r=Mark-Simulacrum
[rust.git] / src / librustc_codegen_ssa / traits / backend.rs
1 use super::write::WriteBackendMethods;
2 use super::CodegenObject;
3 use crate::ModuleCodegen;
4
5 use rustc::middle::cstore::EncodedMetadata;
6 use rustc::session::{config, Session};
7 use rustc::ty::layout::{HasTyCtxt, LayoutOf, TyLayout};
8 use rustc::ty::Ty;
9 use rustc::ty::TyCtxt;
10 use rustc_codegen_utils::codegen_backend::CodegenBackend;
11 use rustc_span::symbol::Symbol;
12 use syntax::expand::allocator::AllocatorKind;
13
14 use std::sync::Arc;
15
16 pub trait BackendTypes {
17     type Value: CodegenObject;
18     type Function: CodegenObject;
19
20     type BasicBlock: Copy;
21     type Type: CodegenObject;
22     type Funclet;
23
24     // FIXME(eddyb) find a common convention for all of the debuginfo-related
25     // names (choose between `Dbg`, `Debug`, `DebugInfo`, `DI` etc.).
26     type DIScope: Copy;
27     type DIVariable: Copy;
28 }
29
30 pub trait Backend<'tcx>:
31     Sized + BackendTypes + HasTyCtxt<'tcx> + LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>>
32 {
33 }
34
35 impl<'tcx, T> Backend<'tcx> for T where
36     Self: BackendTypes + HasTyCtxt<'tcx> + LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>>
37 {
38 }
39
40 pub trait ExtraBackendMethods: CodegenBackend + WriteBackendMethods + Sized + Send + Sync {
41     fn new_metadata(&self, sess: TyCtxt<'_>, mod_name: &str) -> Self::Module;
42     fn write_compressed_metadata<'tcx>(
43         &self,
44         tcx: TyCtxt<'tcx>,
45         metadata: &EncodedMetadata,
46         llvm_module: &mut Self::Module,
47     );
48     fn codegen_allocator<'tcx>(
49         &self,
50         tcx: TyCtxt<'tcx>,
51         mods: &mut Self::Module,
52         kind: AllocatorKind,
53     );
54     /// This generates the codegen unit and returns it along with
55     /// a `u64` giving an estimate of the unit's processing cost.
56     fn compile_codegen_unit(
57         &self,
58         tcx: TyCtxt<'_>,
59         cgu_name: Symbol,
60     ) -> (ModuleCodegen<Self::Module>, u64);
61     // If find_features is true this won't access `sess.crate_types` by assuming
62     // that `is_pie_binary` is false. When we discover LLVM target features
63     // `sess.crate_types` is uninitialized so we cannot access it.
64     fn target_machine_factory(
65         &self,
66         sess: &Session,
67         opt_level: config::OptLevel,
68         find_features: bool,
69     ) -> Arc<dyn Fn() -> Result<Self::TargetMachine, String> + Send + Sync>;
70     fn target_cpu<'b>(&self, sess: &'b Session) -> &'b str;
71 }