FunctionCx: Replace .module with .codegen_cx.module
MODIFY
src/abi/mod.rs
src/abi/mod.rs
@@ -226,9 +226,9 @@ pub(crate) fn import_function<'tcx>(
impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
/// Instance must be monomorphized
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
- .module
+ codegen_cx.module
.declare_func_in_func(func_id, &mut self.bcx.func);
#[cfg(debug_assertions)]
@@ -250,11 +250,11 @@ pub(crate) fn lib_call(
call_conv: CallConv::triple_default(self.triple()),
};
let func_id = self
- .module
+ codegen_cx.module
.declare_function(&name, Linkage::Import, &sig)
.unwrap();
let func_ref = self
- .module
+ codegen_cx.module
.declare_func_in_func(func_id, &mut self.bcx.func);
let call_inst = self.bcx.ins().call(func_ref, args);
#[cfg(debug_assertions)]

MODIFY
src/atomic_shim.rs
src/atomic_shim.rs
@@ -81,7 +81,7 @@ pub(crate) fn init_global_lock_constructor(
}
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",
Linkage::Import,
true,
@@ -89,24 +89,24 @@ pub(crate) fn lock_global_lock(fx: &mut FunctionCx<'_, '_, impl Backend>) {
None,
).unwrap();
- let pthread_mutex_lock = fx.module.declare_function("pthread_mutex_lock", Linkage::Import, &cranelift_codegen::ir::Signature {
- call_conv: fx.module.target_config().default_call_conv,
+ let pthread_mutex_lock = fxcodegen_cx.module.declare_function("pthread_mutex_lock", Linkage::Import, &cranelift_codegen::ir::Signature {
+ call_conv: fxcodegen_cx.module.target_config().default_call_conv,
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 */)],
}).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 = fx.bcx.ins().global_value(fx.module.target_config().pointer_type(), atomic_mutex);
+ let atomic_mutex = fxcodegen_cx.module.declare_data_in_func(atomic_mutex, fx.bcx.func);
+ 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]);
}
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",
Linkage::Import,
true,
@@ -114,18 +114,18 @@ pub(crate) fn unlock_global_lock(fx: &mut FunctionCx<'_, '_, impl Backend>) {
None,
).unwrap();
- let pthread_mutex_unlock = fx.module.declare_function("pthread_mutex_unlock", Linkage::Import, &cranelift_codegen::ir::Signature {
- call_conv: fx.module.target_config().default_call_conv,
+ let pthread_mutex_unlock = fxcodegen_cx.module.declare_function("pthread_mutex_unlock", Linkage::Import, &cranelift_codegen::ir::Signature {
+ call_conv: fxcodegen_cx.module.target_config().default_call_conv,
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 */)],
}).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 = fx.bcx.ins().global_value(fx.module.target_config().pointer_type(), atomic_mutex);
+ let atomic_mutex = fxcodegen_cx.module.declare_data_in_func(atomic_mutex, fx.bcx.func);
+ 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]);
}

