1
Fork 0

Let codegen_get_discriminant accept CValue instead of CPlace

This commit is contained in:
bjorn3 2019-08-18 16:19:33 +02:00
parent 5b818e5e0f
commit 1bee110d95
3 changed files with 10 additions and 12 deletions

View file

@ -367,10 +367,7 @@ fn trans_stmt<'a, 'tcx: 'a>(
_ => unreachable!("cast adt {} -> {}", from_ty, to_ty), _ => unreachable!("cast adt {} -> {}", from_ty, to_ty),
} }
// FIXME avoid forcing to stack let discr = crate::discriminant::codegen_get_discriminant(fx, operand, fx.layout_of(to_ty));
let place =
CPlace::for_addr(operand.force_stack(fx), operand.layout());
let discr = crate::discriminant::codegen_get_discriminant(fx, place, fx.layout_of(to_ty));
lval.write_cvalue(fx, discr); lval.write_cvalue(fx, discr);
} else { } else {
let to_clif_ty = fx.clif_type(to_ty).unwrap(); let to_clif_ty = fx.clif_type(to_ty).unwrap();
@ -405,7 +402,8 @@ fn trans_stmt<'a, 'tcx: 'a>(
} }
Rvalue::Discriminant(place) => { Rvalue::Discriminant(place) => {
let place = trans_place(fx, place); let place = trans_place(fx, place);
let discr = crate::discriminant::codegen_get_discriminant(fx, place, dest_layout); let value = place.to_cvalue(fx);
let discr = crate::discriminant::codegen_get_discriminant(fx, value, dest_layout);
lval.write_cvalue(fx, discr); lval.write_cvalue(fx, discr);
} }
Rvalue::Repeat(operand, times) => { Rvalue::Repeat(operand, times) => {

View file

@ -58,10 +58,10 @@ pub fn codegen_set_discriminant<'tcx>(
pub fn codegen_get_discriminant<'tcx>( pub fn codegen_get_discriminant<'tcx>(
fx: &mut FunctionCx<'_, 'tcx, impl Backend>, fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
place: CPlace<'tcx>, value: CValue<'tcx>,
dest_layout: TyLayout<'tcx>, dest_layout: TyLayout<'tcx>,
) -> CValue<'tcx> { ) -> CValue<'tcx> {
let layout = place.layout(); let layout = value.layout();
if layout.abi == layout::Abi::Uninhabited { if layout.abi == layout::Abi::Uninhabited {
return trap_unreachable_ret_value(fx, dest_layout, "[panic] Tried to get discriminant for uninhabited type."); return trap_unreachable_ret_value(fx, dest_layout, "[panic] Tried to get discriminant for uninhabited type.");
@ -82,7 +82,7 @@ pub fn codegen_get_discriminant<'tcx>(
} }
}; };
let discr = place.place_field(fx, mir::Field::new(discr_index)).to_cvalue(fx); let discr = value.value_field(fx, mir::Field::new(discr_index));
let discr_ty = discr.layout().ty; let discr_ty = discr.layout().ty;
let lldiscr = discr.load_scalar(fx); let lldiscr = discr.load_scalar(fx);
match discr_kind { match discr_kind {

View file

@ -374,10 +374,10 @@ pub fn codegen_intrinsic_call<'a, 'tcx: 'a>(
fx.bcx.call_memmove(fx.module.target_config(), dst, src, byte_amount); fx.bcx.call_memmove(fx.module.target_config(), dst, src, byte_amount);
} }
}; };
discriminant_value, (c val) { discriminant_value, (c ptr) {
let pointee_layout = fx.layout_of(val.layout().ty.builtin_deref(true).unwrap().ty); let pointee_layout = fx.layout_of(ptr.layout().ty.builtin_deref(true).unwrap().ty);
let place = CPlace::for_addr(val.load_scalar(fx), pointee_layout); let val = CValue::by_ref(ptr.load_scalar(fx), pointee_layout);
let discr = crate::discriminant::codegen_get_discriminant(fx, place, ret.layout()); let discr = crate::discriminant::codegen_get_discriminant(fx, val, ret.layout());
ret.write_cvalue(fx, discr); ret.write_cvalue(fx, discr);
}; };
size_of, <T> () { size_of, <T> () {