1
Fork 0

Some refactorings for codegen_mono_items

This commit is contained in:
bjorn3 2018-12-12 16:01:34 +01:00
parent 94eac08a48
commit 4d0dba944c
3 changed files with 40 additions and 32 deletions

View file

@ -13,7 +13,22 @@ use crate::prelude::*;
use rustc::middle::allocator::AllocatorKind; use rustc::middle::allocator::AllocatorKind;
use rustc_allocator::{AllocatorTy, ALLOCATOR_METHODS}; use rustc_allocator::{AllocatorTy, ALLOCATOR_METHODS};
pub fn codegen(module: &mut Module<impl Backend + 'static>, kind: AllocatorKind) { pub fn codegen(sess: &Session, module: &mut Module<impl Backend + 'static>) {
let any_dynamic_crate = sess
.dependency_formats
.borrow()
.iter()
.any(|(_, list)| {
use rustc::middle::dependency_format::Linkage;
list.iter().any(|&linkage| linkage == Linkage::Dynamic)
});
if any_dynamic_crate {
} else if let Some(kind) = *sess.allocator_kind.get() {
codegen_inner(module, kind);
}
}
pub fn codegen_inner(module: &mut Module<impl Backend + 'static>, kind: AllocatorKind) {
let usize_ty = module.target_config().pointer_type(); let usize_ty = module.target_config().pointer_type();
for method in ALLOCATOR_METHODS { for method in ALLOCATOR_METHODS {

View file

@ -1,6 +1,5 @@
use std::fmt; use std::fmt;
use rustc_codegen_ssa::traits::BackendTypes;
use rustc_target::spec::{HasTargetSpec, Target}; use rustc_target::spec::{HasTargetSpec, Target};
use cranelift_module::Module; use cranelift_module::Module;

View file

@ -80,6 +80,7 @@ mod prelude {
pub use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue}; pub use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue};
pub use rustc_codegen_ssa::{CodegenResults, CompiledModule, ModuleKind}; pub use rustc_codegen_ssa::{CodegenResults, CompiledModule, ModuleKind};
pub use rustc_codegen_ssa::traits::*;
pub use cranelift::codegen::ir::{ pub use cranelift::codegen::ir::{
condcodes::IntCC, function::Function, ExternalName, FuncRef, Inst, StackSlot, condcodes::IntCC, function::Function, ExternalName, FuncRef, Inst, StackSlot,
@ -200,6 +201,8 @@ impl CodegenBackend for CraneliftCodegenBackend {
.unwrap(); .unwrap();
codegen_mono_items(tcx, &mut jit_module, &mut log); codegen_mono_items(tcx, &mut jit_module, &mut log);
crate::allocator::codegen(tcx.sess, &mut jit_module);
jit_module.finalize_definitions();
tcx.sess.abort_if_errors(); tcx.sess.abort_if_errors();
println!("Compiled everything"); println!("Compiled everything");
@ -216,10 +219,9 @@ impl CodegenBackend for CraneliftCodegenBackend {
jit_module.finish(); jit_module.finish();
::std::process::exit(0); ::std::process::exit(0);
} else { } else {
let isa = build_isa(tcx.sess);
let mut faerie_module: Module<FaerieBackend> = Module::new( let mut faerie_module: Module<FaerieBackend> = Module::new(
FaerieBuilder::new( FaerieBuilder::new(
isa, build_isa(tcx.sess),
"some_file.o".to_string(), "some_file.o".to_string(),
FaerieTrapCollection::Disabled, FaerieTrapCollection::Disabled,
FaerieBuilder::default_libcall_names(), FaerieBuilder::default_libcall_names(),
@ -232,6 +234,8 @@ impl CodegenBackend for CraneliftCodegenBackend {
); );
codegen_mono_items(tcx, &mut faerie_module, &mut log); codegen_mono_items(tcx, &mut faerie_module, &mut log);
crate::allocator::codegen(tcx.sess, &mut faerie_module);
faerie_module.finalize_definitions();
tcx.sess.abort_if_errors(); tcx.sess.abort_if_errors();
@ -339,9 +343,7 @@ fn codegen_mono_items<'a, 'tcx: 'a>(
.flatten() .flatten()
.collect::<FxHashSet<(_, _)>>(); .collect::<FxHashSet<(_, _)>>();
let before = ::std::time::Instant::now(); time("codegen mono items", move || {
println!("[codegen mono items] start");
for (&mono_item, &(_linkage, _vis)) in mono_items { for (&mono_item, &(_linkage, _vis)) in mono_items {
unimpl::try_unimpl(tcx, log, || { unimpl::try_unimpl(tcx, log, || {
base::trans_mono_item(tcx, module, &mut caches, &mut ccx, mono_item); base::trans_mono_item(tcx, module, &mut caches, &mut ccx, mono_item);
@ -350,25 +352,17 @@ fn codegen_mono_items<'a, 'tcx: 'a>(
crate::main_shim::maybe_create_entry_wrapper(tcx, module); crate::main_shim::maybe_create_entry_wrapper(tcx, module);
let any_dynamic_crate = tcx ccx.finalize(tcx, module);
.sess
.dependency_formats
.borrow()
.iter()
.any(|(_, list)| {
use rustc::middle::dependency_format::Linkage;
list.iter().any(|&linkage| linkage == Linkage::Dynamic)
}); });
if any_dynamic_crate {
} else if let Some(kind) = *tcx.sess.allocator_kind.get() {
allocator::codegen(module, kind);
} }
ccx.finalize(tcx, module); fn time<R>(name: &str, f: impl FnOnce() -> R) -> R {
module.finalize_definitions(); println!("[{}] start", name);
let before = ::std::time::Instant::now();
let res = f();
let after = ::std::time::Instant::now(); let after = ::std::time::Instant::now();
println!("[codegen mono items] end time: {:?}", after - before); println!("[{}] end time: {:?}", name, after - before);
res
} }
fn save_incremental<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) { fn save_incremental<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {