Skip to content

Commit 0fdc07e

Browse files
committed
Impl StatementKind::CopyNonOverlapping
1 parent 3a5d45f commit 0fdc07e

File tree

4 files changed

+57
-2
lines changed

4 files changed

+57
-2
lines changed

compiler/rustc_codegen_ssa/src/mir/analyze.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,15 +293,17 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
293293
| MutatingUseContext::AsmOutput
294294
| MutatingUseContext::Borrow
295295
| MutatingUseContext::AddressOf
296-
| MutatingUseContext::Projection,
296+
| MutatingUseContext::Projection
297+
| MutatingUseContext::CopyNonOverlapping,
297298
)
298299
| PlaceContext::NonMutatingUse(
299300
NonMutatingUseContext::Inspect
300301
| NonMutatingUseContext::SharedBorrow
301302
| NonMutatingUseContext::UniqueBorrow
302303
| NonMutatingUseContext::ShallowBorrow
303304
| NonMutatingUseContext::AddressOf
304-
| NonMutatingUseContext::Projection,
305+
| NonMutatingUseContext::Projection
306+
| NonMutatingUseContext::CopyNonOverlapping,
305307
) => {
306308
self.not_ssa(local);
307309
}

compiler/rustc_codegen_ssa/src/mir/statement.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,21 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
115115
self.codegen_coverage(&mut bx, coverage.clone());
116116
bx
117117
}
118+
mir::StatementKind::CopyNonOverlapping(box mir::CopyNonOverlapping {
119+
ref src,
120+
ref dst,
121+
ref size,
122+
}) => {
123+
bx.memcpy(
124+
dst,
125+
todo!(),
126+
src,
127+
todo!(),
128+
size,
129+
todo!(),
130+
);
131+
bx
132+
}
118133
mir::StatementKind::FakeRead(..)
119134
| mir::StatementKind::Retag { .. }
120135
| mir::StatementKind::AscribeUserType(..)

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,6 +1541,11 @@ pub enum StatementKind<'tcx> {
15411541
/// counter varible at runtime, each time the code region is executed.
15421542
Coverage(Box<Coverage>),
15431543

1544+
/// Denotes a call to the intrinsic function copy_overlapping, where `src_dst` denotes the
1545+
/// memory being read from and written to(one field to save memory), and size
1546+
/// indicates how many bytes are being copied over.
1547+
CopyNonOverlapping(Box<CopyNonOverlapping<'tcx>>),
1548+
15441549
/// No-op. Useful for deleting instructions without affecting statement indices.
15451550
Nop,
15461551
}
@@ -1659,6 +1664,11 @@ impl Debug for Statement<'_> {
16591664
write!(fmt, "Coverage::{:?}", coverage.kind)
16601665
}
16611666
}
1667+
CopyNonOverlapping(box crate::mir::CopyNonOverlapping {
1668+
ref src,
1669+
ref dst,
1670+
ref size,
1671+
}) => write!(fmt, "src {:?} -> dst {:?}, {:?} bytes", src, dst, size),
16621672
Nop => write!(fmt, "nop"),
16631673
}
16641674
}
@@ -1670,6 +1680,13 @@ pub struct Coverage {
16701680
pub code_region: Option<CodeRegion>,
16711681
}
16721682

1683+
#[derive(Clone, Debug, PartialEq, TyEncodable, TyDecodable, HashStable, TypeFoldable)]
1684+
pub struct CopyNonOverlapping<'tcx> {
1685+
pub src: Place<'tcx>,
1686+
pub dst: Place<'tcx>,
1687+
pub size: Operand<'tcx>,
1688+
}
1689+
16731690
///////////////////////////////////////////////////////////////////////////
16741691
// Places
16751692

compiler/rustc_middle/src/mir/visit.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,23 @@ macro_rules! make_mir_visitor {
436436
location
437437
)
438438
}
439+
StatementKind::CopyNonOverlapping(box crate::mir::CopyNonOverlapping{
440+
ref $($mutability)? src,
441+
ref $($mutability)? dst,
442+
ref $($mutability)? size,
443+
}) => {
444+
self.visit_place(
445+
src,
446+
PlaceContext::NonMutatingUse(NonMutatingUseContext::CopyNonOverlapping),
447+
location
448+
);
449+
self.visit_place(
450+
dst,
451+
PlaceContext::MutatingUse(MutatingUseContext::CopyNonOverlapping),
452+
location
453+
);
454+
self.visit_operand(size, location)
455+
}
439456
StatementKind::Nop => {}
440457
}
441458
}
@@ -1151,6 +1168,8 @@ pub enum NonMutatingUseContext {
11511168
/// f(&x.y);
11521169
///
11531170
Projection,
1171+
/// Source from copy_nonoverlapping.
1172+
CopyNonOverlapping,
11541173
}
11551174

11561175
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
@@ -1180,6 +1199,8 @@ pub enum MutatingUseContext {
11801199
Projection,
11811200
/// Retagging, a "Stacked Borrows" shadow state operation
11821201
Retag,
1202+
/// Memory written to in copy_nonoverlapping.
1203+
CopyNonOverlapping,
11831204
}
11841205

11851206
#[derive(Copy, Clone, Debug, PartialEq, Eq)]

0 commit comments

Comments
 (0)