]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_codegen_llvm/glue.rs
Beginning of moving all backend-agnostic code to rustc_codegen_ssa
[rust.git] / src / librustc_codegen_llvm / glue.rs
index 842bdf3cb493ff1b01772c5d4026c8388ae440e3..5e1a03031dde6b7494558c9ae83880f63245b0f4 100644 (file)
 
 use std;
 
-use builder::Builder;
-use common::*;
-use llvm;
+use rustc_codegen_ssa::common::IntPredicate;
 use meth;
 use rustc::ty::layout::LayoutOf;
 use rustc::ty::{self, Ty};
-use value::Value;
+use interfaces::*;
 
-pub fn size_and_align_of_dst(bx: &Builder<'_, 'll, 'tcx>, t: Ty<'tcx>, info: Option<&'ll Value>)
-                                       -> (&'ll Value, &'ll Value) {
+pub fn size_and_align_of_dst<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
+    bx: &Bx,
+    t: Ty<'tcx>,
+    info: Option<Bx::Value>
+) -> (Bx::Value, Bx::Value) {
     debug!("calculate size of DST: {}; with lost info: {:?}",
            t, info);
-    if bx.cx.type_is_sized(t) {
-        let (size, align) = bx.cx.size_and_align_of(t);
+    if bx.cx().type_is_sized(t) {
+        let (size, align) = bx.cx().layout_of(t).size_and_align();
         debug!("size_and_align_of_dst t={} info={:?} size: {:?} align: {:?}",
                t, info, size, align);
-        let size = C_usize(bx.cx, size.bytes());
-        let align = C_usize(bx.cx, align.abi());
+        let size = bx.cx().const_usize(size.bytes());
+        let align = bx.cx().const_usize(align.abi());
         return (size, align);
     }
     match t.sty {
@@ -44,12 +45,12 @@ pub fn size_and_align_of_dst(bx: &Builder<'_, 'll, 'tcx>, t: Ty<'tcx>, info: Opt
             let unit = t.sequence_element_type(bx.tcx());
             // The info in this case is the length of the str, so the size is that
             // times the unit size.
-            let (size, align) = bx.cx.size_and_align_of(unit);
-            (bx.mul(info.unwrap(), C_usize(bx.cx, size.bytes())),
-             C_usize(bx.cx, align.abi()))
+            let (size, align) = bx.cx().layout_of(unit).size_and_align();
+            (bx.mul(info.unwrap(), bx.cx().const_usize(size.bytes())),
+             bx.cx().const_usize(align.abi()))
         }
         _ => {
-            let cx = bx.cx;
+            let cx = bx.cx();
             // First get the size of all statically known fields.
             // Don't use size_of because it also rounds up to alignment, which we
             // want to avoid, as the unsized field's alignment could be smaller.
@@ -62,8 +63,8 @@ pub fn size_and_align_of_dst(bx: &Builder<'_, 'll, 'tcx>, t: Ty<'tcx>, info: Opt
             let sized_align = layout.align.abi();
             debug!("DST {} statically sized prefix size: {} align: {}",
                    t, sized_size, sized_align);
-            let sized_size = C_usize(cx, sized_size);
-            let sized_align = C_usize(cx, sized_align);
+            let sized_size = cx.const_usize(sized_size);
+            let sized_align = cx.const_usize(sized_align);
 
             // Recurse to get the size of the dynamically sized field (must be
             // the last field).
@@ -89,14 +90,14 @@ pub fn size_and_align_of_dst(bx: &Builder<'_, 'll, 'tcx>, t: Ty<'tcx>, info: Opt
 
             // Choose max of two known alignments (combined value must
             // be aligned according to more restrictive of the two).
-            let align = match (const_to_opt_u128(sized_align, false),
-                               const_to_opt_u128(unsized_align, false)) {
+            let align = match (bx.cx().const_to_opt_u128(sized_align, false),
+                               bx.cx().const_to_opt_u128(unsized_align, false)) {
                 (Some(sized_align), Some(unsized_align)) => {
                     // If both alignments are constant, (the sized_align should always be), then
                     // pick the correct alignment statically.
-                    C_usize(cx, std::cmp::max(sized_align, unsized_align) as u64)
+                    cx.const_usize(std::cmp::max(sized_align, unsized_align) as u64)
                 }
-                _ => bx.select(bx.icmp(llvm::IntUGT, sized_align, unsized_align),
+                _ => bx.select(bx.icmp(IntPredicate::IntUGT, sized_align, unsized_align),
                                sized_align,
                                unsized_align)
             };
@@ -112,7 +113,7 @@ pub fn size_and_align_of_dst(bx: &Builder<'_, 'll, 'tcx>, t: Ty<'tcx>, info: Opt
             //
             //   `(size + (align-1)) & -align`
 
-            let addend = bx.sub(align, C_usize(bx.cx, 1));
+            let addend = bx.sub(align, bx.cx().const_usize(1));
             let size = bx.and(bx.add(size, addend), bx.neg(align));
 
             (size, align)