1 use super::write::WriteBackendMethods;
2 use super::CodegenObject;
3 use crate::ModuleCodegen;
5 use rustc::middle::cstore::EncodedMetadata;
6 use rustc::session::{config, Session};
7 use rustc::ty::layout::{HasTyCtxt, LayoutOf, TyLayout};
10 use rustc_codegen_utils::codegen_backend::CodegenBackend;
11 use rustc_span::symbol::Symbol;
12 use syntax::expand::allocator::AllocatorKind;
16 pub trait BackendTypes {
17 type Value: CodegenObject;
18 type Function: CodegenObject;
20 type BasicBlock: Copy;
21 type Type: CodegenObject;
27 pub trait Backend<'tcx>:
28 Sized + BackendTypes + HasTyCtxt<'tcx> + LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>>
32 impl<'tcx, T> Backend<'tcx> for T where
33 Self: BackendTypes + HasTyCtxt<'tcx> + LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>>
37 pub trait ExtraBackendMethods: CodegenBackend + WriteBackendMethods + Sized + Send + Sync {
38 fn new_metadata(&self, sess: TyCtxt<'_>, mod_name: &str) -> Self::Module;
39 fn write_compressed_metadata<'tcx>(
42 metadata: &EncodedMetadata,
43 llvm_module: &mut Self::Module,
45 fn codegen_allocator<'tcx>(
48 mods: &mut Self::Module,
51 /// This generates the codegen unit and returns it along with
52 /// a `u64` giving an estimate of the unit's processing cost.
53 fn compile_codegen_unit(
57 ) -> (ModuleCodegen<Self::Module>, u64);
58 // If find_features is true this won't access `sess.crate_types` by assuming
59 // that `is_pie_binary` is false. When we discover LLVM target features
60 // `sess.crate_types` is uninitialized so we cannot access it.
61 fn target_machine_factory(
64 opt_level: config::OptLevel,
66 ) -> Arc<dyn Fn() -> Result<Self::TargetMachine, String> + Send + Sync>;
67 fn target_cpu<'b>(&self, sess: &'b Session) -> &'b str;