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 {
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.
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).
// 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)
};
//
// `(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)