Merge commit '9a0c32934e
' into sync_cg_clif-2021-03-05
This commit is contained in:
commit
7a6ea77473
73 changed files with 1145 additions and 2596 deletions
|
@ -6,7 +6,7 @@ use cranelift_codegen::entity::EntityRef;
|
|||
use cranelift_codegen::ir::immediates::Offset32;
|
||||
|
||||
fn codegen_field<'tcx>(
|
||||
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
||||
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
||||
base: Pointer,
|
||||
extra: Option<Value>,
|
||||
layout: TyAndLayout<'tcx>,
|
||||
|
@ -15,11 +15,8 @@ fn codegen_field<'tcx>(
|
|||
let field_offset = layout.fields.offset(field.index());
|
||||
let field_layout = layout.field(&*fx, field.index());
|
||||
|
||||
let simple = |fx: &mut FunctionCx<'_, '_, _>| {
|
||||
(
|
||||
base.offset_i64(fx, i64::try_from(field_offset.bytes()).unwrap()),
|
||||
field_layout,
|
||||
)
|
||||
let simple = |fx: &mut FunctionCx<'_, '_, '_>| {
|
||||
(base.offset_i64(fx, i64::try_from(field_offset.bytes()).unwrap()), field_layout)
|
||||
};
|
||||
|
||||
if let Some(extra) = extra {
|
||||
|
@ -58,10 +55,7 @@ fn scalar_pair_calculate_b_offset(
|
|||
a_scalar: &Scalar,
|
||||
b_scalar: &Scalar,
|
||||
) -> Offset32 {
|
||||
let b_offset = a_scalar
|
||||
.value
|
||||
.size(&tcx)
|
||||
.align_to(b_scalar.value.align(&tcx).abi);
|
||||
let b_offset = a_scalar.value.size(&tcx).align_to(b_scalar.value.align(&tcx).abi);
|
||||
Offset32::new(b_offset.bytes().try_into().unwrap())
|
||||
}
|
||||
|
||||
|
@ -106,10 +100,7 @@ impl<'tcx> CValue<'tcx> {
|
|||
}
|
||||
|
||||
// FIXME remove
|
||||
pub(crate) fn force_stack(
|
||||
self,
|
||||
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
||||
) -> (Pointer, Option<Value>) {
|
||||
pub(crate) fn force_stack(self, fx: &mut FunctionCx<'_, '_, 'tcx>) -> (Pointer, Option<Value>) {
|
||||
let layout = self.1;
|
||||
match self.0 {
|
||||
CValueInner::ByRef(ptr, meta) => (ptr, meta),
|
||||
|
@ -129,7 +120,7 @@ impl<'tcx> CValue<'tcx> {
|
|||
}
|
||||
|
||||
/// Load a value with layout.abi of scalar
|
||||
pub(crate) fn load_scalar(self, fx: &mut FunctionCx<'_, 'tcx, impl Module>) -> Value {
|
||||
pub(crate) fn load_scalar(self, fx: &mut FunctionCx<'_, '_, 'tcx>) -> Value {
|
||||
let layout = self.1;
|
||||
match self.0 {
|
||||
CValueInner::ByRef(ptr, None) => {
|
||||
|
@ -153,10 +144,7 @@ impl<'tcx> CValue<'tcx> {
|
|||
}
|
||||
|
||||
/// Load a value pair with layout.abi of scalar pair
|
||||
pub(crate) fn load_scalar_pair(
|
||||
self,
|
||||
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
||||
) -> (Value, Value) {
|
||||
pub(crate) fn load_scalar_pair(self, fx: &mut FunctionCx<'_, '_, 'tcx>) -> (Value, Value) {
|
||||
let layout = self.1;
|
||||
match self.0 {
|
||||
CValueInner::ByRef(ptr, None) => {
|
||||
|
@ -183,7 +171,7 @@ impl<'tcx> CValue<'tcx> {
|
|||
|
||||
pub(crate) fn value_field(
|
||||
self,
|
||||
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
||||
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
||||
field: mir::Field,
|
||||
) -> CValue<'tcx> {
|
||||
let layout = self.1;
|
||||
|
@ -219,21 +207,17 @@ impl<'tcx> CValue<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn unsize_value(
|
||||
self,
|
||||
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
||||
dest: CPlace<'tcx>,
|
||||
) {
|
||||
pub(crate) fn unsize_value(self, fx: &mut FunctionCx<'_, '_, 'tcx>, dest: CPlace<'tcx>) {
|
||||
crate::unsize::coerce_unsized_into(fx, self, dest);
|
||||
}
|
||||
|
||||
/// If `ty` is signed, `const_val` must already be sign extended.
|
||||
pub(crate) fn const_val(
|
||||
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
||||
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
||||
layout: TyAndLayout<'tcx>,
|
||||
const_val: ty::ScalarInt,
|
||||
) -> CValue<'tcx> {
|
||||
assert_eq!(const_val.size(), layout.size);
|
||||
assert_eq!(const_val.size(), layout.size, "{:#?}: {:?}", const_val, layout);
|
||||
use cranelift_codegen::ir::immediates::{Ieee32, Ieee64};
|
||||
|
||||
let clif_ty = fx.clif_type(layout.ty).unwrap();
|
||||
|
@ -250,18 +234,11 @@ impl<'tcx> CValue<'tcx> {
|
|||
ty::Uint(UintTy::U128) | ty::Int(IntTy::I128) => {
|
||||
let const_val = const_val.to_bits(layout.size).unwrap();
|
||||
let lsb = fx.bcx.ins().iconst(types::I64, const_val as u64 as i64);
|
||||
let msb = fx
|
||||
.bcx
|
||||
.ins()
|
||||
.iconst(types::I64, (const_val >> 64) as u64 as i64);
|
||||
let msb = fx.bcx.ins().iconst(types::I64, (const_val >> 64) as u64 as i64);
|
||||
fx.bcx.ins().iconcat(lsb, msb)
|
||||
}
|
||||
ty::Bool | ty::Char | ty::Uint(_) | ty::Int(_) | ty::Ref(..)
|
||||
| ty::RawPtr(..) => {
|
||||
fx
|
||||
.bcx
|
||||
.ins()
|
||||
.iconst(clif_ty, const_val.to_bits(layout.size).unwrap() as i64)
|
||||
ty::Bool | ty::Char | ty::Uint(_) | ty::Int(_) | ty::Ref(..) | ty::RawPtr(..) => {
|
||||
fx.bcx.ins().iconst(clif_ty, const_val.to_bits(layout.size).unwrap() as i64)
|
||||
}
|
||||
ty::Float(FloatTy::F32) => {
|
||||
fx.bcx.ins().f32const(Ieee32::with_bits(u32::try_from(const_val).unwrap()))
|
||||
|
@ -279,14 +256,8 @@ impl<'tcx> CValue<'tcx> {
|
|||
}
|
||||
|
||||
pub(crate) fn cast_pointer_to(self, layout: TyAndLayout<'tcx>) -> Self {
|
||||
assert!(matches!(
|
||||
self.layout().ty.kind(),
|
||||
ty::Ref(..) | ty::RawPtr(..) | ty::FnPtr(..)
|
||||
));
|
||||
assert!(matches!(
|
||||
layout.ty.kind(),
|
||||
ty::Ref(..) | ty::RawPtr(..) | ty::FnPtr(..)
|
||||
));
|
||||
assert!(matches!(self.layout().ty.kind(), ty::Ref(..) | ty::RawPtr(..) | ty::FnPtr(..)));
|
||||
assert!(matches!(layout.ty.kind(), ty::Ref(..) | ty::RawPtr(..) | ty::FnPtr(..)));
|
||||
assert_eq!(self.layout().abi, layout.abi);
|
||||
CValue(self.0, layout)
|
||||
}
|
||||
|
@ -317,14 +288,11 @@ impl<'tcx> CPlace<'tcx> {
|
|||
}
|
||||
|
||||
pub(crate) fn no_place(layout: TyAndLayout<'tcx>) -> CPlace<'tcx> {
|
||||
CPlace {
|
||||
inner: CPlaceInner::Addr(Pointer::dangling(layout.align.pref), None),
|
||||
layout,
|
||||
}
|
||||
CPlace { inner: CPlaceInner::Addr(Pointer::dangling(layout.align.pref), None), layout }
|
||||
}
|
||||
|
||||
pub(crate) fn new_stack_slot(
|
||||
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
||||
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
||||
layout: TyAndLayout<'tcx>,
|
||||
) -> CPlace<'tcx> {
|
||||
assert!(!layout.is_unsized());
|
||||
|
@ -339,28 +307,22 @@ impl<'tcx> CPlace<'tcx> {
|
|||
size: (u32::try_from(layout.size.bytes()).unwrap() + 15) / 16 * 16,
|
||||
offset: None,
|
||||
});
|
||||
CPlace {
|
||||
inner: CPlaceInner::Addr(Pointer::stack_slot(stack_slot), None),
|
||||
layout,
|
||||
}
|
||||
CPlace { inner: CPlaceInner::Addr(Pointer::stack_slot(stack_slot), None), layout }
|
||||
}
|
||||
|
||||
pub(crate) fn new_var(
|
||||
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
||||
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
||||
local: Local,
|
||||
layout: TyAndLayout<'tcx>,
|
||||
) -> CPlace<'tcx> {
|
||||
let var = Variable::with_u32(fx.next_ssa_var);
|
||||
fx.next_ssa_var += 1;
|
||||
fx.bcx.declare_var(var, fx.clif_type(layout.ty).unwrap());
|
||||
CPlace {
|
||||
inner: CPlaceInner::Var(local, var),
|
||||
layout,
|
||||
}
|
||||
CPlace { inner: CPlaceInner::Var(local, var), layout }
|
||||
}
|
||||
|
||||
pub(crate) fn new_var_pair(
|
||||
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
||||
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
||||
local: Local,
|
||||
layout: TyAndLayout<'tcx>,
|
||||
) -> CPlace<'tcx> {
|
||||
|
@ -372,17 +334,11 @@ impl<'tcx> CPlace<'tcx> {
|
|||
let (ty1, ty2) = fx.clif_pair_type(layout.ty).unwrap();
|
||||
fx.bcx.declare_var(var1, ty1);
|
||||
fx.bcx.declare_var(var2, ty2);
|
||||
CPlace {
|
||||
inner: CPlaceInner::VarPair(local, var1, var2),
|
||||
layout,
|
||||
}
|
||||
CPlace { inner: CPlaceInner::VarPair(local, var1, var2), layout }
|
||||
}
|
||||
|
||||
pub(crate) fn for_ptr(ptr: Pointer, layout: TyAndLayout<'tcx>) -> CPlace<'tcx> {
|
||||
CPlace {
|
||||
inner: CPlaceInner::Addr(ptr, None),
|
||||
layout,
|
||||
}
|
||||
CPlace { inner: CPlaceInner::Addr(ptr, None), layout }
|
||||
}
|
||||
|
||||
pub(crate) fn for_ptr_with_extra(
|
||||
|
@ -390,34 +346,27 @@ impl<'tcx> CPlace<'tcx> {
|
|||
extra: Value,
|
||||
layout: TyAndLayout<'tcx>,
|
||||
) -> CPlace<'tcx> {
|
||||
CPlace {
|
||||
inner: CPlaceInner::Addr(ptr, Some(extra)),
|
||||
layout,
|
||||
}
|
||||
CPlace { inner: CPlaceInner::Addr(ptr, Some(extra)), layout }
|
||||
}
|
||||
|
||||
pub(crate) fn to_cvalue(self, fx: &mut FunctionCx<'_, 'tcx, impl Module>) -> CValue<'tcx> {
|
||||
pub(crate) fn to_cvalue(self, fx: &mut FunctionCx<'_, '_, 'tcx>) -> CValue<'tcx> {
|
||||
let layout = self.layout();
|
||||
match self.inner {
|
||||
CPlaceInner::Var(_local, var) => {
|
||||
let val = fx.bcx.use_var(var);
|
||||
fx.bcx
|
||||
.set_val_label(val, cranelift_codegen::ir::ValueLabel::new(var.index()));
|
||||
//fx.bcx.set_val_label(val, cranelift_codegen::ir::ValueLabel::new(var.index()));
|
||||
CValue::by_val(val, layout)
|
||||
}
|
||||
CPlaceInner::VarPair(_local, var1, var2) => {
|
||||
let val1 = fx.bcx.use_var(var1);
|
||||
fx.bcx
|
||||
.set_val_label(val1, cranelift_codegen::ir::ValueLabel::new(var1.index()));
|
||||
//fx.bcx.set_val_label(val1, cranelift_codegen::ir::ValueLabel::new(var1.index()));
|
||||
let val2 = fx.bcx.use_var(var2);
|
||||
fx.bcx
|
||||
.set_val_label(val2, cranelift_codegen::ir::ValueLabel::new(var2.index()));
|
||||
//fx.bcx.set_val_label(val2, cranelift_codegen::ir::ValueLabel::new(var2.index()));
|
||||
CValue::by_val_pair(val1, val2, layout)
|
||||
}
|
||||
CPlaceInner::VarLane(_local, var, lane) => {
|
||||
let val = fx.bcx.use_var(var);
|
||||
fx.bcx
|
||||
.set_val_label(val, cranelift_codegen::ir::ValueLabel::new(var.index()));
|
||||
//fx.bcx.set_val_label(val, cranelift_codegen::ir::ValueLabel::new(var.index()));
|
||||
let val = fx.bcx.ins().extractlane(val, lane);
|
||||
CValue::by_val(val, layout)
|
||||
}
|
||||
|
@ -447,11 +396,7 @@ impl<'tcx> CPlace<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn write_cvalue(
|
||||
self,
|
||||
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
||||
from: CValue<'tcx>,
|
||||
) {
|
||||
pub(crate) fn write_cvalue(self, fx: &mut FunctionCx<'_, '_, 'tcx>, from: CValue<'tcx>) {
|
||||
assert_assignable(fx, from.layout().ty, self.layout().ty);
|
||||
|
||||
self.write_cvalue_maybe_transmute(fx, from, "write_cvalue");
|
||||
|
@ -459,7 +404,7 @@ impl<'tcx> CPlace<'tcx> {
|
|||
|
||||
pub(crate) fn write_cvalue_transmute(
|
||||
self,
|
||||
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
||||
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
||||
from: CValue<'tcx>,
|
||||
) {
|
||||
self.write_cvalue_maybe_transmute(fx, from, "write_cvalue_transmute");
|
||||
|
@ -467,12 +412,12 @@ impl<'tcx> CPlace<'tcx> {
|
|||
|
||||
fn write_cvalue_maybe_transmute(
|
||||
self,
|
||||
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
||||
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
||||
from: CValue<'tcx>,
|
||||
#[cfg_attr(not(debug_assertions), allow(unused_variables))] method: &'static str,
|
||||
) {
|
||||
fn transmute_value<'tcx>(
|
||||
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
||||
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
||||
var: Variable,
|
||||
data: Value,
|
||||
dst_ty: Type,
|
||||
|
@ -511,8 +456,7 @@ impl<'tcx> CPlace<'tcx> {
|
|||
}
|
||||
_ => unreachable!("write_cvalue_transmute: {:?} -> {:?}", src_ty, dst_ty),
|
||||
};
|
||||
fx.bcx
|
||||
.set_val_label(data, cranelift_codegen::ir::ValueLabel::new(var.index()));
|
||||
//fx.bcx.set_val_label(data, cranelift_codegen::ir::ValueLabel::new(var.index()));
|
||||
fx.bcx.def_var(var, data);
|
||||
}
|
||||
|
||||
|
@ -558,15 +502,13 @@ impl<'tcx> CPlace<'tcx> {
|
|||
|
||||
// First get the old vector
|
||||
let vector = fx.bcx.use_var(var);
|
||||
fx.bcx
|
||||
.set_val_label(vector, cranelift_codegen::ir::ValueLabel::new(var.index()));
|
||||
//fx.bcx.set_val_label(vector, cranelift_codegen::ir::ValueLabel::new(var.index()));
|
||||
|
||||
// Next insert the written lane into the vector
|
||||
let vector = fx.bcx.ins().insertlane(vector, data, lane);
|
||||
|
||||
// Finally write the new vector
|
||||
fx.bcx
|
||||
.set_val_label(vector, cranelift_codegen::ir::ValueLabel::new(var.index()));
|
||||
//fx.bcx.set_val_label(vector, cranelift_codegen::ir::ValueLabel::new(var.index()));
|
||||
fx.bcx.def_var(var, vector);
|
||||
|
||||
return;
|
||||
|
@ -604,10 +546,7 @@ impl<'tcx> CPlace<'tcx> {
|
|||
to_ptr.store(fx, val, flags);
|
||||
}
|
||||
CValueInner::ByValPair(_, _) => {
|
||||
bug!(
|
||||
"Non ScalarPair abi {:?} for ByValPair CValue",
|
||||
dst_layout.abi
|
||||
);
|
||||
bug!("Non ScalarPair abi {:?} for ByValPair CValue", dst_layout.abi);
|
||||
}
|
||||
CValueInner::ByRef(from_ptr, None) => {
|
||||
let from_addr = from_ptr.get_addr(fx);
|
||||
|
@ -632,7 +571,7 @@ impl<'tcx> CPlace<'tcx> {
|
|||
|
||||
pub(crate) fn place_field(
|
||||
self,
|
||||
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
||||
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
||||
field: mir::Field,
|
||||
) -> CPlace<'tcx> {
|
||||
let layout = self.layout();
|
||||
|
@ -650,18 +589,8 @@ impl<'tcx> CPlace<'tcx> {
|
|||
let layout = layout.field(&*fx, field.index());
|
||||
|
||||
match field.as_u32() {
|
||||
0 => {
|
||||
return CPlace {
|
||||
inner: CPlaceInner::Var(local, var1),
|
||||
layout,
|
||||
}
|
||||
}
|
||||
1 => {
|
||||
return CPlace {
|
||||
inner: CPlaceInner::Var(local, var2),
|
||||
layout,
|
||||
}
|
||||
}
|
||||
0 => return CPlace { inner: CPlaceInner::Var(local, var1), layout },
|
||||
1 => return CPlace { inner: CPlaceInner::Var(local, var2), layout },
|
||||
_ => unreachable!("field should be 0 or 1"),
|
||||
}
|
||||
}
|
||||
|
@ -680,7 +609,7 @@ impl<'tcx> CPlace<'tcx> {
|
|||
|
||||
pub(crate) fn place_index(
|
||||
self,
|
||||
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
||||
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
||||
index: Value,
|
||||
) -> CPlace<'tcx> {
|
||||
let (elem_layout, ptr) = match self.layout().ty.kind() {
|
||||
|
@ -689,30 +618,24 @@ impl<'tcx> CPlace<'tcx> {
|
|||
_ => bug!("place_index({:?})", self.layout().ty),
|
||||
};
|
||||
|
||||
let offset = fx
|
||||
.bcx
|
||||
.ins()
|
||||
.imul_imm(index, elem_layout.size.bytes() as i64);
|
||||
let offset = fx.bcx.ins().imul_imm(index, elem_layout.size.bytes() as i64);
|
||||
|
||||
CPlace::for_ptr(ptr.offset_value(fx, offset), elem_layout)
|
||||
}
|
||||
|
||||
pub(crate) fn place_deref(self, fx: &mut FunctionCx<'_, 'tcx, impl Module>) -> CPlace<'tcx> {
|
||||
pub(crate) fn place_deref(self, fx: &mut FunctionCx<'_, '_, 'tcx>) -> CPlace<'tcx> {
|
||||
let inner_layout = fx.layout_of(self.layout().ty.builtin_deref(true).unwrap().ty);
|
||||
if has_ptr_meta(fx.tcx, inner_layout.ty) {
|
||||
let (addr, extra) = self.to_cvalue(fx).load_scalar_pair(fx);
|
||||
CPlace::for_ptr_with_extra(Pointer::new(addr), extra, inner_layout)
|
||||
} else {
|
||||
CPlace::for_ptr(
|
||||
Pointer::new(self.to_cvalue(fx).load_scalar(fx)),
|
||||
inner_layout,
|
||||
)
|
||||
CPlace::for_ptr(Pointer::new(self.to_cvalue(fx).load_scalar(fx)), inner_layout)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn place_ref(
|
||||
self,
|
||||
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
||||
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
||||
layout: TyAndLayout<'tcx>,
|
||||
) -> CValue<'tcx> {
|
||||
if has_ptr_meta(fx.tcx, self.layout().ty) {
|
||||
|
@ -729,21 +652,18 @@ impl<'tcx> CPlace<'tcx> {
|
|||
|
||||
pub(crate) fn downcast_variant(
|
||||
self,
|
||||
fx: &FunctionCx<'_, 'tcx, impl Module>,
|
||||
fx: &FunctionCx<'_, '_, 'tcx>,
|
||||
variant: VariantIdx,
|
||||
) -> Self {
|
||||
assert!(!self.layout().is_unsized());
|
||||
let layout = self.layout().for_variant(fx, variant);
|
||||
CPlace {
|
||||
inner: self.inner,
|
||||
layout,
|
||||
}
|
||||
CPlace { inner: self.inner, layout }
|
||||
}
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
pub(crate) fn assert_assignable<'tcx>(
|
||||
fx: &FunctionCx<'_, 'tcx, impl Module>,
|
||||
fx: &FunctionCx<'_, '_, 'tcx>,
|
||||
from_ty: Ty<'tcx>,
|
||||
to_ty: Ty<'tcx>,
|
||||
) {
|
||||
|
@ -776,12 +696,9 @@ pub(crate) fn assert_assignable<'tcx>(
|
|||
}
|
||||
(&ty::Dynamic(from_traits, _), &ty::Dynamic(to_traits, _)) => {
|
||||
for (from, to) in from_traits.iter().zip(to_traits) {
|
||||
let from = fx
|
||||
.tcx
|
||||
.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), from);
|
||||
let to = fx
|
||||
.tcx
|
||||
.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), to);
|
||||
let from =
|
||||
fx.tcx.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), from);
|
||||
let to = fx.tcx.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), to);
|
||||
assert_eq!(
|
||||
from, to,
|
||||
"Can't write trait object of incompatible traits {:?} to place with traits {:?}\n\n{:#?}",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue