Skip to content

Commit fdd0f8a

Browse files
committed
Slightly reduce the amount of fx.module references
1 parent f505157 commit fdd0f8a

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

src/base.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,15 @@ pub(crate) fn codegen_fn<'tcx>(
4949
(0..mir.basic_blocks().len()).map(|_| bcx.create_block()).collect();
5050

5151
// Make FunctionCx
52-
let pointer_type = module.target_config().pointer_type();
52+
let target_config = module.target_config();
53+
let pointer_type = target_config.pointer_type();
5354
let clif_comments = crate::pretty_clif::CommentWriter::new(tcx, instance);
5455

5556
let mut fx = FunctionCx {
5657
cx,
5758
module,
5859
tcx,
60+
target_config,
5961
pointer_type,
6062
constants_cx: ConstantCx::new(),
6163

@@ -676,7 +678,7 @@ fn codegen_stmt<'tcx>(
676678
// FIXME use emit_small_memset where possible
677679
let addr = lval.to_ptr().get_addr(fx);
678680
let val = operand.load_scalar(fx);
679-
fx.bcx.call_memset(fx.module.target_config(), addr, val, times);
681+
fx.bcx.call_memset(fx.target_config, addr, val, times);
680682
} else {
681683
let loop_block = fx.bcx.create_block();
682684
let loop_block2 = fx.bcx.create_block();
@@ -797,7 +799,7 @@ fn codegen_stmt<'tcx>(
797799
let elem_size: u64 = pointee.size.bytes();
798800
let bytes =
799801
if elem_size != 1 { fx.bcx.ins().imul_imm(count, elem_size as i64) } else { count };
800-
fx.bcx.call_memcpy(fx.module.target_config(), dst, src, bytes);
802+
fx.bcx.call_memcpy(fx.target_config, dst, src, bytes);
801803
}
802804
}
803805
}

src/common.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use cranelift_codegen::isa::TargetFrontendConfig;
12
use rustc_index::vec::IndexVec;
23
use rustc_middle::ty::layout::{
34
FnAbiError, FnAbiOfHelpers, FnAbiRequest, LayoutError, LayoutOfHelpers,
@@ -235,6 +236,7 @@ pub(crate) struct FunctionCx<'m, 'clif, 'tcx: 'm> {
235236
pub(crate) cx: &'clif mut crate::CodegenCx<'tcx>,
236237
pub(crate) module: &'m mut dyn Module,
237238
pub(crate) tcx: TyCtxt<'tcx>,
239+
pub(crate) target_config: TargetFrontendConfig, // Cached from module
238240
pub(crate) pointer_type: Type, // Cached from module
239241
pub(crate) constants_cx: ConstantCx,
240242

src/intrinsics/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -503,10 +503,10 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
503503

504504
if intrinsic == sym::copy_nonoverlapping {
505505
// FIXME emit_small_memcpy
506-
fx.bcx.call_memcpy(fx.module.target_config(), dst, src, byte_amount);
506+
fx.bcx.call_memcpy(fx.target_config, dst, src, byte_amount);
507507
} else {
508508
// FIXME emit_small_memmove
509-
fx.bcx.call_memmove(fx.module.target_config(), dst, src, byte_amount);
509+
fx.bcx.call_memmove(fx.target_config, dst, src, byte_amount);
510510
}
511511
};
512512
// NOTE: the volatile variants have src and dst swapped
@@ -522,10 +522,10 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
522522
// FIXME make the copy actually volatile when using emit_small_mem{cpy,move}
523523
if intrinsic == sym::volatile_copy_nonoverlapping_memory {
524524
// FIXME emit_small_memcpy
525-
fx.bcx.call_memcpy(fx.module.target_config(), dst, src, byte_amount);
525+
fx.bcx.call_memcpy(fx.target_config, dst, src, byte_amount);
526526
} else {
527527
// FIXME emit_small_memmove
528-
fx.bcx.call_memmove(fx.module.target_config(), dst, src, byte_amount);
528+
fx.bcx.call_memmove(fx.target_config, dst, src, byte_amount);
529529
}
530530
};
531531
size_of_val, <T> (c ptr) {
@@ -673,7 +673,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
673673
let dst_ptr = dst.load_scalar(fx);
674674
// FIXME make the memset actually volatile when switching to emit_small_memset
675675
// FIXME use emit_small_memset
676-
fx.bcx.call_memset(fx.module.target_config(), dst_ptr, val, count);
676+
fx.bcx.call_memset(fx.target_config, dst_ptr, val, count);
677677
};
678678
ctlz | ctlz_nonzero, <T> (v arg) {
679679
// FIXME trap on `ctlz_nonzero` with zero arg.

src/value_and_place.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ impl<'tcx> CPlace<'tcx> {
601601
let src_align = src_layout.align.abi.bytes() as u8;
602602
let dst_align = dst_layout.align.abi.bytes() as u8;
603603
fx.bcx.emit_small_memory_copy(
604-
fx.module.target_config(),
604+
fx.target_config,
605605
to_addr,
606606
from_addr,
607607
size,

0 commit comments

Comments
 (0)