Introduce CPlace::Stack
This commit is contained in:
parent
3e24c1212f
commit
feec354d65
14
src/abi.rs
14
src/abi.rs
@ -340,23 +340,23 @@ fn local_place<'a, 'tcx: 'a>(
|
||||
fx.bcx.declare_var(mir_var(local), fx.clif_type(layout.ty).unwrap());
|
||||
CPlace::Var(local, layout)
|
||||
} else {
|
||||
let stack_slot = fx.bcx.create_stack_slot(StackSlotData {
|
||||
kind: StackSlotKind::ExplicitSlot,
|
||||
size: layout.size.bytes() as u32,
|
||||
offset: None,
|
||||
});
|
||||
let place = CPlace::new_stack_slot(fx, layout.ty);
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
let TyLayout { ty, details } = layout;
|
||||
let ty::layout::LayoutDetails { size, align, abi: _, variants: _, fields: _ } = details;
|
||||
let stack_slot = match place {
|
||||
CPlace::Stack(stack_slot, _) => stack_slot,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
fx.add_entity_comment(stack_slot, format!(
|
||||
"{:?}: {:?} size={} align={},{}",
|
||||
local, ty, size.bytes(), align.abi.bytes(), align.pref.bytes(),
|
||||
));
|
||||
}
|
||||
|
||||
CPlace::from_stack_slot(fx, stack_slot, layout.ty)
|
||||
place
|
||||
};
|
||||
|
||||
let prev_place = fx.local_map.insert(local, place);
|
||||
@ -606,7 +606,7 @@ pub fn codegen_call_inner<'a, 'tcx: 'a>(
|
||||
let return_ptr = match output_pass_mode {
|
||||
PassMode::NoPass => None,
|
||||
PassMode::ByRef => match ret_place {
|
||||
Some(ret_place) => Some(ret_place.cplace_to_addr(fx)),
|
||||
Some(ret_place) => Some(ret_place.to_addr(fx)),
|
||||
None => Some(fx.bcx.ins().iconst(fx.pointer_type, 0)),
|
||||
},
|
||||
PassMode::ByVal(_) => None,
|
||||
|
@ -258,7 +258,7 @@ fn codegen_fn_content<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx, impl Backend>)
|
||||
// we don't actually need to drop anything
|
||||
} else {
|
||||
let drop_place = trans_place(fx, location);
|
||||
let arg_place = CPlace::temp(
|
||||
let arg_place = CPlace::new_stack_slot(
|
||||
fx,
|
||||
fx.tcx.mk_ref(
|
||||
&ty::RegionKind::ReErased,
|
||||
@ -937,7 +937,7 @@ pub fn trans_checked_int_binop<'a, 'tcx: 'a>(
|
||||
// TODO: check for overflow
|
||||
let has_overflow = fx.bcx.ins().iconst(types::I8, 0);
|
||||
|
||||
let out_place = CPlace::temp(fx, out_ty);
|
||||
let out_place = CPlace::new_stack_slot(fx, out_ty);
|
||||
let out_layout = out_place.layout();
|
||||
out_place.write_cvalue(fx, CValue::ByValPair(res, has_overflow, out_layout));
|
||||
|
||||
|
@ -245,16 +245,19 @@ impl<'tcx> CValue<'tcx> {
|
||||
pub enum CPlace<'tcx> {
|
||||
Var(Local, TyLayout<'tcx>),
|
||||
Addr(Value, Option<Value>, TyLayout<'tcx>),
|
||||
Stack(StackSlot, TyLayout<'tcx>),
|
||||
}
|
||||
|
||||
impl<'a, 'tcx: 'a> CPlace<'tcx> {
|
||||
pub fn layout(&self) -> TyLayout<'tcx> {
|
||||
match *self {
|
||||
CPlace::Var(_, layout) | CPlace::Addr(_, _, layout) => layout,
|
||||
CPlace::Var(_, layout)
|
||||
| CPlace::Addr(_, _, layout)
|
||||
| CPlace::Stack(_, layout) => layout,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn temp(fx: &mut FunctionCx<'a, 'tcx, impl Backend>, ty: Ty<'tcx>) -> CPlace<'tcx> {
|
||||
pub fn new_stack_slot(fx: &mut FunctionCx<'a, 'tcx, impl Backend>, ty: Ty<'tcx>) -> CPlace<'tcx> {
|
||||
let layout = fx.layout_of(ty);
|
||||
assert!(!layout.is_unsized());
|
||||
let stack_slot = fx.bcx.create_stack_slot(StackSlotData {
|
||||
@ -262,25 +265,7 @@ impl<'a, 'tcx: 'a> CPlace<'tcx> {
|
||||
size: layout.size.bytes() as u32,
|
||||
offset: None,
|
||||
});
|
||||
CPlace::Addr(
|
||||
fx.bcx.ins().stack_addr(fx.pointer_type, stack_slot, 0),
|
||||
None,
|
||||
layout,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn from_stack_slot(
|
||||
fx: &mut FunctionCx<'a, 'tcx, impl Backend>,
|
||||
stack_slot: StackSlot,
|
||||
ty: Ty<'tcx>,
|
||||
) -> CPlace<'tcx> {
|
||||
let layout = fx.layout_of(ty);
|
||||
assert!(!layout.is_unsized());
|
||||
CPlace::Addr(
|
||||
fx.bcx.ins().stack_addr(fx.pointer_type, stack_slot, 0),
|
||||
None,
|
||||
layout,
|
||||
)
|
||||
CPlace::Stack(stack_slot, layout)
|
||||
}
|
||||
|
||||
pub fn to_cvalue(self, fx: &mut FunctionCx<'a, 'tcx, impl Backend>) -> CValue<'tcx> {
|
||||
@ -290,10 +275,13 @@ impl<'a, 'tcx: 'a> CPlace<'tcx> {
|
||||
assert!(extra.is_none(), "unsized values are not yet supported");
|
||||
CValue::ByRef(addr, layout)
|
||||
}
|
||||
CPlace::Stack(stack_slot, layout) => {
|
||||
CValue::ByRef(fx.bcx.ins().stack_addr(fx.pointer_type, stack_slot, 0), layout)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cplace_to_addr(self, fx: &mut FunctionCx<'a, 'tcx, impl Backend>) -> Value {
|
||||
pub fn to_addr(self, fx: &mut FunctionCx<'a, 'tcx, impl Backend>) -> Value {
|
||||
match self.to_addr_maybe_unsized(fx) {
|
||||
(addr, None) => addr,
|
||||
(_, Some(_)) => bug!("Expected sized cplace, found {:?}", self),
|
||||
@ -306,6 +294,9 @@ impl<'a, 'tcx: 'a> CPlace<'tcx> {
|
||||
) -> (Value, Option<Value>) {
|
||||
match self {
|
||||
CPlace::Addr(addr, extra, _layout) => (addr, extra),
|
||||
CPlace::Stack(stack_slot, _layout) => {
|
||||
(fx.bcx.ins().stack_addr(fx.pointer_type, stack_slot, 0), None)
|
||||
}
|
||||
CPlace::Var(_, _) => bug!("Expected CPlace::Addr, found CPlace::Var"),
|
||||
}
|
||||
}
|
||||
@ -363,6 +354,9 @@ impl<'a, 'tcx: 'a> CPlace<'tcx> {
|
||||
return;
|
||||
}
|
||||
CPlace::Addr(addr, None, dst_layout) => (addr, dst_layout),
|
||||
CPlace::Stack(stack_slot, dst_layout) => {
|
||||
(fx.bcx.ins().stack_addr(fx.pointer_type, stack_slot, 0), dst_layout)
|
||||
}
|
||||
CPlace::Addr(_, _, _) => bug!("Can't write value to unsized place {:?}", self),
|
||||
};
|
||||
|
||||
@ -409,7 +403,7 @@ impl<'a, 'tcx: 'a> CPlace<'tcx> {
|
||||
index: Value,
|
||||
) -> CPlace<'tcx> {
|
||||
let (elem_layout, addr) = match self.layout().ty.sty {
|
||||
ty::Array(elem_ty, _) => (fx.layout_of(elem_ty), self.cplace_to_addr(fx)),
|
||||
ty::Array(elem_ty, _) => (fx.layout_of(elem_ty), self.to_addr(fx)),
|
||||
ty::Slice(elem_ty) => (
|
||||
fx.layout_of(elem_ty),
|
||||
self.to_addr_maybe_unsized(fx).0,
|
||||
@ -432,7 +426,7 @@ impl<'a, 'tcx: 'a> CPlace<'tcx> {
|
||||
} else {
|
||||
match self.layout().abi {
|
||||
Abi::ScalarPair(ref a, ref b) => {
|
||||
let addr = self.cplace_to_addr(fx);
|
||||
let addr = self.to_addr(fx);
|
||||
let ptr =
|
||||
fx.bcx
|
||||
.ins()
|
||||
@ -455,14 +449,14 @@ impl<'a, 'tcx: 'a> CPlace<'tcx> {
|
||||
|
||||
pub fn write_place_ref(self, fx: &mut FunctionCx<'a, 'tcx, impl Backend>, dest: CPlace<'tcx>) {
|
||||
if !self.layout().is_unsized() {
|
||||
let ptr = CValue::ByVal(self.cplace_to_addr(fx), dest.layout());
|
||||
let ptr = CValue::ByVal(self.to_addr(fx), dest.layout());
|
||||
dest.write_cvalue(fx, ptr);
|
||||
} else {
|
||||
let (value, extra) = self.to_addr_maybe_unsized(fx);
|
||||
|
||||
match dest.layout().abi {
|
||||
Abi::ScalarPair(ref a, _) => {
|
||||
let dest_addr = dest.cplace_to_addr(fx);
|
||||
let dest_addr = dest.to_addr(fx);
|
||||
fx.bcx
|
||||
.ins()
|
||||
.store(MemFlags::new(), value, dest_addr, 0);
|
||||
@ -488,6 +482,10 @@ impl<'a, 'tcx: 'a> CPlace<'tcx> {
|
||||
assert!(!layout.is_unsized());
|
||||
CPlace::Addr(addr, extra, layout)
|
||||
}
|
||||
CPlace::Stack(stack_slot, _) => {
|
||||
assert!(!layout.is_unsized());
|
||||
CPlace::Stack(stack_slot, layout)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -298,32 +298,20 @@ pub fn codegen_intrinsic_call<'a, 'tcx: 'a>(
|
||||
};
|
||||
init, <T> () {
|
||||
let layout = fx.layout_of(T);
|
||||
let stack_slot = fx.bcx.create_stack_slot(StackSlotData {
|
||||
kind: StackSlotKind::ExplicitSlot,
|
||||
size: layout.size.bytes() as u32,
|
||||
offset: None,
|
||||
});
|
||||
let addr = fx.bcx.ins().stack_addr(pointer_ty(fx.tcx), stack_slot, 0);
|
||||
let inited_place = CPlace::new_stack_slot(fx, T);
|
||||
let addr = inited_place.to_addr(fx);
|
||||
let zero_val = fx.bcx.ins().iconst(types::I8, 0);
|
||||
let len_val = fx.bcx.ins().iconst(pointer_ty(fx.tcx), layout.size.bytes() as i64);
|
||||
fx.bcx.call_memset(fx.module.target_config(), addr, zero_val, len_val);
|
||||
|
||||
let uninit_place = CPlace::from_stack_slot(fx, stack_slot, T);
|
||||
let uninit_val = uninit_place.to_cvalue(fx);
|
||||
ret.write_cvalue(fx, uninit_val);
|
||||
let inited_val = inited_place.to_cvalue(fx);
|
||||
ret.write_cvalue(fx, inited_val);
|
||||
};
|
||||
write_bytes, (v dst, v val, v count) {
|
||||
fx.bcx.call_memset(fx.module.target_config(), dst, val, count);
|
||||
};
|
||||
uninit, <T> () {
|
||||
let layout = fx.layout_of(T);
|
||||
let stack_slot = fx.bcx.create_stack_slot(StackSlotData {
|
||||
kind: StackSlotKind::ExplicitSlot,
|
||||
size: layout.size.bytes() as u32,
|
||||
offset: None,
|
||||
});
|
||||
|
||||
let uninit_place = CPlace::from_stack_slot(fx, stack_slot, T);
|
||||
let uninit_place = CPlace::new_stack_slot(fx, T);
|
||||
let uninit_val = uninit_place.to_cvalue(fx);
|
||||
ret.write_cvalue(fx, uninit_val);
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user