From 0fdc07e197e3d0265452e266d038b089b69da6cb Mon Sep 17 00:00:00 2001 From: kadmin Date: Sat, 3 Oct 2020 20:57:47 +0000 Subject: [PATCH] Impl StatementKind::CopyNonOverlapping --- compiler/rustc_codegen_ssa/src/mir/analyze.rs | 6 ++++-- .../rustc_codegen_ssa/src/mir/statement.rs | 15 +++++++++++++ compiler/rustc_middle/src/mir/mod.rs | 17 +++++++++++++++ compiler/rustc_middle/src/mir/visit.rs | 21 +++++++++++++++++++ 4 files changed, 57 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/mir/analyze.rs b/compiler/rustc_codegen_ssa/src/mir/analyze.rs index 289629d9215..5ad9f461472 100644 --- a/compiler/rustc_codegen_ssa/src/mir/analyze.rs +++ b/compiler/rustc_codegen_ssa/src/mir/analyze.rs @@ -293,7 +293,8 @@ fn visit_local(&mut self, &local: &mir::Local, context: PlaceContext, location: | MutatingUseContext::AsmOutput | MutatingUseContext::Borrow | MutatingUseContext::AddressOf - | MutatingUseContext::Projection, + | MutatingUseContext::Projection + | MutatingUseContext::CopyNonOverlapping, ) | PlaceContext::NonMutatingUse( NonMutatingUseContext::Inspect @@ -301,7 +302,8 @@ fn visit_local(&mut self, &local: &mir::Local, context: PlaceContext, location: | NonMutatingUseContext::UniqueBorrow | NonMutatingUseContext::ShallowBorrow | NonMutatingUseContext::AddressOf - | NonMutatingUseContext::Projection, + | NonMutatingUseContext::Projection + | NonMutatingUseContext::CopyNonOverlapping, ) => { self.not_ssa(local); } diff --git a/compiler/rustc_codegen_ssa/src/mir/statement.rs b/compiler/rustc_codegen_ssa/src/mir/statement.rs index 6f74ba77d4c..2c90054b6c7 100644 --- a/compiler/rustc_codegen_ssa/src/mir/statement.rs +++ b/compiler/rustc_codegen_ssa/src/mir/statement.rs @@ -115,6 +115,21 @@ pub fn codegen_statement(&mut self, mut bx: Bx, statement: &mir::Statement<'tcx> self.codegen_coverage(&mut bx, coverage.clone()); bx } + mir::StatementKind::CopyNonOverlapping(box mir::CopyNonOverlapping { + ref src, + ref dst, + ref size, + }) => { + bx.memcpy( + dst, + todo!(), + src, + todo!(), + size, + todo!(), + ); + bx + } mir::StatementKind::FakeRead(..) | mir::StatementKind::Retag { .. } | mir::StatementKind::AscribeUserType(..) diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 42bbc9a0d95..90111d4080c 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -1541,6 +1541,11 @@ pub enum StatementKind<'tcx> { /// counter varible at runtime, each time the code region is executed. Coverage(Box), + /// Denotes a call to the intrinsic function copy_overlapping, where `src_dst` denotes the + /// memory being read from and written to(one field to save memory), and size + /// indicates how many bytes are being copied over. + CopyNonOverlapping(Box>), + /// No-op. Useful for deleting instructions without affecting statement indices. Nop, } @@ -1659,6 +1664,11 @@ fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result { write!(fmt, "Coverage::{:?}", coverage.kind) } } + CopyNonOverlapping(box crate::mir::CopyNonOverlapping { + ref src, + ref dst, + ref size, + }) => write!(fmt, "src {:?} -> dst {:?}, {:?} bytes", src, dst, size), Nop => write!(fmt, "nop"), } } @@ -1670,6 +1680,13 @@ pub struct Coverage { pub code_region: Option, } +#[derive(Clone, Debug, PartialEq, TyEncodable, TyDecodable, HashStable, TypeFoldable)] +pub struct CopyNonOverlapping<'tcx> { + pub src: Place<'tcx>, + pub dst: Place<'tcx>, + pub size: Operand<'tcx>, +} + /////////////////////////////////////////////////////////////////////////// // Places diff --git a/compiler/rustc_middle/src/mir/visit.rs b/compiler/rustc_middle/src/mir/visit.rs index 464220cf77e..ad773adcd82 100644 --- a/compiler/rustc_middle/src/mir/visit.rs +++ b/compiler/rustc_middle/src/mir/visit.rs @@ -436,6 +436,23 @@ fn super_statement(&mut self, location ) } + StatementKind::CopyNonOverlapping(box crate::mir::CopyNonOverlapping{ + ref $($mutability)? src, + ref $($mutability)? dst, + ref $($mutability)? size, + }) => { + self.visit_place( + src, + PlaceContext::NonMutatingUse(NonMutatingUseContext::CopyNonOverlapping), + location + ); + self.visit_place( + dst, + PlaceContext::MutatingUse(MutatingUseContext::CopyNonOverlapping), + location + ); + self.visit_operand(size, location) + } StatementKind::Nop => {} } } @@ -1151,6 +1168,8 @@ pub enum NonMutatingUseContext { /// f(&x.y); /// Projection, + /// Source from copy_nonoverlapping. + CopyNonOverlapping, } #[derive(Copy, Clone, Debug, PartialEq, Eq)] @@ -1180,6 +1199,8 @@ pub enum MutatingUseContext { Projection, /// Retagging, a "Stacked Borrows" shadow state operation Retag, + /// Memory written to in copy_nonoverlapping. + CopyNonOverlapping, } #[derive(Copy, Clone, Debug, PartialEq, Eq)]