Perform some optimizations
This commit is contained in:
parent
0cfe31403a
commit
42066522fb
4 changed files with 35 additions and 32 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -2,3 +2,5 @@
|
||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
*.rlib
|
*.rlib
|
||||||
*.o
|
*.o
|
||||||
|
perf.data
|
||||||
|
perf.data.old
|
||||||
|
|
57
src/base.rs
57
src/base.rs
|
@ -1,10 +1,10 @@
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
struct PrintOnPanic(String);
|
struct PrintOnPanic<F: Fn() -> String>(F);
|
||||||
impl Drop for PrintOnPanic {
|
impl<F: Fn() -> String> Drop for PrintOnPanic<F> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
if ::std::thread::panicking() {
|
if ::std::thread::panicking() {
|
||||||
println!("{}", self.0);
|
println!("{}", (self.0)());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,25 +18,26 @@ pub fn trans_mono_item<'a, 'tcx: 'a>(
|
||||||
) {
|
) {
|
||||||
match mono_item {
|
match mono_item {
|
||||||
MonoItem::Fn(inst) => {
|
MonoItem::Fn(inst) => {
|
||||||
let _print_guard = PrintOnPanic(format!("{:?}", inst));
|
let _inst_guard = PrintOnPanic(|| format!("{:?}", inst));
|
||||||
let mir = match inst.def {
|
let _mir_guard = PrintOnPanic(|| {
|
||||||
InstanceDef::Item(_) | InstanceDef::DropGlue(_, _) | InstanceDef::Virtual(_, _) => {
|
match inst.def {
|
||||||
let mut mir = ::std::io::Cursor::new(Vec::new());
|
InstanceDef::Item(_)
|
||||||
::rustc_mir::util::write_mir_pretty(tcx, Some(inst.def_id()), &mut mir)
|
| InstanceDef::DropGlue(_, _)
|
||||||
.unwrap();
|
| InstanceDef::Virtual(_, _) => {
|
||||||
mir.into_inner()
|
let mut mir = ::std::io::Cursor::new(Vec::new());
|
||||||
|
::rustc_mir::util::write_mir_pretty(tcx, Some(inst.def_id()), &mut mir)
|
||||||
|
.unwrap();
|
||||||
|
String::from_utf8(mir.into_inner()).unwrap()
|
||||||
|
}
|
||||||
|
InstanceDef::FnPtrShim(_, _)
|
||||||
|
| InstanceDef::ClosureOnceShim { .. }
|
||||||
|
| InstanceDef::CloneShim(_, _) => {
|
||||||
|
// FIXME fix write_mir_pretty for these instances
|
||||||
|
format!("{:#?}", tcx.instance_mir(inst.def))
|
||||||
|
}
|
||||||
|
InstanceDef::Intrinsic(_) => bug!("tried to codegen intrinsic"),
|
||||||
}
|
}
|
||||||
InstanceDef::FnPtrShim(_, _)
|
});
|
||||||
| InstanceDef::ClosureOnceShim { .. }
|
|
||||||
| InstanceDef::CloneShim(_, _) => {
|
|
||||||
// FIXME fix write_mir_pretty for these instances
|
|
||||||
format!("{:#?}", tcx.instance_mir(inst.def)).into_bytes()
|
|
||||||
}
|
|
||||||
InstanceDef::Intrinsic(_) => bug!("tried to codegen intrinsic"),
|
|
||||||
};
|
|
||||||
let mir_file_name =
|
|
||||||
"target/out/mir/".to_string() + &format!("{:?}", inst.def_id()).replace('/', "@");
|
|
||||||
::std::fs::write(mir_file_name, mir).unwrap();
|
|
||||||
|
|
||||||
trans_fn(tcx, module, ccx, caches, inst);
|
trans_fn(tcx, module, ccx, caches, inst);
|
||||||
}
|
}
|
||||||
|
@ -103,12 +104,16 @@ fn trans_fn<'a, 'tcx: 'a>(
|
||||||
fx.bcx.seal_all_blocks();
|
fx.bcx.seal_all_blocks();
|
||||||
fx.bcx.finalize();
|
fx.bcx.finalize();
|
||||||
|
|
||||||
// Step 7. Print function to terminal for debugging
|
// Step 7. Write function to file for debugging
|
||||||
let mut writer = crate::pretty_clif::CommentWriter(fx.comments);
|
let mut writer = crate::pretty_clif::CommentWriter(fx.comments);
|
||||||
|
|
||||||
let mut cton = String::new();
|
let mut cton = String::new();
|
||||||
::cranelift::codegen::write::decorate_function(&mut writer, &mut cton, &func, None).unwrap();
|
if cfg!(debug_assertions) {
|
||||||
let clif_file_name = "target/out/clif/".to_string() + &tcx.symbol_name(instance).as_str();
|
::cranelift::codegen::write::decorate_function(&mut writer, &mut cton, &func, None)
|
||||||
::std::fs::write(clif_file_name, cton.as_bytes()).unwrap();
|
.unwrap();
|
||||||
|
let clif_file_name = "target/out/clif/".to_string() + &tcx.symbol_name(instance).as_str();
|
||||||
|
::std::fs::write(clif_file_name, cton.as_bytes()).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
// Step 8. Verify function
|
// Step 8. Verify function
|
||||||
verify_func(tcx, writer, &func);
|
verify_func(tcx, writer, &func);
|
||||||
|
@ -247,7 +252,7 @@ fn trans_stmt<'a, 'tcx: 'a>(
|
||||||
cur_ebb: Ebb,
|
cur_ebb: Ebb,
|
||||||
stmt: &Statement<'tcx>,
|
stmt: &Statement<'tcx>,
|
||||||
) {
|
) {
|
||||||
let _print_guard = PrintOnPanic(format!("stmt {:?}", stmt));
|
let _print_guard = PrintOnPanic(|| format!("stmt {:?}", stmt));
|
||||||
|
|
||||||
let inst = fx.bcx.func.layout.last_inst(cur_ebb).unwrap();
|
let inst = fx.bcx.func.layout.last_inst(cur_ebb).unwrap();
|
||||||
fx.add_comment(inst, format!("{:?}", stmt));
|
fx.add_comment(inst, format!("{:?}", stmt));
|
||||||
|
|
|
@ -246,7 +246,6 @@ impl<'tcx> CValue<'tcx> {
|
||||||
dest.layout().ty
|
dest.layout().ty
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
println!("ty {:?}", self.layout().ty);
|
|
||||||
dest.write_cvalue(fx, CValue::ByValPair(ptr, extra, dest.layout()));
|
dest.write_cvalue(fx, CValue::ByValPair(ptr, extra, dest.layout()));
|
||||||
}
|
}
|
||||||
ty => unimpl!("unsize of non ptr {:?}", ty),
|
ty => unimpl!("unsize of non ptr {:?}", ty),
|
||||||
|
@ -471,10 +470,6 @@ impl<'a, 'tcx: 'a> CPlace<'tcx> {
|
||||||
addr,
|
addr,
|
||||||
a.value.size(fx.tcx).bytes() as u32 as i32,
|
a.value.size(fx.tcx).bytes() as u32 as i32,
|
||||||
);
|
);
|
||||||
println!(
|
|
||||||
"unsized deref: ptr: {:?} extra: {:?} self: {:?}",
|
|
||||||
ptr, extra, self
|
|
||||||
);
|
|
||||||
CPlace::Addr(ptr, Some(extra), inner_layout)
|
CPlace::Addr(ptr, Some(extra), inner_layout)
|
||||||
}
|
}
|
||||||
_ => bug!(
|
_ => bug!(
|
||||||
|
|
|
@ -361,6 +361,7 @@ fn codegen_mono_items<'a, 'tcx: 'a>(
|
||||||
let mut log = ::std::fs::File::create("target/out/log.txt").unwrap();
|
let mut log = ::std::fs::File::create("target/out/log.txt").unwrap();
|
||||||
|
|
||||||
let before = ::std::time::Instant::now();
|
let before = ::std::time::Instant::now();
|
||||||
|
println!("[codegen mono items] start");
|
||||||
|
|
||||||
for mono_item in mono_items {
|
for mono_item in mono_items {
|
||||||
let res = ::std::panic::catch_unwind(::std::panic::AssertUnwindSafe(|| {
|
let res = ::std::panic::catch_unwind(::std::panic::AssertUnwindSafe(|| {
|
||||||
|
@ -383,7 +384,7 @@ fn codegen_mono_items<'a, 'tcx: 'a>(
|
||||||
ccx.finalize(tcx, module);
|
ccx.finalize(tcx, module);
|
||||||
|
|
||||||
let after = ::std::time::Instant::now();
|
let after = ::std::time::Instant::now();
|
||||||
println!("time: {:?}", after - before);
|
println!("[codegen mono items] end time: {:?}", after - before);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save_incremental<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
|
fn save_incremental<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue