Skip to content

Commit 516988b

Browse files
committed
Impl StatementKind::CopyNonOverlapping
1 parent 5233edc commit 516988b

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
@@ -1515,6 +1515,11 @@ pub enum StatementKind<'tcx> {
15151515
/// counter varible at runtime, each time the code region is executed.
15161516
Coverage(Box<Coverage>),
15171517

1518+
/// Denotes a call to the intrinsic function copy_overlapping, where `src_dst` denotes the
1519+
/// memory being read from and written to(one field to save memory), and size
1520+
/// indicates how many bytes are being copied over.
1521+
CopyNonOverlapping(Box<CopyNonOverlapping<'tcx>>),
1522+
15181523
/// No-op. Useful for deleting instructions without affecting statement indices.
15191524
Nop,
15201525
}
@@ -1633,6 +1638,11 @@ impl Debug for Statement<'_> {
16331638
write!(fmt, "Coverage::{:?}", coverage.kind)
16341639
}
16351640
}
1641+
CopyNonOverlapping(box crate::mir::CopyNonOverlapping {
1642+
ref src,
1643+
ref dst,
1644+
ref size,
1645+
}) => write!(fmt, "src {:?} -> dst {:?}, {:?} bytes", src, dst, size),
16361646
Nop => write!(fmt, "nop"),
16371647
}
16381648
}
@@ -1644,6 +1654,13 @@ pub struct Coverage {
16441654
pub code_region: Option<CodeRegion>,
16451655
}
16461656

1657+
#[derive(Clone, Debug, PartialEq, TyEncodable, TyDecodable, HashStable, TypeFoldable)]
1658+
pub struct CopyNonOverlapping<'tcx> {
1659+
pub src: Place<'tcx>,
1660+
pub dst: Place<'tcx>,
1661+
pub size: Operand<'tcx>,
1662+
}
1663+
16471664
///////////////////////////////////////////////////////////////////////////
16481665
// Places
16491666

compiler/rustc_middle/src/mir/visit.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,23 @@ macro_rules! make_mir_visitor {
434434
location
435435
)
436436
}
437+
StatementKind::CopyNonOverlapping(box crate::mir::CopyNonOverlapping{
438+
ref $($mutability)? src,
439+
ref $($mutability)? dst,
440+
ref $($mutability)? size,
441+
}) => {
442+
self.visit_place(
443+
src,
444+
PlaceContext::NonMutatingUse(NonMutatingUseContext::CopyNonOverlapping),
445+
location
446+
);
447+
self.visit_place(
448+
dst,
449+
PlaceContext::MutatingUse(MutatingUseContext::CopyNonOverlapping),
450+
location
451+
);
452+
self.visit_operand(size, location)
453+
}
437454
StatementKind::Nop => {}
438455
}
439456
}
@@ -1149,6 +1166,8 @@ pub enum NonMutatingUseContext {
11491166
/// f(&x.y);
11501167
///
11511168
Projection,
1169+
/// Source from copy_nonoverlapping.
1170+
CopyNonOverlapping,
11521171
}
11531172

11541173
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
@@ -1178,6 +1197,8 @@ pub enum MutatingUseContext {
11781197
Projection,
11791198
/// Retagging, a "Stacked Borrows" shadow state operation
11801199
Retag,
1200+
/// Memory written to in copy_nonoverlapping.
1201+
CopyNonOverlapping,
11811202
}
11821203

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

0 commit comments

Comments
 (0)