rustc_trans: avoid sizing_type_of everywhere possible.
This commit is contained in:
parent
49872b859e
commit
c977daf97c
14 changed files with 53 additions and 82 deletions
|
@ -439,14 +439,10 @@ impl FnType {
|
||||||
match ret_ty.sty {
|
match ret_ty.sty {
|
||||||
// These are not really pointers but pairs, (pointer, len)
|
// These are not really pointers but pairs, (pointer, len)
|
||||||
ty::TyRef(_, ty::TypeAndMut { ty, .. }) => {
|
ty::TyRef(_, ty::TypeAndMut { ty, .. }) => {
|
||||||
let llty = type_of::sizing_type_of(ccx, ty);
|
ret.attrs.set_dereferenceable(ccx.size_of(ty));
|
||||||
let llsz = llsize_of_alloc(ccx, llty);
|
|
||||||
ret.attrs.set_dereferenceable(llsz);
|
|
||||||
}
|
}
|
||||||
ty::TyAdt(def, _) if def.is_box() => {
|
ty::TyAdt(def, _) if def.is_box() => {
|
||||||
let llty = type_of::sizing_type_of(ccx, ret_ty.boxed_ty());
|
ret.attrs.set_dereferenceable(ccx.size_of(ret_ty.boxed_ty()));
|
||||||
let llsz = llsize_of_alloc(ccx, llty);
|
|
||||||
ret.attrs.set_dereferenceable(llsz);
|
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
@ -517,9 +513,7 @@ impl FnType {
|
||||||
args.push(info);
|
args.push(info);
|
||||||
} else {
|
} else {
|
||||||
if let Some(inner) = rust_ptr_attrs(ty, &mut arg) {
|
if let Some(inner) = rust_ptr_attrs(ty, &mut arg) {
|
||||||
let llty = type_of::sizing_type_of(ccx, inner);
|
arg.attrs.set_dereferenceable(ccx.size_of(inner));
|
||||||
let llsz = llsize_of_alloc(ccx, llty);
|
|
||||||
arg.attrs.set_dereferenceable(llsz);
|
|
||||||
}
|
}
|
||||||
args.push(arg);
|
args.push(arg);
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ use std;
|
||||||
|
|
||||||
use llvm::{ValueRef, True, IntEQ, IntNE};
|
use llvm::{ValueRef, True, IntEQ, IntNE};
|
||||||
use rustc::ty::layout;
|
use rustc::ty::layout;
|
||||||
use rustc::ty::{self, Ty, AdtKind};
|
use rustc::ty::{self, Ty};
|
||||||
use common::*;
|
use common::*;
|
||||||
use builder::Builder;
|
use builder::Builder;
|
||||||
use base;
|
use base;
|
||||||
|
@ -285,11 +285,6 @@ pub fn trans_get_discr<'a, 'tcx>(
|
||||||
cast_to: Option<Type>,
|
cast_to: Option<Type>,
|
||||||
range_assert: bool
|
range_assert: bool
|
||||||
) -> ValueRef {
|
) -> ValueRef {
|
||||||
let (def, substs) = match t.sty {
|
|
||||||
ty::TyAdt(ref def, substs) if def.adt_kind() == AdtKind::Enum => (def, substs),
|
|
||||||
_ => bug!("{} is not an enum", t)
|
|
||||||
};
|
|
||||||
|
|
||||||
debug!("trans_get_discr t: {:?}", t);
|
debug!("trans_get_discr t: {:?}", t);
|
||||||
let l = bcx.ccx.layout_of(t);
|
let l = bcx.ccx.layout_of(t);
|
||||||
|
|
||||||
|
@ -297,19 +292,17 @@ pub fn trans_get_discr<'a, 'tcx>(
|
||||||
layout::CEnum { discr, min, max, .. } => {
|
layout::CEnum { discr, min, max, .. } => {
|
||||||
load_discr(bcx, discr, scrutinee, alignment, min, max, range_assert)
|
load_discr(bcx, discr, scrutinee, alignment, min, max, range_assert)
|
||||||
}
|
}
|
||||||
layout::General { discr, .. } => {
|
layout::General { discr, ref variants, .. } => {
|
||||||
let ptr = bcx.struct_gep(scrutinee, 0);
|
let ptr = bcx.struct_gep(scrutinee, 0);
|
||||||
load_discr(bcx, discr, ptr, alignment,
|
load_discr(bcx, discr, ptr, alignment,
|
||||||
0, def.variants.len() as u64 - 1,
|
0, variants.len() as u64 - 1,
|
||||||
range_assert)
|
range_assert)
|
||||||
}
|
}
|
||||||
layout::Univariant { .. } | layout::UntaggedUnion { .. } => C_u8(bcx.ccx, 0),
|
layout::Univariant { .. } | layout::UntaggedUnion { .. } => C_u8(bcx.ccx, 0),
|
||||||
layout::RawNullablePointer { nndiscr, .. } => {
|
layout::RawNullablePointer { nndiscr, .. } => {
|
||||||
let cmp = if nndiscr == 0 { IntEQ } else { IntNE };
|
let cmp = if nndiscr == 0 { IntEQ } else { IntNE };
|
||||||
let llptrty = type_of::sizing_type_of(bcx.ccx,
|
let discr = bcx.load(scrutinee, alignment.to_align());
|
||||||
monomorphize::field_ty(bcx.tcx(), substs,
|
bcx.icmp(cmp, discr, C_null(val_ty(discr)))
|
||||||
&def.variants[nndiscr as usize].fields[0]));
|
|
||||||
bcx.icmp(cmp, bcx.load(scrutinee, alignment.to_align()), C_null(llptrty))
|
|
||||||
}
|
}
|
||||||
layout::StructWrappedNullablePointer { nndiscr, ref discrfield, .. } => {
|
layout::StructWrappedNullablePointer { nndiscr, ref discrfield, .. } => {
|
||||||
struct_wrapped_nullable_bitdiscr(bcx, nndiscr, discrfield, scrutinee, alignment)
|
struct_wrapped_nullable_bitdiscr(bcx, nndiscr, discrfield, scrutinee, alignment)
|
||||||
|
@ -383,9 +376,8 @@ pub fn trans_set_discr<'a, 'tcx>(bcx: &Builder<'a, 'tcx>, t: Ty<'tcx>, val: Valu
|
||||||
assert_eq!(to, Disr(0));
|
assert_eq!(to, Disr(0));
|
||||||
}
|
}
|
||||||
layout::RawNullablePointer { nndiscr, .. } => {
|
layout::RawNullablePointer { nndiscr, .. } => {
|
||||||
let nnty = compute_fields(bcx.ccx, t, nndiscr as usize, false)[0];
|
|
||||||
if to.0 != nndiscr {
|
if to.0 != nndiscr {
|
||||||
let llptrty = type_of::sizing_type_of(bcx.ccx, nnty);
|
let llptrty = val_ty(val).element_type();
|
||||||
bcx.store(C_null(llptrty), val, None);
|
bcx.store(C_null(llptrty), val, None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,6 @@ use context::{SharedCrateContext, CrateContextList};
|
||||||
use debuginfo;
|
use debuginfo;
|
||||||
use declare;
|
use declare;
|
||||||
use machine;
|
use machine;
|
||||||
use machine::llsize_of;
|
|
||||||
use meth;
|
use meth;
|
||||||
use mir;
|
use mir;
|
||||||
use monomorphize::{self, Instance};
|
use monomorphize::{self, Instance};
|
||||||
|
@ -534,14 +533,13 @@ pub fn memcpy_ty<'a, 'tcx>(
|
||||||
) {
|
) {
|
||||||
let ccx = bcx.ccx;
|
let ccx = bcx.ccx;
|
||||||
|
|
||||||
if type_is_zero_size(ccx, t) {
|
let size = ccx.size_of(t);
|
||||||
|
if size == 0 {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let llty = type_of::type_of(ccx, t);
|
let align = align.unwrap_or_else(|| ccx.align_of(t));
|
||||||
let llsz = llsize_of(ccx, llty);
|
call_memcpy(bcx, dst, src, C_uint(ccx, size), align);
|
||||||
let llalign = align.unwrap_or_else(|| type_of::align_of(ccx, t));
|
|
||||||
call_memcpy(bcx, dst, src, llsz, llalign as u32);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn call_memset<'a, 'tcx>(b: &Builder<'a, 'tcx>,
|
pub fn call_memset<'a, 'tcx>(b: &Builder<'a, 'tcx>,
|
||||||
|
|
|
@ -125,10 +125,8 @@ pub fn type_is_imm_pair<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>)
|
||||||
|
|
||||||
/// Identify types which have size zero at runtime.
|
/// Identify types which have size zero at runtime.
|
||||||
pub fn type_is_zero_size<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool {
|
pub fn type_is_zero_size<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool {
|
||||||
use machine::llsize_of_alloc;
|
let layout = ccx.layout_of(ty);
|
||||||
use type_of::sizing_type_of;
|
!layout.is_unsized() && layout.size(&ccx.tcx().data_layout).bytes() == 0
|
||||||
let llty = sizing_type_of(ccx, ty);
|
|
||||||
llsize_of_alloc(ccx, llty) == 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -255,7 +255,7 @@ pub fn trans_static<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
||||||
ccx.statics_to_rauw().borrow_mut().push((g, new_g));
|
ccx.statics_to_rauw().borrow_mut().push((g, new_g));
|
||||||
new_g
|
new_g
|
||||||
};
|
};
|
||||||
llvm::LLVMSetAlignment(g, type_of::align_of(ccx, ty));
|
llvm::LLVMSetAlignment(g, ccx.align_of(ty));
|
||||||
llvm::LLVMSetInitializer(g, v);
|
llvm::LLVMSetInitializer(g, v);
|
||||||
|
|
||||||
// As an optimization, all shared statics which do not have interior
|
// As an optimization, all shared statics which do not have interior
|
||||||
|
|
|
@ -1772,7 +1772,7 @@ pub fn create_global_var_metadata(cx: &CrateContext,
|
||||||
let var_name = CString::new(var_name).unwrap();
|
let var_name = CString::new(var_name).unwrap();
|
||||||
let linkage_name = CString::new(linkage_name).unwrap();
|
let linkage_name = CString::new(linkage_name).unwrap();
|
||||||
|
|
||||||
let global_align = type_of::align_of(cx, variable_type);
|
let global_align = cx.align_of(variable_type);
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
llvm::LLVMRustDIBuilderCreateStaticVariable(DIB(cx),
|
llvm::LLVMRustDIBuilderCreateStaticVariable(DIB(cx),
|
||||||
|
|
|
@ -449,7 +449,7 @@ pub fn declare_local<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
|
||||||
LocalVariable |
|
LocalVariable |
|
||||||
CapturedVariable => (0, DW_TAG_auto_variable)
|
CapturedVariable => (0, DW_TAG_auto_variable)
|
||||||
};
|
};
|
||||||
let align = ::type_of::align_of(cx, variable_type);
|
let align = cx.align_of(variable_type);
|
||||||
|
|
||||||
let name = CString::new(variable_name.as_str().as_bytes()).unwrap();
|
let name = CString::new(variable_name.as_str().as_bytes()).unwrap();
|
||||||
match (variable_access, &[][..]) {
|
match (variable_access, &[][..]) {
|
||||||
|
|
|
@ -19,10 +19,8 @@ use llvm::{ValueRef};
|
||||||
use rustc::traits;
|
use rustc::traits;
|
||||||
use rustc::ty::{self, Ty, TypeFoldable};
|
use rustc::ty::{self, Ty, TypeFoldable};
|
||||||
use common::*;
|
use common::*;
|
||||||
use machine::*;
|
|
||||||
use meth;
|
use meth;
|
||||||
use monomorphize;
|
use monomorphize;
|
||||||
use type_of::{sizing_type_of, align_of};
|
|
||||||
use value::Value;
|
use value::Value;
|
||||||
use builder::Builder;
|
use builder::Builder;
|
||||||
|
|
||||||
|
@ -69,9 +67,8 @@ pub fn size_and_align_of_dst<'a, 'tcx>(bcx: &Builder<'a, 'tcx>, t: Ty<'tcx>, inf
|
||||||
debug!("calculate size of DST: {}; with lost info: {:?}",
|
debug!("calculate size of DST: {}; with lost info: {:?}",
|
||||||
t, Value(info));
|
t, Value(info));
|
||||||
if bcx.ccx.shared().type_is_sized(t) {
|
if bcx.ccx.shared().type_is_sized(t) {
|
||||||
let sizing_type = sizing_type_of(bcx.ccx, t);
|
let size = bcx.ccx.size_of(t);
|
||||||
let size = llsize_of_alloc(bcx.ccx, sizing_type);
|
let align = bcx.ccx.align_of(t);
|
||||||
let align = align_of(bcx.ccx, t);
|
|
||||||
debug!("size_and_align_of_dst t={} info={:?} size: {} align: {}",
|
debug!("size_and_align_of_dst t={} info={:?} size: {} align: {}",
|
||||||
t, Value(info), size, align);
|
t, Value(info), size, align);
|
||||||
let size = C_uint(bcx.ccx, size);
|
let size = C_uint(bcx.ccx, size);
|
||||||
|
@ -82,9 +79,8 @@ pub fn size_and_align_of_dst<'a, 'tcx>(bcx: &Builder<'a, 'tcx>, t: Ty<'tcx>, inf
|
||||||
ty::TyAdt(def, substs) => {
|
ty::TyAdt(def, substs) => {
|
||||||
let ccx = bcx.ccx;
|
let ccx = bcx.ccx;
|
||||||
// First get the size of all statically known fields.
|
// First get the size of all statically known fields.
|
||||||
// Don't use type_of::sizing_type_of because that expects t to be sized,
|
// Don't use size_of because it also rounds up to alignment, which we
|
||||||
// and it also rounds up to alignment, which we want to avoid,
|
// want to avoid, as the unsized field's alignment could be smaller.
|
||||||
// as the unsized field's alignment could be smaller.
|
|
||||||
assert!(!t.is_simd());
|
assert!(!t.is_simd());
|
||||||
let layout = ccx.layout_of(t);
|
let layout = ccx.layout_of(t);
|
||||||
debug!("DST {} layout: {:?}", t, layout);
|
debug!("DST {} layout: {:?}", t, layout);
|
||||||
|
@ -154,14 +150,11 @@ pub fn size_and_align_of_dst<'a, 'tcx>(bcx: &Builder<'a, 'tcx>, t: Ty<'tcx>, inf
|
||||||
(meth::SIZE.get_usize(bcx, info), meth::ALIGN.get_usize(bcx, info))
|
(meth::SIZE.get_usize(bcx, info), meth::ALIGN.get_usize(bcx, info))
|
||||||
}
|
}
|
||||||
ty::TySlice(_) | ty::TyStr => {
|
ty::TySlice(_) | ty::TyStr => {
|
||||||
let unit_ty = t.sequence_element_type(bcx.tcx());
|
let unit = t.sequence_element_type(bcx.tcx());
|
||||||
// The info in this case is the length of the str, so the size is that
|
// The info in this case is the length of the str, so the size is that
|
||||||
// times the unit size.
|
// times the unit size.
|
||||||
let llunit_ty = sizing_type_of(bcx.ccx, unit_ty);
|
(bcx.mul(info, C_uint(bcx.ccx, bcx.ccx.size_of(unit))),
|
||||||
let unit_align = llalign_of_min(bcx.ccx, llunit_ty);
|
C_uint(bcx.ccx, bcx.ccx.align_of(unit)))
|
||||||
let unit_size = llsize_of_alloc(bcx.ccx, llunit_ty);
|
|
||||||
(bcx.mul(info, C_uint(bcx.ccx, unit_size)),
|
|
||||||
C_uint(bcx.ccx, unit_align))
|
|
||||||
}
|
}
|
||||||
_ => bug!("Unexpected unsized type, found {}", t)
|
_ => bug!("Unexpected unsized type, found {}", t)
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,7 +151,7 @@ pub fn trans_intrinsic_call<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
|
||||||
}
|
}
|
||||||
"min_align_of" => {
|
"min_align_of" => {
|
||||||
let tp_ty = substs.type_at(0);
|
let tp_ty = substs.type_at(0);
|
||||||
C_uint(ccx, type_of::align_of(ccx, tp_ty))
|
C_uint(ccx, ccx.align_of(tp_ty))
|
||||||
}
|
}
|
||||||
"min_align_of_val" => {
|
"min_align_of_val" => {
|
||||||
let tp_ty = substs.type_at(0);
|
let tp_ty = substs.type_at(0);
|
||||||
|
@ -160,7 +160,7 @@ pub fn trans_intrinsic_call<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
|
||||||
glue::size_and_align_of_dst(bcx, tp_ty, llargs[1]);
|
glue::size_and_align_of_dst(bcx, tp_ty, llargs[1]);
|
||||||
llalign
|
llalign
|
||||||
} else {
|
} else {
|
||||||
C_uint(ccx, type_of::align_of(ccx, tp_ty))
|
C_uint(ccx, ccx.align_of(tp_ty))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"pref_align_of" => {
|
"pref_align_of" => {
|
||||||
|
@ -234,7 +234,7 @@ pub fn trans_intrinsic_call<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
|
||||||
}
|
}
|
||||||
let load = bcx.volatile_load(ptr);
|
let load = bcx.volatile_load(ptr);
|
||||||
unsafe {
|
unsafe {
|
||||||
llvm::LLVMSetAlignment(load, type_of::align_of(ccx, tp_ty));
|
llvm::LLVMSetAlignment(load, ccx.align_of(tp_ty));
|
||||||
}
|
}
|
||||||
to_immediate(bcx, load, tp_ty)
|
to_immediate(bcx, load, tp_ty)
|
||||||
},
|
},
|
||||||
|
@ -252,7 +252,7 @@ pub fn trans_intrinsic_call<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
|
||||||
let ptr = bcx.pointercast(llargs[0], val_ty(val).ptr_to());
|
let ptr = bcx.pointercast(llargs[0], val_ty(val).ptr_to());
|
||||||
let store = bcx.volatile_store(val, ptr);
|
let store = bcx.volatile_store(val, ptr);
|
||||||
unsafe {
|
unsafe {
|
||||||
llvm::LLVMSetAlignment(store, type_of::align_of(ccx, tp_ty));
|
llvm::LLVMSetAlignment(store, ccx.align_of(tp_ty));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
C_nil(ccx)
|
C_nil(ccx)
|
||||||
|
@ -634,7 +634,7 @@ pub fn trans_intrinsic_call<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
|
||||||
if val_ty(llval) != Type::void(ccx) && machine::llsize_of_alloc(ccx, val_ty(llval)) != 0 {
|
if val_ty(llval) != Type::void(ccx) && machine::llsize_of_alloc(ccx, val_ty(llval)) != 0 {
|
||||||
if let Some(ty) = fn_ty.ret.cast {
|
if let Some(ty) = fn_ty.ret.cast {
|
||||||
let ptr = bcx.pointercast(llresult, ty.ptr_to());
|
let ptr = bcx.pointercast(llresult, ty.ptr_to());
|
||||||
bcx.store(llval, ptr, Some(type_of::align_of(ccx, ret_ty)));
|
bcx.store(llval, ptr, Some(ccx.align_of(ret_ty)));
|
||||||
} else {
|
} else {
|
||||||
store_ty(bcx, llval, llresult, Alignment::AbiAligned, ret_ty);
|
store_ty(bcx, llval, llresult, Alignment::AbiAligned, ret_ty);
|
||||||
}
|
}
|
||||||
|
@ -651,7 +651,7 @@ fn copy_intrinsic<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
|
||||||
-> ValueRef {
|
-> ValueRef {
|
||||||
let ccx = bcx.ccx;
|
let ccx = bcx.ccx;
|
||||||
let lltp_ty = type_of::type_of(ccx, tp_ty);
|
let lltp_ty = type_of::type_of(ccx, tp_ty);
|
||||||
let align = C_i32(ccx, type_of::align_of(ccx, tp_ty) as i32);
|
let align = C_i32(ccx, ccx.align_of(tp_ty) as i32);
|
||||||
let size = machine::llsize_of(ccx, lltp_ty);
|
let size = machine::llsize_of(ccx, lltp_ty);
|
||||||
let int_size = machine::llbitsize_of_real(ccx, ccx.int_type());
|
let int_size = machine::llbitsize_of_real(ccx, ccx.int_type());
|
||||||
|
|
||||||
|
@ -685,7 +685,7 @@ fn memset_intrinsic<'a, 'tcx>(
|
||||||
count: ValueRef
|
count: ValueRef
|
||||||
) -> ValueRef {
|
) -> ValueRef {
|
||||||
let ccx = bcx.ccx;
|
let ccx = bcx.ccx;
|
||||||
let align = C_i32(ccx, type_of::align_of(ccx, ty) as i32);
|
let align = C_i32(ccx, ccx.align_of(ty) as i32);
|
||||||
let lltp_ty = type_of::type_of(ccx, ty);
|
let lltp_ty = type_of::type_of(ccx, ty);
|
||||||
let size = machine::llsize_of(ccx, lltp_ty);
|
let size = machine::llsize_of(ccx, lltp_ty);
|
||||||
let dst = bcx.pointercast(dst, Type::i8p(ccx));
|
let dst = bcx.pointercast(dst, Type::i8p(ccx));
|
||||||
|
|
|
@ -17,7 +17,6 @@ use consts;
|
||||||
use machine;
|
use machine;
|
||||||
use monomorphize;
|
use monomorphize;
|
||||||
use type_::Type;
|
use type_::Type;
|
||||||
use type_of::*;
|
|
||||||
use value::Value;
|
use value::Value;
|
||||||
use rustc::ty;
|
use rustc::ty;
|
||||||
|
|
||||||
|
@ -80,14 +79,10 @@ pub fn get_vtable<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
||||||
// Not in the cache. Build it.
|
// Not in the cache. Build it.
|
||||||
let nullptr = C_null(Type::nil(ccx).ptr_to());
|
let nullptr = C_null(Type::nil(ccx).ptr_to());
|
||||||
|
|
||||||
let size_ty = sizing_type_of(ccx, ty);
|
|
||||||
let size = machine::llsize_of_alloc(ccx, size_ty);
|
|
||||||
let align = align_of(ccx, ty);
|
|
||||||
|
|
||||||
let mut components: Vec<_> = [
|
let mut components: Vec<_> = [
|
||||||
callee::get_fn(ccx, monomorphize::resolve_drop_in_place(ccx.shared(), ty)),
|
callee::get_fn(ccx, monomorphize::resolve_drop_in_place(ccx.shared(), ty)),
|
||||||
C_uint(ccx, size),
|
C_uint(ccx, ccx.size_of(ty)),
|
||||||
C_uint(ccx, align)
|
C_uint(ccx, ccx.align_of(ty))
|
||||||
].iter().cloned().collect();
|
].iter().cloned().collect();
|
||||||
|
|
||||||
if let Some(trait_ref) = trait_ref {
|
if let Some(trait_ref) = trait_ref {
|
||||||
|
|
|
@ -24,8 +24,8 @@ use consts;
|
||||||
use machine::llalign_of_min;
|
use machine::llalign_of_min;
|
||||||
use meth;
|
use meth;
|
||||||
use monomorphize;
|
use monomorphize;
|
||||||
|
use type_of;
|
||||||
use tvec;
|
use tvec;
|
||||||
use type_of::{self, align_of};
|
|
||||||
use type_::Type;
|
use type_::Type;
|
||||||
|
|
||||||
use rustc_data_structures::indexed_vec::IndexVec;
|
use rustc_data_structures::indexed_vec::IndexVec;
|
||||||
|
@ -910,7 +910,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
|
||||||
let cast_ptr = bcx.pointercast(dst.llval, llty.ptr_to());
|
let cast_ptr = bcx.pointercast(dst.llval, llty.ptr_to());
|
||||||
let in_type = val.ty;
|
let in_type = val.ty;
|
||||||
let out_type = dst.ty.to_ty(bcx.tcx());;
|
let out_type = dst.ty.to_ty(bcx.tcx());;
|
||||||
let llalign = cmp::min(align_of(bcx.ccx, in_type), align_of(bcx.ccx, out_type));
|
let llalign = cmp::min(bcx.ccx.align_of(in_type), bcx.ccx.align_of(out_type));
|
||||||
self.store_operand(bcx, cast_ptr, Some(llalign), val);
|
self.store_operand(bcx, cast_ptr, Some(llalign), val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -148,7 +148,7 @@ impl<'tcx> Const<'tcx> {
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, or if the value is not immediate, we create
|
// Otherwise, or if the value is not immediate, we create
|
||||||
// a constant LLVM global and cast its address if necessary.
|
// a constant LLVM global and cast its address if necessary.
|
||||||
let align = type_of::align_of(ccx, self.ty);
|
let align = ccx.align_of(self.ty);
|
||||||
let ptr = consts::addr_of(ccx, self.llval, align, "const");
|
let ptr = consts::addr_of(ccx, self.llval, align, "const");
|
||||||
OperandValue::Ref(consts::ptrcast(ptr, llty.ptr_to()), Alignment::AbiAligned)
|
OperandValue::Ref(consts::ptrcast(ptr, llty.ptr_to()), Alignment::AbiAligned)
|
||||||
};
|
};
|
||||||
|
@ -717,7 +717,7 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> {
|
||||||
Base::Value(llval) => {
|
Base::Value(llval) => {
|
||||||
// FIXME: may be wrong for &*(&simd_vec as &fmt::Debug)
|
// FIXME: may be wrong for &*(&simd_vec as &fmt::Debug)
|
||||||
let align = if self.ccx.shared().type_is_sized(ty) {
|
let align = if self.ccx.shared().type_is_sized(ty) {
|
||||||
type_of::align_of(self.ccx, ty)
|
self.ccx.align_of(ty)
|
||||||
} else {
|
} else {
|
||||||
self.ccx.tcx().data_layout.pointer_align.abi() as machine::llalign
|
self.ccx.tcx().data_layout.pointer_align.abi() as machine::llalign
|
||||||
};
|
};
|
||||||
|
@ -1022,25 +1022,20 @@ fn trans_const<'a, 'tcx>(
|
||||||
C_vector(vals)
|
C_vector(vals)
|
||||||
}
|
}
|
||||||
layout::RawNullablePointer { nndiscr, .. } => {
|
layout::RawNullablePointer { nndiscr, .. } => {
|
||||||
let nnty = adt::compute_fields(ccx, t, nndiscr as usize, false)[0];
|
|
||||||
if variant_index as u64 == nndiscr {
|
if variant_index as u64 == nndiscr {
|
||||||
assert_eq!(vals.len(), 1);
|
assert_eq!(vals.len(), 1);
|
||||||
vals[0]
|
vals[0]
|
||||||
} else {
|
} else {
|
||||||
C_null(type_of::sizing_type_of(ccx, nnty))
|
C_null(type_of::type_of(ccx, t))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
layout::StructWrappedNullablePointer { ref nonnull, nndiscr, .. } => {
|
layout::StructWrappedNullablePointer { ref nonnull, nndiscr, .. } => {
|
||||||
if variant_index as u64 == nndiscr {
|
if variant_index as u64 == nndiscr {
|
||||||
C_struct(ccx, &build_const_struct(ccx, &nonnull, vals), false)
|
C_struct(ccx, &build_const_struct(ccx, &nonnull, vals), false)
|
||||||
} else {
|
} else {
|
||||||
let fields = adt::compute_fields(ccx, t, nndiscr as usize, false);
|
// Always use null even if it's not the `discrfield`th
|
||||||
let vals = fields.iter().map(|&ty| {
|
// field; see #8506.
|
||||||
// Always use null even if it's not the `discrfield`th
|
C_null(type_of::type_of(ccx, t))
|
||||||
// field; see #8506.
|
|
||||||
C_null(type_of::sizing_type_of(ccx, ty))
|
|
||||||
}).collect::<Vec<ValueRef>>();
|
|
||||||
C_struct(ccx, &build_const_struct(ccx, &nonnull, &vals[..]), false)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => bug!("trans_const: cannot handle type {} repreented as {:#?}", t, l)
|
_ => bug!("trans_const: cannot handle type {} repreented as {:#?}", t, l)
|
||||||
|
|
|
@ -438,7 +438,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
|
||||||
let content_ty: Ty<'tcx> = self.monomorphize(&content_ty);
|
let content_ty: Ty<'tcx> = self.monomorphize(&content_ty);
|
||||||
let llty = type_of::type_of(bcx.ccx, content_ty);
|
let llty = type_of::type_of(bcx.ccx, content_ty);
|
||||||
let llsize = machine::llsize_of(bcx.ccx, llty);
|
let llsize = machine::llsize_of(bcx.ccx, llty);
|
||||||
let align = type_of::align_of(bcx.ccx, content_ty);
|
let align = bcx.ccx.align_of(content_ty);
|
||||||
let llalign = C_uint(bcx.ccx, align);
|
let llalign = C_uint(bcx.ccx, align);
|
||||||
let llty_ptr = llty.ptr_to();
|
let llty_ptr = llty.ptr_to();
|
||||||
let box_ty = bcx.tcx().mk_box(content_ty);
|
let box_ty = bcx.tcx().mk_box(content_ty);
|
||||||
|
|
|
@ -322,10 +322,16 @@ pub fn in_memory_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) ->
|
||||||
llty
|
llty
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn align_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>)
|
impl<'a, 'tcx> CrateContext<'a, 'tcx> {
|
||||||
-> machine::llalign {
|
pub fn align_of(&self, ty: Ty<'tcx>) -> machine::llalign {
|
||||||
let layout = cx.layout_of(t);
|
let layout = self.layout_of(ty);
|
||||||
layout.align(&cx.tcx().data_layout).abi() as machine::llalign
|
layout.align(&self.tcx().data_layout).abi() as machine::llalign
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn size_of(&self, ty: Ty<'tcx>) -> machine::llsize {
|
||||||
|
let layout = self.layout_of(ty);
|
||||||
|
layout.size(&self.tcx().data_layout).bytes() as machine::llsize
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn llvm_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>) -> String {
|
fn llvm_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>) -> String {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue