Use FunctionBuilder::call_mem{cpy,move}
This commit is contained in:
parent
16e936b93f
commit
742a795c78
15
src/abi.rs
15
src/abi.rs
@ -646,15 +646,16 @@ fn codegen_intrinsic_call<'a, 'tcx: 'a>(
|
||||
.ins()
|
||||
.iconst(fx.module.pointer_type(), elem_size as i64);
|
||||
assert_eq!(args.len(), 3);
|
||||
let src = args[0];
|
||||
let dst = args[1];
|
||||
let src = args[0].load_value(fx);
|
||||
let dst = args[1].load_value(fx);
|
||||
let count = args[2].load_value(fx);
|
||||
let byte_amount = fx.bcx.ins().imul(count, elem_size);
|
||||
fx.easy_call(
|
||||
"memmove",
|
||||
&[dst, src, CValue::ByVal(byte_amount, usize_layout)],
|
||||
nil_ty,
|
||||
);
|
||||
|
||||
if intrinsic.ends_with("_nonoverlapping") {
|
||||
fx.bcx.call_memcpy(fx.isa, dst, src, byte_amount);
|
||||
} else {
|
||||
fx.bcx.call_memmove(fx.isa, dst, src, byte_amount);
|
||||
}
|
||||
}
|
||||
"discriminant_value" => {
|
||||
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>(
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
isa: &isa::TargetIsa,
|
||||
module: &mut Module<impl Backend>,
|
||||
caches: &mut Caches<'tcx>,
|
||||
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) => {
|
||||
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>(
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
isa: &isa::TargetIsa,
|
||||
module: &mut Module<impl Backend>,
|
||||
constants: &mut crate::constant::ConstantCx,
|
||||
caches: &mut Caches<'tcx>,
|
||||
@ -89,6 +91,7 @@ fn trans_fn<'a, 'tcx: 'a>(
|
||||
// Step 5. Make FunctionCx
|
||||
let mut fx = FunctionCx {
|
||||
tcx,
|
||||
isa,
|
||||
module,
|
||||
instance,
|
||||
mir,
|
||||
|
@ -584,6 +584,8 @@ pub fn cton_intcast<'a, 'tcx: 'a>(
|
||||
|
||||
pub struct FunctionCx<'a, 'tcx: 'a, B: Backend + 'a> {
|
||||
pub tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
// FIXME get isa from Module
|
||||
pub isa: &'a isa::TargetIsa,
|
||||
pub module: &'a mut Module<B>,
|
||||
pub instance: Instance<'tcx>,
|
||||
pub mir: &'tcx Mir<'tcx>,
|
||||
|
20
src/lib.rs
20
src/lib.rs
@ -178,13 +178,16 @@ impl CodegenBackend for CraneliftCodegenBackend {
|
||||
|
||||
let metadata = tcx.encode_metadata();
|
||||
|
||||
let mut flags_builder = settings::builder();
|
||||
flags_builder.enable("is_pic").unwrap();
|
||||
let flags = settings::Flags::new(flags_builder);
|
||||
let isa =
|
||||
fn build_isa(tcx: TyCtxt) -> Box<isa::TargetIsa> {
|
||||
let mut flags_builder = settings::builder();
|
||||
flags_builder.enable("is_pic").unwrap();
|
||||
let flags = settings::Flags::new(flags_builder);
|
||||
cranelift::codegen::isa::lookup(tcx.sess.target.target.llvm_target.parse().unwrap())
|
||||
.unwrap()
|
||||
.finish(flags);
|
||||
.finish(flags)
|
||||
}
|
||||
|
||||
let isa = build_isa(tcx);
|
||||
|
||||
let mono_items =
|
||||
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());
|
||||
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();
|
||||
println!("Compiled everything");
|
||||
@ -237,7 +240,7 @@ impl CodegenBackend for CraneliftCodegenBackend {
|
||||
);
|
||||
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();
|
||||
|
||||
@ -318,6 +321,7 @@ impl CodegenBackend for CraneliftCodegenBackend {
|
||||
|
||||
fn codegen_mono_items<'a, 'tcx: 'a>(
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
isa: &isa::TargetIsa,
|
||||
module: &mut Module<impl Backend + 'static>,
|
||||
mono_items: &FxHashSet<MonoItem<'tcx>>,
|
||||
) {
|
||||
@ -333,7 +337,7 @@ fn codegen_mono_items<'a, 'tcx: 'a>(
|
||||
|
||||
for mono_item in mono_items {
|
||||
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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user