Skip to content

Commit 0686d5d

Browse files
committed
Update cranelift
1 parent 9fde038 commit 0686d5d

File tree

9 files changed

+52
-1309
lines changed

9 files changed

+52
-1309
lines changed

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,16 @@ fn codegen_stmt<'tcx>(
919919
}
920920
}
921921
StatementKind::Coverage { .. } => fx.tcx.sess.fatal("-Zcoverage is unimplemented"),
922+
StatementKind::CopyNonOverlapping(box rustc_middle::mir::CopyNonOverlapping {
923+
src,
924+
dst,
925+
count,
926+
}) => {
927+
let dst = codegen_operand(fx, dst).load_scalar(fx);
928+
let src = codegen_operand(fx, src).load_scalar(fx);
929+
let count = codegen_operand(fx, count).load_scalar(fx);
930+
fx.bcx.call_memcpy(fx.cx.module.target_config(), dst, src, count);
931+
}
922932
}
923933
}
924934

compiler/rustc_codegen_cranelift/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#![warn(rust_2018_idioms)]
1111
#![warn(unused_lifetimes)]
1212
#![warn(unreachable_pub)]
13+
#![feature(box_patterns)]
1314

1415
#[cfg(feature = "jit")]
1516
extern crate libc;

compiler/rustc_codegen_ssa/src/mir/statement.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,23 +118,22 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
118118
mir::StatementKind::CopyNonOverlapping(box mir::CopyNonOverlapping {
119119
ref src,
120120
ref dst,
121-
ref size,
121+
ref count,
122122
}) => {
123123
let dst_val = self.codegen_operand(&mut bx, dst);
124124
let src_val = self.codegen_operand(&mut bx, src);
125-
let size_val = self.codegen_operand(&mut bx, size);
126-
let size = size_val.immediate_or_packed_pair(&mut bx);
125+
let count_val = self.codegen_operand(&mut bx, count);
126+
let count = count_val.immediate_or_packed_pair(&mut bx);
127127
let dst = dst_val.immediate_or_packed_pair(&mut bx);
128128
let src = src_val.immediate_or_packed_pair(&mut bx);
129129
use crate::MemFlags;
130-
let flags =
131-
(!MemFlags::UNALIGNED) & (!MemFlags::VOLATILE) & (!MemFlags::NONTEMPORAL);
130+
let flags = MemFlags::empty();
132131
bx.memcpy(
133132
dst,
134133
dst_val.layout.layout.align.pref,
135134
src,
136135
src_val.layout.layout.align.pref,
137-
size,
136+
count,
138137
flags,
139138
);
140139
bx

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,8 +1641,10 @@ impl Debug for Statement<'_> {
16411641
CopyNonOverlapping(box crate::mir::CopyNonOverlapping {
16421642
ref src,
16431643
ref dst,
1644-
ref size,
1645-
}) => write!(fmt, "copy_nonoverlapping(src={:?}, dst={:?}, size={:?})", src, dst, size),
1644+
ref count,
1645+
}) => {
1646+
write!(fmt, "copy_nonoverlapping(src={:?}, dst={:?}, count={:?})", src, dst, count)
1647+
}
16461648
Nop => write!(fmt, "nop"),
16471649
}
16481650
}
@@ -1658,7 +1660,8 @@ pub struct Coverage {
16581660
pub struct CopyNonOverlapping<'tcx> {
16591661
pub src: Operand<'tcx>,
16601662
pub dst: Operand<'tcx>,
1661-
pub size: Operand<'tcx>,
1663+
/// Number of elements to copy from src to dest, not bytes.
1664+
pub count: Operand<'tcx>,
16621665
}
16631666

16641667
///////////////////////////////////////////////////////////////////////////

compiler/rustc_middle/src/mir/visit.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -437,17 +437,11 @@ macro_rules! make_mir_visitor {
437437
StatementKind::CopyNonOverlapping(box crate::mir::CopyNonOverlapping{
438438
ref $($mutability)? src,
439439
ref $($mutability)? dst,
440-
ref $($mutability)? size,
440+
ref $($mutability)? count,
441441
}) => {
442-
self.visit_operand(
443-
src,
444-
location
445-
);
446-
self.visit_operand(
447-
dst,
448-
location
449-
);
450-
self.visit_operand(size, location)
442+
self.visit_operand(src, location);
443+
self.visit_operand(dst, location);
444+
self.visit_operand(count, location)
451445
}
452446
StatementKind::Nop => {}
453447
}

compiler/rustc_mir/src/borrow_check/invalidation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
9595
StatementKind::CopyNonOverlapping(box rustc_middle::mir::CopyNonOverlapping {
9696
ref src,
9797
ref dst,
98-
ref size,
98+
ref count,
9999
}) => {
100100
self.consume_operand(location, src);
101101
self.consume_operand(location, dst);
102-
self.consume_operand(location, size);
102+
self.consume_operand(location, count);
103103
match dst {
104104
Operand::Move(ref place) | Operand::Copy(ref place) => {
105105
self.mutate_place(location, *place, Deep, JustWrite);

compiler/rustc_mir/src/interpret/step.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -114,28 +114,36 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
114114
}
115115

116116
// Call CopyNonOverlapping
117-
CopyNonOverlapping(box rustc_middle::mir::CopyNonOverlapping { dst, src, size }) => {
118-
let size = self.eval_operand(size, None)?;
117+
CopyNonOverlapping(box rustc_middle::mir::CopyNonOverlapping { dst, src, count }) => {
118+
let (src, size) = {
119+
let src = self.eval_operand(src, None)?;
120+
let size = src.layout.layout.size;
121+
let mplace = *src.assert_mem_place(self);
122+
let ptr = match mplace.ptr {
123+
Scalar::Ptr(ptr) => ptr,
124+
_ => panic!(),
125+
};
126+
(ptr, size)
127+
};
119128

120129
let dst = {
121130
let dst = self.eval_operand(dst, None)?;
122131
let mplace = *dst.assert_mem_place(self);
123132
match mplace.ptr {
124-
Scalar::Ptr(ptr) => ptr,
125-
_ => panic!(),
133+
Scalar::Ptr(ptr) => ptr,
134+
_ => panic!(),
126135
}
127136
};
128-
let src = {
129-
let src = self.eval_operand(src, None)?;
130-
let mplace = *src.assert_mem_place(self);
131-
match mplace.ptr {
132-
Scalar::Ptr(ptr) => ptr,
133-
_ => panic!(),
134-
}
137+
138+
let count = self.eval_operand(count, None)?;
139+
let count = self.read_immediate(count)?.to_scalar()?;
140+
let count = if let Scalar::Int(i) = count {
141+
core::convert::TryFrom::try_from(i).unwrap()
142+
} else {
143+
panic!();
135144
};
136-
// Not sure how to convert an MPlaceTy<'_, <M as Machine<'_, '_>>::PointerTag>
137-
// to a pointer, or OpTy to a size
138-
self.memory.copy(src, dst, size.layout.layout.size, /*nonoverlapping*/ true)?;
145+
146+
self.memory.copy_repeatedly(src, dst, size, count, /*nonoverlapping*/ true)?;
139147
}
140148

141149
// Statements we do not track.

0 commit comments

Comments
 (0)