FunctionCx: Replace .module with .codegen_cx.module
This commit is contained in:
parent
297d65c247
commit
cb69c7019c
12 changed files with 62 additions and 62 deletions
|
@ -226,9 +226,9 @@ pub(crate) fn import_function<'tcx>(
|
||||||
impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
|
impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
|
||||||
/// Instance must be monomorphized
|
/// Instance must be monomorphized
|
||||||
pub(crate) fn get_function_ref(&mut self, inst: Instance<'tcx>) -> FuncRef {
|
pub(crate) fn get_function_ref(&mut self, inst: Instance<'tcx>) -> FuncRef {
|
||||||
let func_id = import_function(selfcodegen_cx.tcx, self.module, inst);
|
let func_id = import_function(selfcodegen_cx.tcx, selfcodegen_cx.module, inst);
|
||||||
let func_ref = self
|
let func_ref = self
|
||||||
.module
|
codegen_cx.module
|
||||||
.declare_func_in_func(func_id, &mut self.bcx.func);
|
.declare_func_in_func(func_id, &mut self.bcx.func);
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
|
@ -250,11 +250,11 @@ impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
|
||||||
call_conv: CallConv::triple_default(self.triple()),
|
call_conv: CallConv::triple_default(self.triple()),
|
||||||
};
|
};
|
||||||
let func_id = self
|
let func_id = self
|
||||||
.module
|
codegen_cx.module
|
||||||
.declare_function(&name, Linkage::Import, &sig)
|
.declare_function(&name, Linkage::Import, &sig)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let func_ref = self
|
let func_ref = self
|
||||||
.module
|
codegen_cx.module
|
||||||
.declare_func_in_func(func_id, &mut self.bcx.func);
|
.declare_func_in_func(func_id, &mut self.bcx.func);
|
||||||
let call_inst = self.bcx.ins().call(func_ref, args);
|
let call_inst = self.bcx.ins().call(func_ref, args);
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
|
|
|
@ -81,7 +81,7 @@ pub(crate) fn init_global_lock_constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn lock_global_lock(fx: &mut FunctionCx<'_, '_, impl Backend>) {
|
pub(crate) fn lock_global_lock(fx: &mut FunctionCx<'_, '_, impl Backend>) {
|
||||||
let atomic_mutex = fx.module.declare_data(
|
let atomic_mutex = fxcodegen_cx.module.declare_data(
|
||||||
"__cg_clif_global_atomic_mutex",
|
"__cg_clif_global_atomic_mutex",
|
||||||
Linkage::Import,
|
Linkage::Import,
|
||||||
true,
|
true,
|
||||||
|
@ -89,24 +89,24 @@ pub(crate) fn lock_global_lock(fx: &mut FunctionCx<'_, '_, impl Backend>) {
|
||||||
None,
|
None,
|
||||||
).unwrap();
|
).unwrap();
|
||||||
|
|
||||||
let pthread_mutex_lock = fx.module.declare_function("pthread_mutex_lock", Linkage::Import, &cranelift_codegen::ir::Signature {
|
let pthread_mutex_lock = fxcodegen_cx.module.declare_function("pthread_mutex_lock", Linkage::Import, &cranelift_codegen::ir::Signature {
|
||||||
call_conv: fx.module.target_config().default_call_conv,
|
call_conv: fxcodegen_cx.module.target_config().default_call_conv,
|
||||||
params: vec![
|
params: vec![
|
||||||
AbiParam::new(fx.module.target_config().pointer_type() /* *mut pthread_mutex_t */),
|
AbiParam::new(fxcodegen_cx.module.target_config().pointer_type() /* *mut pthread_mutex_t */),
|
||||||
],
|
],
|
||||||
returns: vec![AbiParam::new(types::I32 /* c_int */)],
|
returns: vec![AbiParam::new(types::I32 /* c_int */)],
|
||||||
}).unwrap();
|
}).unwrap();
|
||||||
|
|
||||||
let pthread_mutex_lock = fx.module.declare_func_in_func(pthread_mutex_lock, fx.bcx.func);
|
let pthread_mutex_lock = fxcodegen_cx.module.declare_func_in_func(pthread_mutex_lock, fx.bcx.func);
|
||||||
|
|
||||||
let atomic_mutex = fx.module.declare_data_in_func(atomic_mutex, fx.bcx.func);
|
let atomic_mutex = fxcodegen_cx.module.declare_data_in_func(atomic_mutex, fx.bcx.func);
|
||||||
let atomic_mutex = fx.bcx.ins().global_value(fx.module.target_config().pointer_type(), atomic_mutex);
|
let atomic_mutex = fx.bcx.ins().global_value(fxcodegen_cx.module.target_config().pointer_type(), atomic_mutex);
|
||||||
|
|
||||||
fx.bcx.ins().call(pthread_mutex_lock, &[atomic_mutex]);
|
fx.bcx.ins().call(pthread_mutex_lock, &[atomic_mutex]);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn unlock_global_lock(fx: &mut FunctionCx<'_, '_, impl Backend>) {
|
pub(crate) fn unlock_global_lock(fx: &mut FunctionCx<'_, '_, impl Backend>) {
|
||||||
let atomic_mutex = fx.module.declare_data(
|
let atomic_mutex = fxcodegen_cx.module.declare_data(
|
||||||
"__cg_clif_global_atomic_mutex",
|
"__cg_clif_global_atomic_mutex",
|
||||||
Linkage::Import,
|
Linkage::Import,
|
||||||
true,
|
true,
|
||||||
|
@ -114,18 +114,18 @@ pub(crate) fn unlock_global_lock(fx: &mut FunctionCx<'_, '_, impl Backend>) {
|
||||||
None,
|
None,
|
||||||
).unwrap();
|
).unwrap();
|
||||||
|
|
||||||
let pthread_mutex_unlock = fx.module.declare_function("pthread_mutex_unlock", Linkage::Import, &cranelift_codegen::ir::Signature {
|
let pthread_mutex_unlock = fxcodegen_cx.module.declare_function("pthread_mutex_unlock", Linkage::Import, &cranelift_codegen::ir::Signature {
|
||||||
call_conv: fx.module.target_config().default_call_conv,
|
call_conv: fxcodegen_cx.module.target_config().default_call_conv,
|
||||||
params: vec![
|
params: vec![
|
||||||
AbiParam::new(fx.module.target_config().pointer_type() /* *mut pthread_mutex_t */),
|
AbiParam::new(fxcodegen_cx.module.target_config().pointer_type() /* *mut pthread_mutex_t */),
|
||||||
],
|
],
|
||||||
returns: vec![AbiParam::new(types::I32 /* c_int */)],
|
returns: vec![AbiParam::new(types::I32 /* c_int */)],
|
||||||
}).unwrap();
|
}).unwrap();
|
||||||
|
|
||||||
let pthread_mutex_unlock = fx.module.declare_func_in_func(pthread_mutex_unlock, fx.bcx.func);
|
let pthread_mutex_unlock = fxcodegen_cx.module.declare_func_in_func(pthread_mutex_unlock, fx.bcx.func);
|
||||||
|
|
||||||
let atomic_mutex = fx.module.declare_data_in_func(atomic_mutex, fx.bcx.func);
|
let atomic_mutex = fxcodegen_cx.module.declare_data_in_func(atomic_mutex, fx.bcx.func);
|
||||||
let atomic_mutex = fx.bcx.ins().global_value(fx.module.target_config().pointer_type(), atomic_mutex);
|
let atomic_mutex = fx.bcx.ins().global_value(fxcodegen_cx.module.target_config().pointer_type(), atomic_mutex);
|
||||||
|
|
||||||
fx.bcx.ins().call(pthread_mutex_unlock, &[atomic_mutex]);
|
fx.bcx.ins().call(pthread_mutex_unlock, &[atomic_mutex]);
|
||||||
}
|
}
|
||||||
|
|
16
src/base.rs
16
src/base.rs
|
@ -13,8 +13,8 @@ pub(crate) fn trans_fn<'tcx, B: Backend + 'static>(
|
||||||
let mir = tcx.instance_mir(instance.def);
|
let mir = tcx.instance_mir(instance.def);
|
||||||
|
|
||||||
// Declare function
|
// Declare function
|
||||||
let (name, sig) = get_function_name_and_sig(tcx, cx.module.isa().triple(), instance, false);
|
let (name, sig) = get_function_name_and_sig(tcx, cxcodegen_cx.module.isa().triple(), instance, false);
|
||||||
let func_id = cx.module.declare_function(&name, linkage, &sig).unwrap();
|
let func_id = cxcodegen_cx.module.declare_function(&name, linkage, &sig).unwrap();
|
||||||
|
|
||||||
// Make FunctionBuilder
|
// Make FunctionBuilder
|
||||||
let context = &mut cx.cached_context;
|
let context = &mut cx.cached_context;
|
||||||
|
@ -30,12 +30,12 @@ pub(crate) fn trans_fn<'tcx, B: Backend + 'static>(
|
||||||
let block_map: IndexVec<BasicBlock, Block> = (0..mir.basic_blocks().len()).map(|_| bcx.create_block()).collect();
|
let block_map: IndexVec<BasicBlock, Block> = (0..mir.basic_blocks().len()).map(|_| bcx.create_block()).collect();
|
||||||
|
|
||||||
// Make FunctionCx
|
// Make FunctionCx
|
||||||
let pointer_type = cx.module.target_config().pointer_type();
|
let pointer_type = cxcodegen_cx.module.target_config().pointer_type();
|
||||||
let clif_comments = crate::pretty_clif::CommentWriter::new(tcx, instance);
|
let clif_comments = crate::pretty_clif::CommentWriter::new(tcx, instance);
|
||||||
|
|
||||||
let mut fx = FunctionCx {
|
let mut fx = FunctionCx {
|
||||||
tcx,
|
tcx,
|
||||||
module: &mut cx.module,
|
module: &mut cxcodegen_cx.module,
|
||||||
global_asm: &mut cx.global_asm,
|
global_asm: &mut cx.global_asm,
|
||||||
pointer_type,
|
pointer_type,
|
||||||
|
|
||||||
|
@ -98,10 +98,10 @@ pub(crate) fn trans_fn<'tcx, B: Backend + 'static>(
|
||||||
// instruction, which doesn't have an encoding.
|
// instruction, which doesn't have an encoding.
|
||||||
context.compute_cfg();
|
context.compute_cfg();
|
||||||
context.compute_domtree();
|
context.compute_domtree();
|
||||||
context.eliminate_unreachable_code(cx.module.isa()).unwrap();
|
context.eliminate_unreachable_code(cxcodegen_cx.module.isa()).unwrap();
|
||||||
|
|
||||||
// Define function
|
// Define function
|
||||||
let module = &mut cx.module;
|
let module = &mut cxcodegen_cx.module;
|
||||||
tcx.sess.time(
|
tcx.sess.time(
|
||||||
"define function",
|
"define function",
|
||||||
|| module.define_function(
|
|| module.define_function(
|
||||||
|
@ -115,14 +115,14 @@ pub(crate) fn trans_fn<'tcx, B: Backend + 'static>(
|
||||||
crate::pretty_clif::write_clif_file(
|
crate::pretty_clif::write_clif_file(
|
||||||
cxcodegen_cx.tcx,
|
cxcodegen_cx.tcx,
|
||||||
"opt",
|
"opt",
|
||||||
Some(cx.module.isa()),
|
Some(cxcodegen_cx.module.isa()),
|
||||||
instance,
|
instance,
|
||||||
&context,
|
&context,
|
||||||
&clif_comments,
|
&clif_comments,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Define debuginfo for function
|
// Define debuginfo for function
|
||||||
let isa = cx.module.isa();
|
let isa = cxcodegen_cx.module.isa();
|
||||||
let debug_context = &mut cx.debug_context;
|
let debug_context = &mut cx.debug_context;
|
||||||
let unwind_context = &mut cx.unwind_context;
|
let unwind_context = &mut cx.unwind_context;
|
||||||
tcx.sess.time("generate debug info", || {
|
tcx.sess.time("generate debug info", || {
|
||||||
|
|
|
@ -395,7 +395,7 @@ impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn triple(&self) -> &target_lexicon::Triple {
|
pub(crate) fn triple(&self) -> &target_lexicon::Triple {
|
||||||
self.module.isa().triple()
|
selfcodegen_cx.module.isa().triple()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn anonymous_str(&mut self, prefix: &str, msg: &str) -> Value {
|
pub(crate) fn anonymous_str(&mut self, prefix: &str, msg: &str) -> Value {
|
||||||
|
@ -408,7 +408,7 @@ impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
|
||||||
let mut data_ctx = DataContext::new();
|
let mut data_ctx = DataContext::new();
|
||||||
data_ctx.define(msg.as_bytes().to_vec().into_boxed_slice());
|
data_ctx.define(msg.as_bytes().to_vec().into_boxed_slice());
|
||||||
let msg_id = self
|
let msg_id = self
|
||||||
.module
|
codegen_cx.module
|
||||||
.declare_data(
|
.declare_data(
|
||||||
&format!("__{}_{:08x}", prefix, msg_hash),
|
&format!("__{}_{:08x}", prefix, msg_hash),
|
||||||
Linkage::Local,
|
Linkage::Local,
|
||||||
|
@ -419,9 +419,9 @@ impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Ignore DuplicateDefinition error, as the data will be the same
|
// Ignore DuplicateDefinition error, as the data will be the same
|
||||||
let _ = self.module.define_data(msg_id, &data_ctx);
|
let _ = selfcodegen_cx.module.define_data(msg_id, &data_ctx);
|
||||||
|
|
||||||
let local_msg_id = self.module.declare_data_in_func(msg_id, self.bcx.func);
|
let local_msg_id = selfcodegen_cx.module.declare_data_in_func(msg_id, self.bcx.func);
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
self.add_comment(local_msg_id, msg);
|
self.add_comment(local_msg_id, msg);
|
||||||
|
|
|
@ -67,8 +67,8 @@ pub(crate) fn codegen_tls_ref<'tcx>(
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
layout: TyAndLayout<'tcx>,
|
layout: TyAndLayout<'tcx>,
|
||||||
) -> CValue<'tcx> {
|
) -> CValue<'tcx> {
|
||||||
let data_id = data_id_for_static(fxcodegen_cx.tcx, fx.module, def_id, false);
|
let data_id = data_id_for_static(fxcodegen_cx.tcx, fxcodegen_cx.module, def_id, false);
|
||||||
let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
|
let local_data_id = fxcodegen_cx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
fx.add_comment(local_data_id, format!("tls {:?}", def_id));
|
fx.add_comment(local_data_id, format!("tls {:?}", def_id));
|
||||||
let tls_ptr = fx.bcx.ins().tls_value(fx.pointer_type, local_data_id);
|
let tls_ptr = fx.bcx.ins().tls_value(fx.pointer_type, local_data_id);
|
||||||
|
@ -80,8 +80,8 @@ fn codegen_static_ref<'tcx>(
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
layout: TyAndLayout<'tcx>,
|
layout: TyAndLayout<'tcx>,
|
||||||
) -> CPlace<'tcx> {
|
) -> CPlace<'tcx> {
|
||||||
let data_id = data_id_for_static(fxcodegen_cx.tcx, fx.module, def_id, false);
|
let data_id = data_id_for_static(fxcodegen_cx.tcx, fxcodegen_cx.module, def_id, false);
|
||||||
let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
|
let local_data_id = fxcodegen_cx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
fx.add_comment(local_data_id, format!("{:?}", def_id));
|
fx.add_comment(local_data_id, format!("{:?}", def_id));
|
||||||
let global_ptr = fx.bcx.ins().global_value(fx.pointer_type, local_data_id);
|
let global_ptr = fx.bcx.ins().global_value(fx.pointer_type, local_data_id);
|
||||||
|
@ -168,21 +168,21 @@ pub(crate) fn trans_const_value<'tcx>(
|
||||||
let base_addr = match alloc_kind {
|
let base_addr = match alloc_kind {
|
||||||
Some(GlobalAlloc::Memory(alloc)) => {
|
Some(GlobalAlloc::Memory(alloc)) => {
|
||||||
fx.constants_cx.todo.push(TodoItem::Alloc(ptr.alloc_id));
|
fx.constants_cx.todo.push(TodoItem::Alloc(ptr.alloc_id));
|
||||||
let data_id = data_id_for_alloc_id(fx.module, ptr.alloc_id, alloc.align, alloc.mutability);
|
let data_id = data_id_for_alloc_id(fxcodegen_cx.module, ptr.alloc_id, alloc.align, alloc.mutability);
|
||||||
let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
|
let local_data_id = fxcodegen_cx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
fx.add_comment(local_data_id, format!("{:?}", ptr.alloc_id));
|
fx.add_comment(local_data_id, format!("{:?}", ptr.alloc_id));
|
||||||
fx.bcx.ins().global_value(fx.pointer_type, local_data_id)
|
fx.bcx.ins().global_value(fx.pointer_type, local_data_id)
|
||||||
}
|
}
|
||||||
Some(GlobalAlloc::Function(instance)) => {
|
Some(GlobalAlloc::Function(instance)) => {
|
||||||
let func_id = crate::abi::import_function(fxcodegen_cx.tcx, fx.module, instance);
|
let func_id = crate::abi::import_function(fxcodegen_cx.tcx, fxcodegen_cx.module, instance);
|
||||||
let local_func_id = fx.module.declare_func_in_func(func_id, &mut fx.bcx.func);
|
let local_func_id = fxcodegen_cx.module.declare_func_in_func(func_id, &mut fx.bcx.func);
|
||||||
fx.bcx.ins().func_addr(fx.pointer_type, local_func_id)
|
fx.bcx.ins().func_addr(fx.pointer_type, local_func_id)
|
||||||
}
|
}
|
||||||
Some(GlobalAlloc::Static(def_id)) => {
|
Some(GlobalAlloc::Static(def_id)) => {
|
||||||
assert!(fxcodegen_cx.tcx.is_static(def_id));
|
assert!(fxcodegen_cx.tcx.is_static(def_id));
|
||||||
let data_id = data_id_for_static(fxcodegen_cx.tcx, fx.module, def_id, false);
|
let data_id = data_id_for_static(fxcodegen_cx.tcx, fxcodegen_cx.module, def_id, false);
|
||||||
let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
|
let local_data_id = fxcodegen_cx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
fx.add_comment(local_data_id, format!("{:?}", def_id));
|
fx.add_comment(local_data_id, format!("{:?}", def_id));
|
||||||
fx.bcx.ins().global_value(fx.pointer_type, local_data_id)
|
fx.bcx.ins().global_value(fx.pointer_type, local_data_id)
|
||||||
|
@ -217,9 +217,9 @@ fn pointer_for_allocation<'tcx>(
|
||||||
) -> crate::pointer::Pointer {
|
) -> crate::pointer::Pointer {
|
||||||
let alloc_id = fxcodegen_cx.tcx.create_memory_alloc(alloc);
|
let alloc_id = fxcodegen_cx.tcx.create_memory_alloc(alloc);
|
||||||
fx.constants_cx.todo.push(TodoItem::Alloc(alloc_id));
|
fx.constants_cx.todo.push(TodoItem::Alloc(alloc_id));
|
||||||
let data_id = data_id_for_alloc_id(fx.module, alloc_id, alloc.align, alloc.mutability);
|
let data_id = data_id_for_alloc_id(fxcodegen_cx.module, alloc_id, alloc.align, alloc.mutability);
|
||||||
|
|
||||||
let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
|
let local_data_id = fxcodegen_cx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
fx.add_comment(local_data_id, format!("{:?}", alloc_id));
|
fx.add_comment(local_data_id, format!("{:?}", alloc_id));
|
||||||
let global_ptr = fx.bcx.ins().global_value(fx.pointer_type, local_data_id);
|
let global_ptr = fx.bcx.ins().global_value(fx.pointer_type, local_data_id);
|
||||||
|
|
|
@ -38,9 +38,9 @@ fn codegen_mono_items<'tcx>(
|
||||||
match mono_item {
|
match mono_item {
|
||||||
MonoItem::Fn(instance) => {
|
MonoItem::Fn(instance) => {
|
||||||
let (name, sig) =
|
let (name, sig) =
|
||||||
get_function_name_and_sig(cxcodegen_cx.tcx, cx.module.isa().triple(), instance, false);
|
get_function_name_and_sig(cxcodegen_cx.tcx, cxcodegen_cx.module.isa().triple(), instance, false);
|
||||||
let linkage = crate::linkage::get_clif_linkage(mono_item, linkage, visibility);
|
let linkage = crate::linkage::get_clif_linkage(mono_item, linkage, visibility);
|
||||||
cx.module.declare_function(&name, linkage, &sig).unwrap();
|
cxcodegen_cx.module.declare_function(&name, linkage, &sig).unwrap();
|
||||||
}
|
}
|
||||||
MonoItem::Static(_) | MonoItem::GlobalAsm(_) => {}
|
MonoItem::Static(_) | MonoItem::GlobalAsm(_) => {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -169,12 +169,12 @@ fn call_inline_asm<'tcx>(
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
fx.add_comment(stack_slot, "inline asm scratch slot");
|
fx.add_comment(stack_slot, "inline asm scratch slot");
|
||||||
|
|
||||||
let inline_asm_func = fx.module.declare_function(asm_name, Linkage::Import, &Signature {
|
let inline_asm_func = fxcodegen_cx.module.declare_function(asm_name, Linkage::Import, &Signature {
|
||||||
call_conv: CallConv::SystemV,
|
call_conv: CallConv::SystemV,
|
||||||
params: vec![AbiParam::new(fx.pointer_type)],
|
params: vec![AbiParam::new(fx.pointer_type)],
|
||||||
returns: vec![],
|
returns: vec![],
|
||||||
}).unwrap();
|
}).unwrap();
|
||||||
let inline_asm_func = fx.module.declare_func_in_func(inline_asm_func, &mut fx.bcx.func);
|
let inline_asm_func = fxcodegen_cx.module.declare_func_in_func(inline_asm_func, &mut fx.bcx.func);
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
fx.add_comment(inline_asm_func, asm_name);
|
fx.add_comment(inline_asm_func, asm_name);
|
||||||
|
|
||||||
|
|
|
@ -494,10 +494,10 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
|
||||||
|
|
||||||
if intrinsic.contains("nonoverlapping") {
|
if intrinsic.contains("nonoverlapping") {
|
||||||
// FIXME emit_small_memcpy
|
// FIXME emit_small_memcpy
|
||||||
fx.bcx.call_memcpy(fx.module.target_config(), dst, src, byte_amount);
|
fx.bcx.call_memcpy(fxcodegen_cx.module.target_config(), dst, src, byte_amount);
|
||||||
} else {
|
} else {
|
||||||
// FIXME emit_small_memmove
|
// FIXME emit_small_memmove
|
||||||
fx.bcx.call_memmove(fx.module.target_config(), dst, src, byte_amount);
|
fx.bcx.call_memmove(fxcodegen_cx.module.target_config(), dst, src, byte_amount);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// NOTE: the volatile variants have src and dst swapped
|
// NOTE: the volatile variants have src and dst swapped
|
||||||
|
@ -513,10 +513,10 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
|
||||||
// FIXME make the copy actually volatile when using emit_small_mem{cpy,move}
|
// FIXME make the copy actually volatile when using emit_small_mem{cpy,move}
|
||||||
if intrinsic.contains("nonoverlapping") {
|
if intrinsic.contains("nonoverlapping") {
|
||||||
// FIXME emit_small_memcpy
|
// FIXME emit_small_memcpy
|
||||||
fx.bcx.call_memcpy(fx.module.target_config(), dst, src, byte_amount);
|
fx.bcx.call_memcpy(fxcodegen_cx.module.target_config(), dst, src, byte_amount);
|
||||||
} else {
|
} else {
|
||||||
// FIXME emit_small_memmove
|
// FIXME emit_small_memmove
|
||||||
fx.bcx.call_memmove(fx.module.target_config(), dst, src, byte_amount);
|
fx.bcx.call_memmove(fxcodegen_cx.module.target_config(), dst, src, byte_amount);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
discriminant_value, (c ptr) {
|
discriminant_value, (c ptr) {
|
||||||
|
@ -680,7 +680,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
|
||||||
let dst_ptr = dst.load_scalar(fx);
|
let dst_ptr = dst.load_scalar(fx);
|
||||||
// FIXME make the memset actually volatile when switching to emit_small_memset
|
// FIXME make the memset actually volatile when switching to emit_small_memset
|
||||||
// FIXME use emit_small_memset
|
// FIXME use emit_small_memset
|
||||||
fx.bcx.call_memset(fx.module.target_config(), dst_ptr, val, count);
|
fx.bcx.call_memset(fxcodegen_cx.module.target_config(), dst_ptr, val, count);
|
||||||
};
|
};
|
||||||
ctlz | ctlz_nonzero, <T> (v arg) {
|
ctlz | ctlz_nonzero, <T> (v arg) {
|
||||||
// FIXME trap on `ctlz_nonzero` with zero arg.
|
// FIXME trap on `ctlz_nonzero` with zero arg.
|
||||||
|
|
|
@ -160,8 +160,8 @@ impl<'tcx, B: Backend + 'static> CodegenCx<'tcx, B> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn finalize(mut self) -> (Module<B>, String, Option<DebugContext<'tcx>>, UnwindContext<'tcx>) {
|
fn finalize(mut self) -> (Module<B>, String, Option<DebugContext<'tcx>>, UnwindContext<'tcx>) {
|
||||||
self.constants_cx.finalize(selfcodegen_cx.tcx, &mut self.module);
|
self.constants_cx.finalize(selfcodegen_cx.tcx, &mut selfcodegen_cx.module);
|
||||||
(self.module, self.global_asm, self.debug_context, self.unwind_context)
|
(selfcodegen_cx.module, self.global_asm, self.debug_context, self.unwind_context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::prelude::*;
|
||||||
|
|
||||||
fn codegen_print(fx: &mut FunctionCx<'_, '_, impl cranelift_module::Backend>, msg: &str) {
|
fn codegen_print(fx: &mut FunctionCx<'_, '_, impl cranelift_module::Backend>, msg: &str) {
|
||||||
let puts = fx
|
let puts = fx
|
||||||
.module
|
codegen_cx.module
|
||||||
.declare_function(
|
.declare_function(
|
||||||
"puts",
|
"puts",
|
||||||
Linkage::Import,
|
Linkage::Import,
|
||||||
|
@ -13,7 +13,7 @@ fn codegen_print(fx: &mut FunctionCx<'_, '_, impl cranelift_module::Backend>, ms
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let puts = fx.module.declare_func_in_func(puts, &mut fx.bcx.func);
|
let puts = fxcodegen_cx.module.declare_func_in_func(puts, &mut fx.bcx.func);
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
fx.add_comment(puts, "puts");
|
fx.add_comment(puts, "puts");
|
||||||
|
|
|
@ -595,7 +595,7 @@ impl<'tcx> CPlace<'tcx> {
|
||||||
let src_align = src_layout.align.abi.bytes() as u8;
|
let src_align = src_layout.align.abi.bytes() as u8;
|
||||||
let dst_align = dst_layout.align.abi.bytes() as u8;
|
let dst_align = dst_layout.align.abi.bytes() as u8;
|
||||||
fx.bcx.emit_small_memory_copy(
|
fx.bcx.emit_small_memory_copy(
|
||||||
fx.module.target_config(),
|
fxcodegen_cx.module.target_config(),
|
||||||
to_addr,
|
to_addr,
|
||||||
from_addr,
|
from_addr,
|
||||||
size,
|
size,
|
||||||
|
|
|
@ -80,7 +80,7 @@ pub(crate) fn get_vtable<'tcx>(
|
||||||
data_id
|
data_id
|
||||||
};
|
};
|
||||||
|
|
||||||
let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
|
let local_data_id = fxcodegen_cx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
|
||||||
fx.bcx.ins().global_value(fx.pointer_type, local_data_id)
|
fx.bcx.ins().global_value(fx.pointer_type, local_data_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ fn build_vtable<'tcx>(
|
||||||
let usize_size = fx.layout_of(fxcodegen_cx.tcx.types.usize).size.bytes() as usize;
|
let usize_size = fx.layout_of(fxcodegen_cx.tcx.types.usize).size.bytes() as usize;
|
||||||
|
|
||||||
let drop_in_place_fn =
|
let drop_in_place_fn =
|
||||||
import_function(tcx, fx.module, Instance::resolve_drop_in_place(tcx, layout.ty).polymorphize(fxcodegen_cx.tcx));
|
import_function(tcx, fxcodegen_cx.module, Instance::resolve_drop_in_place(tcx, layout.ty).polymorphize(fxcodegen_cx.tcx));
|
||||||
|
|
||||||
let mut components: Vec<_> = vec![Some(drop_in_place_fn), None, None];
|
let mut components: Vec<_> = vec![Some(drop_in_place_fn), None, None];
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ fn build_vtable<'tcx>(
|
||||||
opt_mth.map_or(None, |(def_id, substs)| {
|
opt_mth.map_or(None, |(def_id, substs)| {
|
||||||
Some(import_function(
|
Some(import_function(
|
||||||
tcx,
|
tcx,
|
||||||
fx.module,
|
fxcodegen_cx.module,
|
||||||
Instance::resolve_for_vtable(tcx, ParamEnv::reveal_all(), def_id, substs).unwrap().polymorphize(fxcodegen_cx.tcx),
|
Instance::resolve_for_vtable(tcx, ParamEnv::reveal_all(), def_id, substs).unwrap().polymorphize(fxcodegen_cx.tcx),
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
|
@ -127,13 +127,13 @@ fn build_vtable<'tcx>(
|
||||||
|
|
||||||
for (i, component) in components.into_iter().enumerate() {
|
for (i, component) in components.into_iter().enumerate() {
|
||||||
if let Some(func_id) = component {
|
if let Some(func_id) = component {
|
||||||
let func_ref = fx.module.declare_func_in_data(func_id, &mut data_ctx);
|
let func_ref = fxcodegen_cx.module.declare_func_in_data(func_id, &mut data_ctx);
|
||||||
data_ctx.write_function_addr((i * usize_size) as u32, func_ref);
|
data_ctx.write_function_addr((i * usize_size) as u32, func_ref);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let data_id = fx
|
let data_id = fx
|
||||||
.module
|
codegen_cx.module
|
||||||
.declare_data(
|
.declare_data(
|
||||||
&format!(
|
&format!(
|
||||||
"__vtable.{}.for.{:?}.{}",
|
"__vtable.{}.for.{:?}.{}",
|
||||||
|
@ -159,7 +159,7 @@ fn build_vtable<'tcx>(
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
fx.module.define_data(data_id, &data_ctx).unwrap();
|
fxcodegen_cx.module.define_data(data_id, &data_ctx).unwrap();
|
||||||
|
|
||||||
data_id
|
data_id
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue