]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_codegen_llvm/mir/operand.rs
Generalized base.rs#call_memcpy and everything that it uses
[rust.git] / src / librustc_codegen_llvm / mir / operand.rs
index 32609b06952beacf40a5093b0023bcf9be52e97a..e640b72cd44587a5c58e4e9c60d64a9b3eb77ceb 100644 (file)
@@ -21,6 +21,8 @@
 use type_::Type;
 use glue;
 
+use traits::BuilderMethods;
+
 use std::fmt;
 
 use super::{FunctionCx, LocalRef};
@@ -260,7 +262,11 @@ pub fn store(self, bx: &Builder<'a, 'll, 'tcx>, dest: PlaceRef<'tcx, &'ll Value>
         self.store_with_flags(bx, dest, MemFlags::empty());
     }
 
-    pub fn volatile_store(self, bx: &Builder<'a, 'll, 'tcx>, dest: PlaceRef<'tcx, &'ll Value>) {
+    pub fn volatile_store(
+        self,
+        bx: &Builder<'a, 'll, 'tcx, &'ll Value>,
+        dest: PlaceRef<'tcx, &'ll Value>
+    ) {
         self.store_with_flags(bx, dest, MemFlags::VOLATILE);
     }
 
@@ -271,14 +277,23 @@ pub fn unaligned_volatile_store(
     ) {
         self.store_with_flags(bx, dest, MemFlags::VOLATILE | MemFlags::UNALIGNED);
     }
+}
 
-    pub fn nontemporal_store(self, bx: &Builder<'a, 'll, 'tcx>, dest: PlaceRef<'tcx, &'ll Value>) {
+impl<'a, 'll: 'a, 'tcx: 'll, Value : ?Sized> OperandValue<&'ll Value> where
+    Value : ValueTrait,
+    Builder<'a, 'll, 'tcx, &'ll Value>: BuilderMethods<'a, 'll, 'tcx, Value>
+{
+    pub fn nontemporal_store(
+        self,
+        bx: &Builder<'a, 'll, 'tcx, &'ll Value>,
+        dest: PlaceRef<'tcx, &'ll Value>
+    ) {
         self.store_with_flags(bx, dest, MemFlags::NONTEMPORAL);
     }
 
-    fn store_with_flags(
+    fn store_with_flags<Builder: BuilderMethods<'a, 'll, 'tcx, Value>>(
         self,
-        bx: &Builder<'a, 'll, 'tcx>,
+        bx: &Builder,
         dest: PlaceRef<'tcx, &'ll Value>,
         flags: MemFlags,
     ) {
@@ -309,11 +324,13 @@ fn store_with_flags(
             }
         }
     }
+}
 
+impl OperandValue<&'ll Value> {
     pub fn store_unsized(
         self,
-        bx: &Builder<'a, 'll, 'tcx>,
-        indirect_dest: PlaceRef<'tcx, &'ll Value>,
+        bx: &Builder<'a, 'll, 'tcx, &'ll Value>,
+        indirect_dest: PlaceRef<'tcx, &'ll Value>
     ) {
         debug!("OperandRef::store_unsized: operand={:?}, indirect_dest={:?}", self, indirect_dest);
         let flags = MemFlags::empty();
@@ -334,13 +351,13 @@ pub fn store_unsized(
         let min_align = Align::from_bits(8, 8).unwrap();
 
         // Allocate an appropriate region on the stack, and copy the value into it
-        let (llsize, _) = glue::size_and_align_of_dst(&bx, unsized_ty, Some(llextra));
+        let (llsize, _) = glue::size_and_align_of_dst(bx, unsized_ty, Some(llextra));
         let lldst = bx.array_alloca(Type::i8(bx.cx), llsize, "unsized_tmp", max_align);
-        base::call_memcpy(&bx, lldst, max_align, llptr, min_align, llsize, flags);
+        base::call_memcpy(bx, lldst, max_align, llptr, min_align, llsize, flags);
 
         // Store the allocated region and the extra to the indirect place.
         let indirect_operand = OperandValue::Pair(lldst, llextra);
-        indirect_operand.store(&bx, indirect_dest);
+        indirect_operand.store(bx, indirect_dest);
     }
 }