Use Builder instead of CodegenCx for OperandRef and LocalRef
This commit is contained in:
parent
a0c2ca1b56
commit
83e80a7443
4 changed files with 28 additions and 25 deletions
|
|
@ -616,7 +616,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
|
|||
assert_eq!(place.llextra.is_some(), place.layout.is_unsized());
|
||||
|
||||
if place.layout.is_zst() {
|
||||
return OperandRef::new_zst(self.cx(), place.layout);
|
||||
return OperandRef::new_zst(self, place.layout);
|
||||
}
|
||||
|
||||
fn scalar_load_metadata<'a, 'll, 'tcx>(
|
||||
|
|
|
|||
|
|
@ -178,16 +178,16 @@ enum LocalRef<'tcx, V> {
|
|||
Operand(Option<OperandRef<'tcx, V>>),
|
||||
}
|
||||
|
||||
impl<'tcx, V: CodegenObject> LocalRef<'tcx, V> {
|
||||
fn new_operand<Cx: CodegenMethods<'tcx, Value = V>>(
|
||||
cx: &Cx,
|
||||
impl<'a, 'tcx: 'a, V: CodegenObject> LocalRef<'tcx, V> {
|
||||
fn new_operand<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
|
||||
bx: &mut Bx,
|
||||
layout: TyLayout<'tcx>,
|
||||
) -> LocalRef<'tcx, V> {
|
||||
if layout.is_zst() {
|
||||
// Zero-size temporaries aren't always initialized, which
|
||||
// doesn't matter because they don't contain data, but
|
||||
// we need something in the operand.
|
||||
LocalRef::Operand(Some(OperandRef::new_zst(cx, layout)))
|
||||
LocalRef::Operand(Some(OperandRef::new_zst(bx, layout)))
|
||||
} else {
|
||||
LocalRef::Operand(None)
|
||||
}
|
||||
|
|
@ -275,7 +275,7 @@ pub fn codegen_mir<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
|
|||
|
||||
if !memory_locals.contains(local) && !dbg {
|
||||
debug!("alloc: {:?} ({}) -> operand", local, name);
|
||||
return LocalRef::new_operand(bx.cx(), layout);
|
||||
return LocalRef::new_operand(&mut bx, layout);
|
||||
}
|
||||
|
||||
debug!("alloc: {:?} ({}) -> place", local, name);
|
||||
|
|
@ -320,7 +320,7 @@ pub fn codegen_mir<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
|
|||
// alloca in advance. Instead we wait until we see the
|
||||
// definition and update the operand there.
|
||||
debug!("alloc: {:?} -> operand", local);
|
||||
LocalRef::new_operand(bx.cx(), layout)
|
||||
LocalRef::new_operand(&mut bx, layout)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -529,7 +529,7 @@ fn arg_local_refs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
|
|||
let local = |op| LocalRef::Operand(Some(op));
|
||||
match arg.mode {
|
||||
PassMode::Ignore(IgnoreMode::Zst) => {
|
||||
return local(OperandRef::new_zst(bx.cx(), arg.layout));
|
||||
return local(OperandRef::new_zst(bx, arg.layout));
|
||||
}
|
||||
PassMode::Ignore(IgnoreMode::CVarArgs) => {}
|
||||
PassMode::Direct(_) => {
|
||||
|
|
|
|||
|
|
@ -54,13 +54,13 @@ impl<V: CodegenObject> fmt::Debug for OperandRef<'tcx, V> {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx: 'a, V: CodegenObject> OperandRef<'tcx, V> {
|
||||
pub fn new_zst<Cx: CodegenMethods<'tcx, Value = V>>(
|
||||
cx: &Cx,
|
||||
pub fn new_zst<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
|
||||
bx: &mut Bx,
|
||||
layout: TyLayout<'tcx>
|
||||
) -> OperandRef<'tcx, V> {
|
||||
assert!(layout.is_zst());
|
||||
OperandRef {
|
||||
val: OperandValue::Immediate(cx.const_undef(cx.immediate_backend_type(layout))),
|
||||
val: OperandValue::Immediate(bx.const_undef(bx.immediate_backend_type(layout))),
|
||||
layout
|
||||
}
|
||||
}
|
||||
|
|
@ -69,10 +69,10 @@ impl<'a, 'tcx: 'a, V: CodegenObject> OperandRef<'tcx, V> {
|
|||
bx: &mut Bx,
|
||||
val: ty::Const<'tcx>
|
||||
) -> Result<Self, ErrorHandled> {
|
||||
let layout = bx.cx().layout_of(val.ty);
|
||||
let layout = bx.layout_of(val.ty);
|
||||
|
||||
if layout.is_zst() {
|
||||
return Ok(OperandRef::new_zst(bx.cx(), layout));
|
||||
return Ok(OperandRef::new_zst(bx, layout));
|
||||
}
|
||||
|
||||
let val = match val.val {
|
||||
|
|
@ -84,10 +84,10 @@ impl<'a, 'tcx: 'a, V: CodegenObject> OperandRef<'tcx, V> {
|
|||
layout::Abi::Scalar(ref x) => x,
|
||||
_ => bug!("from_const: invalid ByVal layout: {:#?}", layout)
|
||||
};
|
||||
let llval = bx.cx().scalar_to_backend(
|
||||
let llval = bx.scalar_to_backend(
|
||||
x,
|
||||
scalar,
|
||||
bx.cx().immediate_backend_type(layout),
|
||||
bx.immediate_backend_type(layout),
|
||||
);
|
||||
OperandValue::Immediate(llval)
|
||||
},
|
||||
|
|
@ -96,16 +96,16 @@ impl<'a, 'tcx: 'a, V: CodegenObject> OperandRef<'tcx, V> {
|
|||
layout::Abi::ScalarPair(ref a, _) => a,
|
||||
_ => bug!("from_const: invalid ScalarPair layout: {:#?}", layout)
|
||||
};
|
||||
let a_llval = bx.cx().scalar_to_backend(
|
||||
let a_llval = bx.scalar_to_backend(
|
||||
a,
|
||||
a_scalar,
|
||||
bx.cx().scalar_pair_element_backend_type(layout, 0, true),
|
||||
bx.scalar_pair_element_backend_type(layout, 0, true),
|
||||
);
|
||||
let b_llval = bx.cx().const_usize(b);
|
||||
let b_llval = bx.const_usize(b);
|
||||
OperandValue::Pair(a_llval, b_llval)
|
||||
},
|
||||
ConstValue::ByRef(ptr, alloc) => {
|
||||
return Ok(bx.load_operand(bx.cx().from_const_alloc(layout, alloc, ptr.offset)));
|
||||
return Ok(bx.load_operand(bx.from_const_alloc(layout, alloc, ptr.offset)));
|
||||
},
|
||||
};
|
||||
|
||||
|
|
@ -124,7 +124,7 @@ impl<'a, 'tcx: 'a, V: CodegenObject> OperandRef<'tcx, V> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn deref<Cx: CodegenMethods<'tcx, Value = V>>(
|
||||
pub fn deref<Cx: LayoutTypeMethods<'tcx>>(
|
||||
self,
|
||||
cx: &Cx
|
||||
) -> PlaceRef<'tcx, V> {
|
||||
|
|
@ -199,7 +199,7 @@ impl<'a, 'tcx: 'a, V: CodegenObject> OperandRef<'tcx, V> {
|
|||
let mut val = match (self.val, &self.layout.abi) {
|
||||
// If the field is ZST, it has no data.
|
||||
_ if field.is_zst() => {
|
||||
return OperandRef::new_zst(bx.cx(), field);
|
||||
return OperandRef::new_zst(bx, field);
|
||||
}
|
||||
|
||||
// Newtype of a scalar, scalar pair or vector.
|
||||
|
|
@ -409,7 +409,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|||
// checks in `codegen_consume` and `extract_field`.
|
||||
let elem = o.layout.field(bx.cx(), 0);
|
||||
if elem.is_zst() {
|
||||
return Some(OperandRef::new_zst(bx.cx(), elem));
|
||||
return Some(OperandRef::new_zst(bx, elem));
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
|
|
@ -432,7 +432,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|||
|
||||
// ZSTs don't require any actual memory access.
|
||||
if layout.is_zst() {
|
||||
return OperandRef::new_zst(bx.cx(), layout);
|
||||
return OperandRef::new_zst(bx, layout);
|
||||
}
|
||||
|
||||
if let Some(o) = self.maybe_codegen_consume_direct(bx, place) {
|
||||
|
|
|
|||
|
|
@ -523,8 +523,11 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|||
// According to `rvalue_creates_operand`, only ZST
|
||||
// aggregate rvalues are allowed to be operands.
|
||||
let ty = rvalue.ty(self.mir, self.cx.tcx());
|
||||
(bx, OperandRef::new_zst(self.cx,
|
||||
self.cx.layout_of(self.monomorphize(&ty))))
|
||||
let operand = OperandRef::new_zst(
|
||||
&mut bx,
|
||||
self.cx.layout_of(self.monomorphize(&ty)),
|
||||
);
|
||||
(bx, operand)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue