1
Fork 0

Added compile codegen to backend trait

This commit is contained in:
Denis Merigoux 2018-09-27 15:31:20 +02:00 committed by Eduard-Mihai Burtescu
parent 6819e6e6e1
commit 4ba09ab8d2
4 changed files with 18 additions and 30 deletions

View file

@ -56,6 +56,7 @@ use rustc_mir::monomorphize::item::DefPathBasedNames;
use common::{self, IntPredicate, RealPredicate, TypeKind}; use common::{self, IntPredicate, RealPredicate, TypeKind};
use meth; use meth;
use mir; use mir;
use context::CodegenCx;
use monomorphize::Instance; use monomorphize::Instance;
use monomorphize::partitioning::{CodegenUnit, CodegenUnitExt}; use monomorphize::partitioning::{CodegenUnit, CodegenUnitExt};
use rustc_codegen_utils::symbol_names_test; use rustc_codegen_utils::symbol_names_test;
@ -712,7 +713,7 @@ fn determine_cgu_reuse<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
} }
} }
pub fn codegen_crate<'a, 'tcx, B: BackendMethods>( pub fn codegen_crate<B: BackendMethods>(
backend: B, backend: B,
tcx: TyCtxt<'a, 'tcx, 'tcx>, tcx: TyCtxt<'a, 'tcx, 'tcx>,
rx: mpsc::Receiver<Box<dyn Any + Send>> rx: mpsc::Receiver<Box<dyn Any + Send>>
@ -858,7 +859,7 @@ pub fn codegen_crate<'a, 'tcx, B: BackendMethods>(
&format!("codegen {}", cgu.name())) &format!("codegen {}", cgu.name()))
}); });
let start_time = Instant::now(); let start_time = Instant::now();
let stats = compile_codegen_unit(tcx, *cgu.name()); let stats = backend.compile_codegen_unit(tcx, *cgu.name());
all_stats.extend(stats); all_stats.extend(stats);
total_codegen_time += start_time.elapsed(); total_codegen_time += start_time.elapsed();
false false
@ -1066,7 +1067,7 @@ impl CrateInfo {
} }
} }
fn compile_codegen_unit<'ll, 'tcx>(tcx: TyCtxt<'ll, 'tcx, 'tcx>, pub fn compile_codegen_unit<'ll, 'tcx>(tcx: TyCtxt<'ll, 'tcx, 'tcx>,
cgu_name: InternedString) cgu_name: InternedString)
-> Stats { -> Stats {
let start_time = Instant::now(); let start_time = Instant::now();
@ -1098,7 +1099,7 @@ fn compile_codegen_unit<'ll, 'tcx>(tcx: TyCtxt<'ll, 'tcx, 'tcx>,
// Instantiate monomorphizations without filling out definitions yet... // Instantiate monomorphizations without filling out definitions yet...
let llvm_module = backend.new_metadata(tcx.sess, &cgu_name.as_str()); let llvm_module = backend.new_metadata(tcx.sess, &cgu_name.as_str());
let stats = { let stats = {
let cx = backend.new_codegen_context(tcx, cgu, &llvm_module); let cx = CodegenCx::new(tcx, cgu, &llvm_module);
let mono_items = cx.codegen_unit let mono_items = cx.codegen_unit
.items_in_deterministic_order(cx.tcx); .items_in_deterministic_order(cx.tcx);
for &(mono_item, (linkage, visibility)) in &mono_items { for &(mono_item, (linkage, visibility)) in &mono_items {

View file

@ -11,15 +11,15 @@
use rustc::ty::layout::{HasTyCtxt, LayoutOf, TyLayout}; use rustc::ty::layout::{HasTyCtxt, LayoutOf, TyLayout};
use rustc::ty::Ty; use rustc::ty::Ty;
use super::{CodegenMethods, CodegenObject}; use super::CodegenObject;
use monomorphize::partitioning::CodegenUnit;
use rustc::middle::allocator::AllocatorKind; use rustc::middle::allocator::AllocatorKind;
use rustc::middle::cstore::EncodedMetadata; use rustc::middle::cstore::EncodedMetadata;
use rustc::mir::mono::Stats;
use rustc::session::Session; use rustc::session::Session;
use rustc::ty::TyCtxt; use rustc::ty::TyCtxt;
use std::any::Any; use std::any::Any;
use std::sync::mpsc::Receiver; use std::sync::mpsc::Receiver;
use std::sync::Arc; use syntax_pos::symbol::InternedString;
use time_graph::TimeGraph; use time_graph::TimeGraph;
use ModuleCodegen; use ModuleCodegen;
@ -71,15 +71,9 @@ pub trait BackendMethods {
fn codegen_finished(&self, codegen: &Self::OngoingCodegen, tcx: TyCtxt); fn codegen_finished(&self, codegen: &Self::OngoingCodegen, tcx: TyCtxt);
fn check_for_errors(&self, codegen: &Self::OngoingCodegen, sess: &Session); fn check_for_errors(&self, codegen: &Self::OngoingCodegen, sess: &Session);
fn wait_for_signal_to_codegen_item(&self, codegen: &Self::OngoingCodegen); fn wait_for_signal_to_codegen_item(&self, codegen: &Self::OngoingCodegen);
} fn compile_codegen_unit<'a, 'tcx: 'a>(
pub trait BackendCodegenCxMethods<'a, 'tcx: 'a>: BackendMethods {
type CodegenCx: CodegenMethods<'tcx>;
fn new_codegen_context(
&self, &self,
tcx: TyCtxt<'a, 'tcx, 'tcx>, tcx: TyCtxt<'a, 'tcx, 'tcx>,
codegen_unit: Arc<CodegenUnit<'tcx>>, cgu_name: InternedString,
llvm_module: &'a Self::Module, ) -> Stats;
) -> Self::CodegenCx;
} }

View file

@ -22,7 +22,7 @@ mod type_;
pub use self::abi::{AbiBuilderMethods, AbiMethods}; pub use self::abi::{AbiBuilderMethods, AbiMethods};
pub use self::asm::{AsmBuilderMethods, AsmMethods}; pub use self::asm::{AsmBuilderMethods, AsmMethods};
pub use self::backend::{Backend, BackendCodegenCxMethods, BackendMethods, BackendTypes}; pub use self::backend::{Backend, BackendMethods, BackendTypes};
pub use self::builder::BuilderMethods; pub use self::builder::BuilderMethods;
pub use self::consts::ConstMethods; pub use self::consts::ConstMethods;
pub use self::debuginfo::{DebugInfoBuilderMethods, DebugInfoMethods}; pub use self::debuginfo::{DebugInfoBuilderMethods, DebugInfoMethods};

View file

@ -72,12 +72,11 @@ use interfaces::*;
use time_graph::TimeGraph; use time_graph::TimeGraph;
use std::sync::mpsc::Receiver; use std::sync::mpsc::Receiver;
use back::write::{self, OngoingCodegen}; use back::write::{self, OngoingCodegen};
use context::CodegenCx; use syntax_pos::symbol::InternedString;
use monomorphize::partitioning::CodegenUnit; use rustc::mir::mono::Stats;
pub use llvm_util::target_features; pub use llvm_util::target_features;
use std::any::Any; use std::any::Any;
use std::sync::Arc;
use std::sync::mpsc; use std::sync::mpsc;
use rustc_data_structures::sync::Lrc; use rustc_data_structures::sync::Lrc;
@ -188,18 +187,12 @@ impl BackendMethods for LlvmCodegenBackend {
fn wait_for_signal_to_codegen_item(&self, codegen: &OngoingCodegen) { fn wait_for_signal_to_codegen_item(&self, codegen: &OngoingCodegen) {
codegen.wait_for_signal_to_codegen_item() codegen.wait_for_signal_to_codegen_item()
} }
} fn compile_codegen_unit<'a, 'tcx: 'a>(
impl<'a, 'tcx: 'a> BackendCodegenCxMethods<'a, 'tcx> for LlvmCodegenBackend {
type CodegenCx = CodegenCx<'a, 'tcx>;
fn new_codegen_context(
&self, &self,
tcx: TyCtxt<'a, 'tcx, 'tcx>, tcx: TyCtxt<'a, 'tcx, 'tcx>,
codegen_unit: Arc<CodegenUnit<'tcx>>, cgu_name: InternedString,
llvm_module: &'a ModuleLlvm ) -> Stats {
) -> CodegenCx<'a, 'tcx> { base::compile_codegen_unit(tcx, cgu_name)
CodegenCx::new(tcx, codegen_unit, llvm_module)
} }
} }