MODIFY
src/base.rs
src/base.rs
@@ -13,8 +13,8 @@ pub(crate) fn trans_fn<'tcx, B: Backend + 'static>(
let mir = tcx.instance_mir(instance.def);
// Declare function
- let (name, sig) = get_function_name_and_sig(tcx, cx.module.isa().triple(), instance, false);
- let func_id = cx.module.declare_function(&name, linkage, &sig).unwrap();
+ let (name, sig) = get_function_name_and_sig(tcx, cxcodegen_cx.module.isa().triple(), instance, false);
+ let func_id = cxcodegen_cx.module.declare_function(&name, linkage, &sig).unwrap();
// Make FunctionBuilder
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();
// 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 mut fx = FunctionCx {
tcx,
- module: &mut cx.module,
+ module: &mut cxcodegen_cx.module,
global_asm: &mut cx.global_asm,
pointer_type,
@@ -98,10 +98,10 @@ pub(crate) fn trans_fn<'tcx, B: Backend + 'static>(
// instruction, which doesn't have an encoding.
context.compute_cfg();
context.compute_domtree();
- context.eliminate_unreachable_code(cx.module.isa()).unwrap();
+ context.eliminate_unreachable_code(cxcodegen_cx.module.isa()).unwrap();
// Define function
- let module = &mut cx.module;
+ let module = &mut cxcodegen_cx.module;
tcx.sess.time(
"define function",
|| module.define_function(
@@ -115,14 +115,14 @@ pub(crate) fn trans_fn<'tcx, B: Backend + 'static>(
crate::pretty_clif::write_clif_file(
cxcodegen_cx.tcx,
"opt",
- Some(cx.module.isa()),
+ Some(cxcodegen_cx.module.isa()),
instance,
&context,
&clif_comments,
);
// Define debuginfo for function
- let isa = cx.module.isa();
+ let isa = cxcodegen_cx.module.isa();
let debug_context = &mut cx.debug_context;
let unwind_context = &mut cx.unwind_context;
tcx.sess.time("generate debug info", || {

MODIFY
src/common.rs
src/common.rs
@@ -395,7 +395,7 @@ pub(crate) fn get_caller_location(&mut self, span: Span) -> CValue<'tcx> {
}
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 {
@@ -408,7 +408,7 @@ pub(crate) fn anonymous_str(&mut self, prefix: &str, msg: &str) -> Value {
let mut data_ctx = DataContext::new();
data_ctx.define(msg.as_bytes().to_vec().into_boxed_slice());
let msg_id = self
- .module
+ codegen_cx.module
.declare_data(
&format!("__{}_{:08x}", prefix, msg_hash),
Linkage::Local,
@@ -419,9 +419,9 @@ pub(crate) fn anonymous_str(&mut self, prefix: &str, msg: &str) -> Value {
.unwrap();
// 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)]
{
self.add_comment(local_msg_id, msg);

MODIFY
src/constant.rs
src/constant.rs
@@ -67,8 +67,8 @@ pub(crate) fn codegen_tls_ref<'tcx>(
def_id: DefId,
layout: TyAndLayout<'tcx>,
) -> CValue<'tcx> {
- let data_id = data_id_for_static(fxcodegen_cx.tcx, fx.module, def_id, false);
- let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
+ let data_id = data_id_for_static(fxcodegen_cx.tcx, fxcodegen_cx.module, def_id, false);
+ let local_data_id = fxcodegen_cx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
#[cfg(debug_assertions)]
fx.add_comment(local_data_id, format!("tls {:?}", def_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,
layout: TyAndLayout<'tcx>,
) -> CPlace<'tcx> {
- let data_id = data_id_for_static(fxcodegen_cx.tcx, fx.module, def_id, false);
- let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
+ let data_id = data_id_for_static(fxcodegen_cx.tcx, fxcodegen_cx.module, def_id, false);
+ let local_data_id = fxcodegen_cx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
#[cfg(debug_assertions)]
fx.add_comment(local_data_id, format!("{:?}", def_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 {
Some(GlobalAlloc::Memory(alloc)) => {
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 local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
+ let data_id = data_id_for_alloc_id(fxcodegen_cx.module, ptr.alloc_id, alloc.align, alloc.mutability);
+ let local_data_id = fxcodegen_cx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
#[cfg(debug_assertions)]
fx.add_comment(local_data_id, format!("{:?}", ptr.alloc_id));
fx.bcx.ins().global_value(fx.pointer_type, local_data_id)
}
Some(GlobalAlloc::Function(instance)) => {
- let func_id = crate::abi::import_function(fxcodegen_cx.tcx, fx.module, instance);
- let local_func_id = fx.module.declare_func_in_func(func_id, &mut fx.bcx.func);
+ let func_id = crate::abi::import_function(fxcodegen_cx.tcx, fxcodegen_cx.module, instance);
+ 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)
}
Some(GlobalAlloc::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 local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
+ let data_id = data_id_for_static(fxcodegen_cx.tcx, fxcodegen_cx.module, def_id, false);
+ let local_data_id = fxcodegen_cx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
#[cfg(debug_assertions)]
fx.add_comment(local_data_id, format!("{:?}", def_id));
fx.bcx.ins().global_value(fx.pointer_type, local_data_id)
@@ -217,9 +217,9 @@ fn pointer_for_allocation<'tcx>(
) -> crate::pointer::Pointer {
let alloc_id = fxcodegen_cx.tcx.create_memory_alloc(alloc);
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)]
fx.add_comment(local_data_id, format!("{:?}", alloc_id));
let global_ptr = fx.bcx.ins().global_value(fx.pointer_type, local_data_id);

MODIFY
src/driver/mod.rs
src/driver/mod.rs
@@ -38,9 +38,9 @@ fn codegen_mono_items<'tcx>(
match mono_item {
MonoItem::Fn(instance) => {
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);
- cx.module.declare_function(&name, linkage, &sig).unwrap();
+ cxcodegen_cx.module.declare_function(&name, linkage, &sig).unwrap();
}
MonoItem::Static(_) | MonoItem::GlobalAsm(_) => {}
}

MODIFY
src/inline_asm.rs
src/inline_asm.rs
@@ -169,12 +169,12 @@ fn call_inline_asm<'tcx>(
#[cfg(debug_assertions)]
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,
params: vec![AbiParam::new(fx.pointer_type)],
returns: vec![],
}).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)]
fx.add_comment(inline_asm_func, asm_name);

MODIFY
src/intrinsics/mod.rs
src/intrinsics/mod.rs
@@ -494,10 +494,10 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
if intrinsic.contains("nonoverlapping") {
// 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 {
// 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
@@ -513,10 +513,10 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
// FIXME make the copy actually volatile when using emit_small_mem{cpy,move}
if intrinsic.contains("nonoverlapping") {
// 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 {
// 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) {
@@ -680,7 +680,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
let dst_ptr = dst.load_scalar(fx);
// FIXME make the memset actually volatile when switching to 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) {
// FIXME trap on `ctlz_nonzero` with zero arg.

MODIFY
src/lib.rs
src/lib.rs
@@ -160,8 +160,8 @@ fn new(
}
fn finalize(mut self) -> (Module<B>, String, Option<DebugContext<'tcx>>, UnwindContext<'tcx>) {
- self.constants_cx.finalize(selfcodegen_cx.tcx, &mut self.module);
- (self.module, self.global_asm, self.debug_context, self.unwind_context)
+ self.constants_cx.finalize(selfcodegen_cx.tcx, &mut selfcodegen_cx.module);
+ (selfcodegen_cx.module, self.global_asm, self.debug_context, self.unwind_context)
}
}

MODIFY
src/trap.rs
src/trap.rs
fn codegen_print(fx: &mut FunctionCx<'_, '_, impl cranelift_module::Backend>, msg: &str) {
let puts = fx
- .module
+ codegen_cx.module
.declare_function(
"puts",
Linkage::Import,
@@ -13,7 +13,7 @@ fn codegen_print(fx: &mut FunctionCx<'_, '_, impl cranelift_module::Backend>, ms
},
)
.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)]
{
fx.add_comment(puts, "puts");

MODIFY
src/value_and_place.rs
src/value_and_place.rs
@@ -595,7 +595,7 @@ fn transmute_value<'tcx>(
let src_align = src_layout.align.abi.bytes() as u8;
let dst_align = dst_layout.align.abi.bytes() as u8;
fx.bcx.emit_small_memory_copy(
- fx.module.target_config(),
+ fxcodegen_cx.module.target_config(),
to_addr,
from_addr,
size,

MODIFY
src/vtable.rs
src/vtable.rs
@@ -80,7 +80,7 @@ pub(crate) fn get_vtable<'tcx>(
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)
}
@@ -93,7 +93,7 @@ fn build_vtable<'tcx>(
let usize_size = fx.layout_of(fxcodegen_cx.tcx.types.usize).size.bytes() as usize;
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];
@@ -108,7 +108,7 @@ fn build_vtable<'tcx>(
opt_mth.map_or(None, |(def_id, substs)| {
Some(import_function(
tcx,
- fx.module,
+ fxcodegen_cx.module,
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() {
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);
}
}
let data_id = fx
- .module
+ codegen_cx.module
.declare_data(
&format!(
"__vtable.{}.for.{:?}.{}",
@@ -159,7 +159,7 @@ fn build_vtable<'tcx>(
)
.unwrap();
- fx.module.define_data(data_id, &data_ctx).unwrap();
+ fxcodegen_cx.module.define_data(data_id, &data_ctx).unwrap();
data_id
}

FunctionCx: Replace .module with .codegen_cx.module