codegen_place and related functions can take PlaceRef by value

上级 10b19f6d
...@@ -264,7 +264,7 @@ fn codegen_return_terminator(&mut self, mut bx: Bx) { ...@@ -264,7 +264,7 @@ fn codegen_return_terminator(&mut self, mut bx: Bx) {
} }
PassMode::Direct(_) | PassMode::Pair(..) => { PassMode::Direct(_) | PassMode::Pair(..) => {
let op = self.codegen_consume(&mut bx, &mir::Place::return_place().as_ref()); let op = self.codegen_consume(&mut bx, mir::Place::return_place().as_ref());
if let Ref(llval, _, align) = op.val { if let Ref(llval, _, align) = op.val {
bx.load(llval, align) bx.load(llval, align)
} else { } else {
...@@ -319,7 +319,7 @@ fn codegen_drop_terminator( ...@@ -319,7 +319,7 @@ fn codegen_drop_terminator(
return; return;
} }
let place = self.codegen_place(&mut bx, &location.as_ref()); let place = self.codegen_place(&mut bx, location.as_ref());
let (args1, args2); let (args1, args2);
let mut args = if let Some(llextra) = place.llextra { let mut args = if let Some(llextra) = place.llextra {
args2 = [place.llval, llextra]; args2 = [place.llval, llextra];
...@@ -1111,7 +1111,7 @@ fn make_return_dest( ...@@ -1111,7 +1111,7 @@ fn make_return_dest(
} else { } else {
self.codegen_place( self.codegen_place(
bx, bx,
&mir::PlaceRef { local: &dest.local, projection: &dest.projection }, mir::PlaceRef { local: &dest.local, projection: &dest.projection },
) )
}; };
if fn_ret.is_indirect() { if fn_ret.is_indirect() {
...@@ -1137,7 +1137,7 @@ fn codegen_transmute(&mut self, bx: &mut Bx, src: &mir::Operand<'tcx>, dst: &mir ...@@ -1137,7 +1137,7 @@ fn codegen_transmute(&mut self, bx: &mut Bx, src: &mir::Operand<'tcx>, dst: &mir
LocalRef::Place(place) => self.codegen_transmute_into(bx, src, place), LocalRef::Place(place) => self.codegen_transmute_into(bx, src, place),
LocalRef::UnsizedPlace(_) => bug!("transmute must not involve unsized locals"), LocalRef::UnsizedPlace(_) => bug!("transmute must not involve unsized locals"),
LocalRef::Operand(None) => { LocalRef::Operand(None) => {
let dst_layout = bx.layout_of(self.monomorphized_place_ty(&dst.as_ref())); let dst_layout = bx.layout_of(self.monomorphized_place_ty(dst.as_ref()));
assert!(!dst_layout.ty.has_erasable_regions()); assert!(!dst_layout.ty.has_erasable_regions());
let place = PlaceRef::alloca(bx, dst_layout); let place = PlaceRef::alloca(bx, dst_layout);
place.storage_live(bx); place.storage_live(bx);
...@@ -1151,7 +1151,7 @@ fn codegen_transmute(&mut self, bx: &mut Bx, src: &mir::Operand<'tcx>, dst: &mir ...@@ -1151,7 +1151,7 @@ fn codegen_transmute(&mut self, bx: &mut Bx, src: &mir::Operand<'tcx>, dst: &mir
} }
} }
} else { } else {
let dst = self.codegen_place(bx, &dst.as_ref()); let dst = self.codegen_place(bx, dst.as_ref());
self.codegen_transmute_into(bx, src, dst); self.codegen_transmute_into(bx, src, dst);
} }
} }
......
...@@ -369,7 +369,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { ...@@ -369,7 +369,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
fn maybe_codegen_consume_direct( fn maybe_codegen_consume_direct(
&mut self, &mut self,
bx: &mut Bx, bx: &mut Bx,
place_ref: &mir::PlaceRef<'_, 'tcx>, place_ref: mir::PlaceRef<'_, 'tcx>,
) -> Option<OperandRef<'tcx, Bx::Value>> { ) -> Option<OperandRef<'tcx, Bx::Value>> {
debug!("maybe_codegen_consume_direct(place_ref={:?})", place_ref); debug!("maybe_codegen_consume_direct(place_ref={:?})", place_ref);
...@@ -413,7 +413,7 @@ fn maybe_codegen_consume_direct( ...@@ -413,7 +413,7 @@ fn maybe_codegen_consume_direct(
pub fn codegen_consume( pub fn codegen_consume(
&mut self, &mut self,
bx: &mut Bx, bx: &mut Bx,
place_ref: &mir::PlaceRef<'_, 'tcx>, place_ref: mir::PlaceRef<'_, 'tcx>,
) -> OperandRef<'tcx, Bx::Value> { ) -> OperandRef<'tcx, Bx::Value> {
debug!("codegen_consume(place_ref={:?})", place_ref); debug!("codegen_consume(place_ref={:?})", place_ref);
...@@ -444,7 +444,7 @@ pub fn codegen_operand( ...@@ -444,7 +444,7 @@ pub fn codegen_operand(
match *operand { match *operand {
mir::Operand::Copy(ref place) | mir::Operand::Move(ref place) => { mir::Operand::Copy(ref place) | mir::Operand::Move(ref place) => {
self.codegen_consume(bx, &place.as_ref()) self.codegen_consume(bx, place.as_ref())
} }
mir::Operand::Constant(ref constant) => { mir::Operand::Constant(ref constant) => {
......
...@@ -408,14 +408,14 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { ...@@ -408,14 +408,14 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
pub fn codegen_place( pub fn codegen_place(
&mut self, &mut self,
bx: &mut Bx, bx: &mut Bx,
place_ref: &mir::PlaceRef<'_, 'tcx>, place_ref: mir::PlaceRef<'_, 'tcx>,
) -> PlaceRef<'tcx, Bx::Value> { ) -> PlaceRef<'tcx, Bx::Value> {
debug!("codegen_place(place_ref={:?})", place_ref); debug!("codegen_place(place_ref={:?})", place_ref);
let cx = self.cx; let cx = self.cx;
let tcx = self.cx.tcx(); let tcx = self.cx.tcx();
let result = match place_ref { let result = match place_ref {
mir::PlaceRef { local, projection: [] } => match self.locals[**local] { mir::PlaceRef { local, projection: [] } => match self.locals[*local] {
LocalRef::Place(place) => { LocalRef::Place(place) => {
return place; return place;
} }
...@@ -428,13 +428,13 @@ pub fn codegen_place( ...@@ -428,13 +428,13 @@ pub fn codegen_place(
}, },
mir::PlaceRef { local, projection: [proj_base @ .., mir::ProjectionElem::Deref] } => { mir::PlaceRef { local, projection: [proj_base @ .., mir::ProjectionElem::Deref] } => {
// Load the pointer from its location. // Load the pointer from its location.
self.codegen_consume(bx, &mir::PlaceRef { local, projection: proj_base }) self.codegen_consume(bx, mir::PlaceRef { local, projection: proj_base })
.deref(bx.cx()) .deref(bx.cx())
} }
mir::PlaceRef { local, projection: [proj_base @ .., elem] } => { mir::PlaceRef { local, projection: [proj_base @ .., elem] } => {
// FIXME turn this recursion into iteration // FIXME turn this recursion into iteration
let cg_base = let cg_base =
self.codegen_place(bx, &mir::PlaceRef { local, projection: proj_base }); self.codegen_place(bx, mir::PlaceRef { local, projection: proj_base });
match elem { match elem {
mir::ProjectionElem::Deref => bug!(), mir::ProjectionElem::Deref => bug!(),
...@@ -497,7 +497,7 @@ pub fn codegen_place( ...@@ -497,7 +497,7 @@ pub fn codegen_place(
result result
} }
pub fn monomorphized_place_ty(&self, place_ref: &mir::PlaceRef<'_, 'tcx>) -> Ty<'tcx> { pub fn monomorphized_place_ty(&self, place_ref: mir::PlaceRef<'_, 'tcx>) -> Ty<'tcx> {
let tcx = self.cx.tcx(); let tcx = self.cx.tcx();
let place_ty = mir::Place::ty_from(place_ref.local, place_ref.projection, *self.mir, tcx); let place_ty = mir::Place::ty_from(place_ref.local, place_ref.projection, *self.mir, tcx);
self.monomorphize(&place_ty.ty) self.monomorphize(&place_ty.ty)
......
...@@ -467,7 +467,7 @@ pub fn codegen_rvalue_operand( ...@@ -467,7 +467,7 @@ pub fn codegen_rvalue_operand(
mir::Rvalue::Discriminant(ref place) => { mir::Rvalue::Discriminant(ref place) => {
let discr_ty = rvalue.ty(*self.mir, bx.tcx()); let discr_ty = rvalue.ty(*self.mir, bx.tcx());
let discr = self let discr = self
.codegen_place(&mut bx, &place.as_ref()) .codegen_place(&mut bx, place.as_ref())
.codegen_get_discr(&mut bx, discr_ty); .codegen_get_discr(&mut bx, discr_ty);
( (
bx, bx,
...@@ -541,7 +541,7 @@ fn evaluate_array_len(&mut self, bx: &mut Bx, place: &mir::Place<'tcx>) -> Bx::V ...@@ -541,7 +541,7 @@ fn evaluate_array_len(&mut self, bx: &mut Bx, place: &mir::Place<'tcx>) -> Bx::V
} }
} }
// use common size calculation for non zero-sized types // use common size calculation for non zero-sized types
let cg_value = self.codegen_place(bx, &place.as_ref()); let cg_value = self.codegen_place(bx, place.as_ref());
cg_value.len(bx.cx()) cg_value.len(bx.cx())
} }
...@@ -552,7 +552,7 @@ fn codegen_place_to_pointer( ...@@ -552,7 +552,7 @@ fn codegen_place_to_pointer(
place: &mir::Place<'tcx>, place: &mir::Place<'tcx>,
mk_ptr_ty: impl FnOnce(TyCtxt<'tcx>, Ty<'tcx>) -> Ty<'tcx>, mk_ptr_ty: impl FnOnce(TyCtxt<'tcx>, Ty<'tcx>) -> Ty<'tcx>,
) -> (Bx, OperandRef<'tcx, Bx::Value>) { ) -> (Bx, OperandRef<'tcx, Bx::Value>) {
let cg_place = self.codegen_place(&mut bx, &place.as_ref()); let cg_place = self.codegen_place(&mut bx, place.as_ref());
let ty = cg_place.layout.ty; let ty = cg_place.layout.ty;
......
...@@ -41,12 +41,12 @@ pub fn codegen_statement(&mut self, mut bx: Bx, statement: &mir::Statement<'tcx> ...@@ -41,12 +41,12 @@ pub fn codegen_statement(&mut self, mut bx: Bx, statement: &mir::Statement<'tcx>
} }
} }
} else { } else {
let cg_dest = self.codegen_place(&mut bx, &place.as_ref()); let cg_dest = self.codegen_place(&mut bx, place.as_ref());
self.codegen_rvalue(bx, cg_dest, rvalue) self.codegen_rvalue(bx, cg_dest, rvalue)
} }
} }
mir::StatementKind::SetDiscriminant { box ref place, variant_index } => { mir::StatementKind::SetDiscriminant { box ref place, variant_index } => {
self.codegen_place(&mut bx, &place.as_ref()) self.codegen_place(&mut bx, place.as_ref())
.codegen_set_discr(&mut bx, variant_index); .codegen_set_discr(&mut bx, variant_index);
bx bx
} }
...@@ -70,7 +70,7 @@ pub fn codegen_statement(&mut self, mut bx: Bx, statement: &mir::Statement<'tcx> ...@@ -70,7 +70,7 @@ pub fn codegen_statement(&mut self, mut bx: Bx, statement: &mir::Statement<'tcx>
let outputs = asm let outputs = asm
.outputs .outputs
.iter() .iter()
.map(|output| self.codegen_place(&mut bx, &output.as_ref())) .map(|output| self.codegen_place(&mut bx, output.as_ref()))
.collect(); .collect();
let input_vals = asm.inputs.iter().fold( let input_vals = asm.inputs.iter().fold(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册