Skip to content

Commit 244fbb4

Browse files
committed
Rewrite place workflow in rustc_codegen_llvm
1 parent fea2e88 commit 244fbb4

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

src/librustc_codegen_llvm/mir/analyze.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rustc_data_structures::bitvec::BitArray;
1515
use rustc_data_structures::graph::dominators::Dominators;
1616
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
1717
use rustc::mir::{self, Location, TerminatorKind};
18+
use rustc::mir::tcx::PlaceTy;
1819
use rustc::mir::visit::{Visitor, PlaceContext};
1920
use rustc::mir::traversal;
2021
use rustc::ty;
@@ -162,8 +163,9 @@ impl Visitor<'tcx> for LocalAnalyzer<'mir, 'a, 'll, 'tcx> {
162163
location: Location) {
163164
let cx = self.fx.cx;
164165

165-
if !place.elems.is_empty() {
166-
for (i, elem) in place.elems.iter().cloned().enumerate().rev() {
166+
if !place.has_no_projection() {
167+
let mut base_ty = place.base.ty(self.fx.mir);
168+
for elem in place.elems.iter().cloned() {
167169
debug!("visit_place(place={:?}, context={:?})", place, context);
168170

169171
// Allow uses of projections that are ZSTs or from scalar fields.
@@ -172,20 +174,15 @@ impl Visitor<'tcx> for LocalAnalyzer<'mir, 'a, 'll, 'tcx> {
172174
_ => false
173175
};
174176

175-
let base = place.elem_base(cx.tcx, i);
176177
if is_consume {
177-
let base_ty = base.ty(self.fx.mir, cx.tcx);
178-
let base_ty = self.fx.monomorphize(&base_ty);
178+
base_ty = self.fx.monomorphize(&base_ty);
179179

180-
// ZSTs don't require any actual memory access.
181-
let elem_ty = base_ty.projection_ty(cx.tcx, &elem).to_ty(cx.tcx);
182-
let elem_ty = self.fx.monomorphize(&elem_ty);
183-
if cx.layout_of(elem_ty).is_zst() {
180+
if cx.layout_of(base_ty).is_zst() {
184181
return;
185182
}
186183

187184
if let mir::ProjectionElem::Field(..) = elem {
188-
let layout = cx.layout_of(base_ty.to_ty(cx.tcx));
185+
let layout = cx.layout_of(base_ty);
189186
if layout.is_llvm_immediate() || layout.is_llvm_scalar_pair() {
190187
// Recurse with the same context, instead of `Projection`,
191188
// potentially stopping at non-operand projections,
@@ -200,6 +197,7 @@ impl Visitor<'tcx> for LocalAnalyzer<'mir, 'a, 'll, 'tcx> {
200197
context = PlaceContext::Copy;
201198
continue;
202199
}
200+
base_ty = PlaceTy::from(base_ty).projection_ty(cx.tcx, &elem).to_ty(cx.tcx);
203201
}
204202
}
205203

src/librustc_codegen_llvm/mir/operand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ impl FunctionCx<'a, 'll, 'tcx> {
313313
let mut result = None;
314314
// watch out for locals that do not have an
315315
// alloca; they are handled somewhat differently
316-
if place.elems.is_empty() {
316+
if place.has_no_projection() {
317317
if let mir::PlaceBase::Local(index) = place.base {
318318
match self.locals[index] {
319319
LocalRef::Operand(Some(o)) => {

src/librustc_codegen_llvm/mir/place.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -417,10 +417,8 @@ impl FunctionCx<'a, 'll, 'tcx> {
417417
debug!("codegen_place(place={:?})", place);
418418

419419
let cx = bx.cx;
420-
let tcx = cx.tcx;
421-
422-
let mut result = match place.base {
423-
mir::PlaceBase::Local(index) => {
420+
if let mir::PlaceBase::Local(index) = place.base {
421+
if place.has_no_projection() {
424422
match self.locals[index] {
425423
LocalRef::Place(place) => {
426424
return place;
@@ -430,6 +428,9 @@ impl FunctionCx<'a, 'll, 'tcx> {
430428
}
431429
}
432430
}
431+
};
432+
let mut result = match place.base {
433+
mir::PlaceBase::Local(_) => bug!(),
433434
mir::PlaceBase::Promoted(box (index, ty)) => {
434435
let param_env = ty::ParamEnv::reveal_all();
435436
let cid = mir::interpret::GlobalId {
@@ -462,7 +463,8 @@ impl FunctionCx<'a, 'll, 'tcx> {
462463
}
463464
};
464465

465-
if !place.elems.is_empty() {
466+
if !place.has_no_projection() {
467+
let tcx = cx.tcx;
466468
for (i, elem) in place.elems.iter().cloned().enumerate().rev() {
467469
let base = place.elem_base(tcx, i);
468470
result = match elem {

src/librustc_codegen_llvm/mir/rvalue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ impl FunctionCx<'a, 'll, 'tcx> {
518518
) -> &'ll Value {
519519
// ZST are passed as operands and require special handling
520520
// because codegen_place() panics if Local is operand.
521-
if place.elems.is_empty() {
521+
if place.has_no_projection() {
522522
if let mir::PlaceBase::Local(index) = place.base {
523523
if let LocalRef::Operand(Some(op)) = self.locals[index] {
524524
if let ty::TyArray(_, n) = op.layout.ty.sty {

0 commit comments

Comments
 (0)