Use FunctionBuilder::call_mem{cpy,move}
This commit is contained in:
parent
16e936b93f
commit
742a795c78
4 changed files with 26 additions and 16 deletions
15
src/abi.rs
15
src/abi.rs
|
@ -646,15 +646,16 @@ fn codegen_intrinsic_call<'a, 'tcx: 'a>(
|
||||||
.ins()
|
.ins()
|
||||||
.iconst(fx.module.pointer_type(), elem_size as i64);
|
.iconst(fx.module.pointer_type(), elem_size as i64);
|
||||||
assert_eq!(args.len(), 3);
|
assert_eq!(args.len(), 3);
|
||||||
let src = args[0];
|
let src = args[0].load_value(fx);
|
||||||
let dst = args[1];
|
let dst = args[1].load_value(fx);
|
||||||
let count = args[2].load_value(fx);
|
let count = args[2].load_value(fx);
|
||||||
let byte_amount = fx.bcx.ins().imul(count, elem_size);
|
let byte_amount = fx.bcx.ins().imul(count, elem_size);
|
||||||
fx.easy_call(
|
|
||||||
"memmove",
|
if intrinsic.ends_with("_nonoverlapping") {
|
||||||
&[dst, src, CValue::ByVal(byte_amount, usize_layout)],
|
fx.bcx.call_memcpy(fx.isa, dst, src, byte_amount);
|
||||||
nil_ty,
|
} else {
|
||||||
);
|
fx.bcx.call_memmove(fx.isa, dst, src, byte_amount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
"discriminant_value" => {
|
"discriminant_value" => {
|
||||||
assert_eq!(args.len(), 1);
|
assert_eq!(args.len(), 1);
|
||||||
|
|
|
@ -11,6 +11,7 @@ impl<F: Fn() -> String> Drop for PrintOnPanic<F> {
|
||||||
|
|
||||||
pub fn trans_mono_item<'a, 'tcx: 'a>(
|
pub fn trans_mono_item<'a, 'tcx: 'a>(
|
||||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
|
isa: &isa::TargetIsa,
|
||||||
module: &mut Module<impl Backend>,
|
module: &mut Module<impl Backend>,
|
||||||
caches: &mut Caches<'tcx>,
|
caches: &mut Caches<'tcx>,
|
||||||
ccx: &mut crate::constant::ConstantCx,
|
ccx: &mut crate::constant::ConstantCx,
|
||||||
|
@ -47,7 +48,7 @@ pub fn trans_mono_item<'a, 'tcx: 'a>(
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
trans_fn(tcx, module, ccx, caches, inst);
|
trans_fn(tcx, isa, module, ccx, caches, inst);
|
||||||
}
|
}
|
||||||
MonoItem::Static(def_id) => {
|
MonoItem::Static(def_id) => {
|
||||||
crate::constant::codegen_static(ccx, def_id);
|
crate::constant::codegen_static(ccx, def_id);
|
||||||
|
@ -60,6 +61,7 @@ pub fn trans_mono_item<'a, 'tcx: 'a>(
|
||||||
|
|
||||||
fn trans_fn<'a, 'tcx: 'a>(
|
fn trans_fn<'a, 'tcx: 'a>(
|
||||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
|
isa: &isa::TargetIsa,
|
||||||
module: &mut Module<impl Backend>,
|
module: &mut Module<impl Backend>,
|
||||||
constants: &mut crate::constant::ConstantCx,
|
constants: &mut crate::constant::ConstantCx,
|
||||||
caches: &mut Caches<'tcx>,
|
caches: &mut Caches<'tcx>,
|
||||||
|
@ -89,6 +91,7 @@ fn trans_fn<'a, 'tcx: 'a>(
|
||||||
// Step 5. Make FunctionCx
|
// Step 5. Make FunctionCx
|
||||||
let mut fx = FunctionCx {
|
let mut fx = FunctionCx {
|
||||||
tcx,
|
tcx,
|
||||||
|
isa,
|
||||||
module,
|
module,
|
||||||
instance,
|
instance,
|
||||||
mir,
|
mir,
|
||||||
|
|
|
@ -584,6 +584,8 @@ pub fn cton_intcast<'a, 'tcx: 'a>(
|
||||||
|
|
||||||
pub struct FunctionCx<'a, 'tcx: 'a, B: Backend + 'a> {
|
pub struct FunctionCx<'a, 'tcx: 'a, B: Backend + 'a> {
|
||||||
pub tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
pub tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
|
// FIXME get isa from Module
|
||||||
|
pub isa: &'a isa::TargetIsa,
|
||||||
pub module: &'a mut Module<B>,
|
pub module: &'a mut Module<B>,
|
||||||
pub instance: Instance<'tcx>,
|
pub instance: Instance<'tcx>,
|
||||||
pub mir: &'tcx Mir<'tcx>,
|
pub mir: &'tcx Mir<'tcx>,
|
||||||
|
|
14
src/lib.rs
14
src/lib.rs
|
@ -178,13 +178,16 @@ impl CodegenBackend for CraneliftCodegenBackend {
|
||||||
|
|
||||||
let metadata = tcx.encode_metadata();
|
let metadata = tcx.encode_metadata();
|
||||||
|
|
||||||
|
fn build_isa(tcx: TyCtxt) -> Box<isa::TargetIsa> {
|
||||||
let mut flags_builder = settings::builder();
|
let mut flags_builder = settings::builder();
|
||||||
flags_builder.enable("is_pic").unwrap();
|
flags_builder.enable("is_pic").unwrap();
|
||||||
let flags = settings::Flags::new(flags_builder);
|
let flags = settings::Flags::new(flags_builder);
|
||||||
let isa =
|
|
||||||
cranelift::codegen::isa::lookup(tcx.sess.target.target.llvm_target.parse().unwrap())
|
cranelift::codegen::isa::lookup(tcx.sess.target.target.llvm_target.parse().unwrap())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.finish(flags);
|
.finish(flags)
|
||||||
|
}
|
||||||
|
|
||||||
|
let isa = build_isa(tcx);
|
||||||
|
|
||||||
let mono_items =
|
let mono_items =
|
||||||
collector::collect_crate_mono_items(tcx, collector::MonoItemCollectionMode::Eager).0;
|
collector::collect_crate_mono_items(tcx, collector::MonoItemCollectionMode::Eager).0;
|
||||||
|
@ -197,7 +200,7 @@ impl CodegenBackend for CraneliftCodegenBackend {
|
||||||
let mut jit_module: Module<SimpleJITBackend> = Module::new(SimpleJITBuilder::new());
|
let mut jit_module: Module<SimpleJITBackend> = Module::new(SimpleJITBuilder::new());
|
||||||
assert_eq!(pointer_ty(tcx), jit_module.pointer_type());
|
assert_eq!(pointer_ty(tcx), jit_module.pointer_type());
|
||||||
|
|
||||||
codegen_mono_items(tcx, &mut jit_module, &mono_items);
|
codegen_mono_items(tcx, &*isa, &mut jit_module, &mono_items);
|
||||||
|
|
||||||
tcx.sess.abort_if_errors();
|
tcx.sess.abort_if_errors();
|
||||||
println!("Compiled everything");
|
println!("Compiled everything");
|
||||||
|
@ -237,7 +240,7 @@ impl CodegenBackend for CraneliftCodegenBackend {
|
||||||
);
|
);
|
||||||
assert_eq!(pointer_ty(tcx), faerie_module.pointer_type());
|
assert_eq!(pointer_ty(tcx), faerie_module.pointer_type());
|
||||||
|
|
||||||
codegen_mono_items(tcx, &mut faerie_module, &mono_items);
|
codegen_mono_items(tcx, &*build_isa(tcx), &mut faerie_module, &mono_items);
|
||||||
|
|
||||||
tcx.sess.abort_if_errors();
|
tcx.sess.abort_if_errors();
|
||||||
|
|
||||||
|
@ -318,6 +321,7 @@ impl CodegenBackend for CraneliftCodegenBackend {
|
||||||
|
|
||||||
fn codegen_mono_items<'a, 'tcx: 'a>(
|
fn codegen_mono_items<'a, 'tcx: 'a>(
|
||||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
|
isa: &isa::TargetIsa,
|
||||||
module: &mut Module<impl Backend + 'static>,
|
module: &mut Module<impl Backend + 'static>,
|
||||||
mono_items: &FxHashSet<MonoItem<'tcx>>,
|
mono_items: &FxHashSet<MonoItem<'tcx>>,
|
||||||
) {
|
) {
|
||||||
|
@ -333,7 +337,7 @@ fn codegen_mono_items<'a, 'tcx: 'a>(
|
||||||
|
|
||||||
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(|| {
|
||||||
base::trans_mono_item(tcx, module, &mut caches, &mut ccx, *mono_item);
|
base::trans_mono_item(tcx, isa, module, &mut caches, &mut ccx, *mono_item);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
if let Err(err) = res {
|
if let Err(err) = res {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue